Merge pull request #35 from sanredz/issue-34

Add more unit tests
This commit is contained in:
editf 2023-03-08 14:31:48 +01:00 committed by GitHub
commit 4c5ee9b286
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 1581 additions and 7 deletions

126
coverage_after.txt Normal file
View File

@ -0,0 +1,126 @@
Name Stmts Miss Branch BrPart Cover
---------------------------------------------------------------------------------
httpie/__init__.py 4 0 0 0 100%
httpie/__main__.py 8 0 0 0 100%
httpie/adapters.py 7 0 0 0 100%
httpie/cli/__init__.py 0 0 0 0 100%
httpie/cli/argparser.py 316 20 152 11 92%
httpie/cli/argtemplate.py 99 0 38 0 100%
httpie/cli/argtypes.py 135 7 36 1 95%
httpie/cli/constants.py 46 0 2 0 100%
httpie/cli/definition.py 105 8 14 3 89%
httpie/cli/dicts.py 40 1 16 2 95%
httpie/cli/exceptions.py 2 0 0 0 100%
httpie/cli/nested_json/__init__.py 4 0 0 0 100%
httpie/cli/nested_json/errors.py 14 0 2 0 100%
httpie/cli/nested_json/interpret.py 77 3 40 4 94%
httpie/cli/nested_json/parse.py 107 5 44 4 94%
httpie/cli/nested_json/tokens.py 49 4 12 1 85%
httpie/cli/options.py 124 3 48 1 98%
httpie/cli/requestitems.py 100 8 28 0 92%
httpie/cli/utils.py 41 2 10 0 96%
httpie/client.py 169 0 76 4 98%
httpie/compat.py 51 31 16 3 34%
httpie/config.py 95 2 28 1 98%
httpie/context.py 122 14 38 6 86%
httpie/cookies.py 11 0 2 0 100%
httpie/core.py 202 18 102 15 89%
httpie/downloads.py 175 6 60 9 94%
httpie/encoding.py 18 0 6 1 96%
httpie/internal/__build_channel__.py 1 0 0 0 100%
httpie/internal/__init__.py 0 0 0 0 100%
httpie/internal/daemon_runner.py 28 4 4 0 88%
httpie/internal/daemons.py 58 30 14 3 43%
httpie/internal/update_warnings.py 96 5 42 4 92%
httpie/legacy/__init__.py 0 0 0 0 100%
httpie/legacy/v3_1_0_session_cookie_format.py 33 1 26 2 95%
httpie/legacy/v3_2_0_session_header_format.py 27 1 16 1 95%
httpie/manager/__init__.py 0 0 0 0 100%
httpie/manager/__main__.py 33 5 6 0 87%
httpie/manager/cli.py 39 0 8 0 100%
httpie/manager/compat.py 35 13 10 1 51%
httpie/manager/core.py 20 1 8 1 93%
httpie/manager/tasks/__init__.py 5 0 0 0 100%
httpie/manager/tasks/check_updates.py 8 0 0 0 100%
httpie/manager/tasks/export_args.py 14 1 2 1 88%
httpie/manager/tasks/plugins.py 153 8 64 12 91%
httpie/manager/tasks/sessions.py 43 2 18 2 93%
httpie/models.py 112 5 44 1 96%
httpie/output/__init__.py 0 0 0 0 100%
httpie/output/formatters/__init__.py 0 0 0 0 100%
httpie/output/formatters/colors.py 140 0 30 1 99%
httpie/output/formatters/headers.py 9 0 2 0 100%
httpie/output/formatters/json.py 16 0 3 0 100%
httpie/output/formatters/xml.py 43 1 16 3 93%
httpie/output/lexers/__init__.py 0 0 0 0 100%
httpie/output/lexers/common.py 4 0 2 0 100%
httpie/output/lexers/http.py 22 3 2 1 83%
httpie/output/lexers/json.py 10 0 0 0 100%
httpie/output/lexers/metadata.py 17 3 4 2 76%
httpie/output/models.py 27 1 8 0 97%
httpie/output/processing.py 37 0 22 2 97%
httpie/output/streams.py 138 2 54 1 98%
httpie/output/ui/__init__.py 0 0 0 0 100%
httpie/output/ui/palette.py 72 9 18 3 84%
httpie/output/ui/rich_help.py 104 49 38 0 49%
httpie/output/ui/rich_palette.py 33 3 8 1 90%
httpie/output/ui/rich_progress.py 62 15 14 4 72%
httpie/output/utils.py 20 0 0 0 100%
httpie/output/writer.py 76 13 30 1 79%
httpie/plugins/__init__.py 2 0 0 0 100%
httpie/plugins/base.py 38 4 2 0 90%
httpie/plugins/builtin.py 39 0 2 0 100%
httpie/plugins/manager.py 67 1 22 1 98%
httpie/plugins/registry.py 8 0 0 0 100%
httpie/sessions.py 155 3 64 2 98%
httpie/ssl_.py 37 2 13 0 96%
httpie/status.py 20 0 8 0 100%
httpie/uploads.py 132 19 56 5 83%
httpie/utils.py 131 15 42 3 85%
tests/__init__.py 0 0 0 0 100%
tests/conftest.py 46 11 20 3 79%
tests/fixtures/__init__.py 37 0 4 0 100%
tests/test_argtemplate.py 197 0 28 0 100%
tests/test_auth.py 79 0 20 0 100%
tests/test_auth_plugins.py 76 0 4 1 99%
tests/test_binary.py 32 0 2 0 100%
tests/test_cli.py 200 0 10 0 100%
tests/test_cli_ui.py 20 0 4 0 100%
tests/test_cli_utils.py 42 0 4 0 100%
tests/test_compress.py 60 0 0 0 100%
tests/test_config.py 72 2 10 0 98%
tests/test_cookie.py 26 0 0 0 100%
tests/test_cookie_on_redirects.py 63 0 26 0 100%
tests/test_defaults.py 79 0 0 0 100%
tests/test_downloads.py 129 0 30 0 100%
tests/test_encoding.py 111 0 40 0 100%
tests/test_errors.py 45 0 14 0 100%
tests/test_exit_status.py 42 0 4 0 100%
tests/test_httpie.py 209 4 30 0 98%
tests/test_httpie_cli.py 63 0 28 0 100%
tests/test_json.py 76 0 36 2 98%
tests/test_meta.py 12 0 2 0 100%
tests/test_offline.py 36 0 0 0 100%
tests/test_output.py 249 1 65 1 99%
tests/test_parser_schema.py 11 0 2 0 100%
tests/test_plugins_cli.py 89 0 44 0 100%
tests/test_redirects.py 50 1 16 0 98%
tests/test_regressions.py 18 0 2 0 100%
tests/test_sessions.py 339 1 97 2 99%
tests/test_ssl.py 108 8 40 4 91%
tests/test_stream.py 66 0 20 0 100%
tests/test_tokens.py 63 0 0 0 100%
tests/test_transport_plugin.py 30 0 0 0 100%
tests/test_update_warnings.py 117 1 36 1 99%
tests/test_uploads.py 182 6 40 0 97%
tests/test_windows.py 15 1 4 0 95%
tests/test_xml.py 41 1 22 1 97%
tests/utils/__init__.py 236 18 63 8 90%
tests/utils/http_server.py 101 1 42 2 98%
tests/utils/matching/__init__.py 10 0 2 0 100%
tests/utils/matching/parsing.py 49 1 20 2 96%
tests/utils/matching/test_matching.py 46 0 0 0 100%
tests/utils/matching/tokens.py 17 0 0 0 100%
tests/utils/plugins_cli.py 125 1 50 2 98%
---------------------------------------------------------------------------------
TOTAL 7999 409 2373 153 94%

124
coverage_before.txt Normal file
View File

@ -0,0 +1,124 @@
Name Stmts Miss Branch BrPart Cover
---------------------------------------------------------------------------------
httpie/__init__.py 4 0 0 0 100%
httpie/__main__.py 8 0 0 0 100%
httpie/adapters.py 7 0 0 0 100%
httpie/cli/__init__.py 0 0 0 0 100%
httpie/cli/argparser.py 316 20 152 11 92%
httpie/cli/argtypes.py 135 7 36 1 95%
httpie/cli/constants.py 46 0 2 0 100%
httpie/cli/definition.py 105 8 14 3 89%
httpie/cli/dicts.py 40 1 16 2 95%
httpie/cli/exceptions.py 2 0 0 0 100%
httpie/cli/nested_json/__init__.py 4 0 0 0 100%
httpie/cli/nested_json/errors.py 14 0 2 0 100%
httpie/cli/nested_json/interpret.py 77 3 40 4 94%
httpie/cli/nested_json/parse.py 107 5 44 4 94%
httpie/cli/nested_json/tokens.py 49 4 12 1 85%
httpie/cli/options.py 124 3 48 1 98%
httpie/cli/requestitems.py 100 8 28 0 92%
httpie/cli/utils.py 41 2 10 0 96%
httpie/client.py 169 0 76 4 98%
httpie/compat.py 51 31 16 3 34%
httpie/config.py 95 2 28 1 98%
httpie/context.py 122 14 38 6 86%
httpie/cookies.py 11 0 2 0 100%
httpie/core.py 170 8 80 9 93%
httpie/downloads.py 175 6 60 9 94%
httpie/encoding.py 18 0 6 1 96%
httpie/internal/__build_channel__.py 1 0 0 0 100%
httpie/internal/__init__.py 0 0 0 0 100%
httpie/internal/daemon_runner.py 28 4 4 0 88%
httpie/internal/daemons.py 58 30 14 3 43%
httpie/internal/update_warnings.py 96 5 42 4 92%
httpie/legacy/__init__.py 0 0 0 0 100%
httpie/legacy/v3_1_0_session_cookie_format.py 33 1 26 2 95%
httpie/legacy/v3_2_0_session_header_format.py 27 1 16 1 95%
httpie/manager/__init__.py 0 0 0 0 100%
httpie/manager/__main__.py 33 5 6 0 87%
httpie/manager/cli.py 39 0 8 0 100%
httpie/manager/compat.py 35 13 10 1 51%
httpie/manager/core.py 20 1 8 1 93%
httpie/manager/tasks/__init__.py 5 0 0 0 100%
httpie/manager/tasks/check_updates.py 8 0 0 0 100%
httpie/manager/tasks/export_args.py 14 1 2 1 88%
httpie/manager/tasks/plugins.py 153 8 64 12 91%
httpie/manager/tasks/sessions.py 43 2 18 2 93%
httpie/models.py 112 5 44 1 96%
httpie/output/__init__.py 0 0 0 0 100%
httpie/output/formatters/__init__.py 0 0 0 0 100%
httpie/output/formatters/colors.py 140 0 30 1 99%
httpie/output/formatters/headers.py 9 0 2 0 100%
httpie/output/formatters/json.py 16 0 3 0 100%
httpie/output/formatters/xml.py 43 1 16 3 93%
httpie/output/lexers/__init__.py 0 0 0 0 100%
httpie/output/lexers/common.py 4 0 2 0 100%
httpie/output/lexers/http.py 22 3 2 1 83%
httpie/output/lexers/json.py 10 0 0 0 100%
httpie/output/lexers/metadata.py 17 3 4 2 76%
httpie/output/models.py 27 1 8 0 97%
httpie/output/processing.py 37 0 22 2 97%
httpie/output/streams.py 138 2 54 1 98%
httpie/output/ui/__init__.py 0 0 0 0 100%
httpie/output/ui/palette.py 72 9 18 3 84%
httpie/output/ui/rich_help.py 104 49 38 0 49%
httpie/output/ui/rich_palette.py 33 3 8 1 90%
httpie/output/ui/rich_progress.py 62 15 14 4 72%
httpie/output/utils.py 20 0 0 0 100%
httpie/output/writer.py 76 13 30 1 79%
httpie/plugins/__init__.py 2 0 0 0 100%
httpie/plugins/base.py 38 4 2 0 90%
httpie/plugins/builtin.py 39 0 2 0 100%
httpie/plugins/manager.py 67 1 22 1 98%
httpie/plugins/registry.py 8 0 0 0 100%
httpie/sessions.py 155 3 64 2 98%
httpie/ssl_.py 37 2 13 0 96%
httpie/status.py 20 0 8 0 100%
httpie/uploads.py 132 19 56 5 83%
httpie/utils.py 131 15 42 3 85%
tests/__init__.py 0 0 0 0 100%
tests/conftest.py 46 11 20 3 79%
tests/fixtures/__init__.py 37 0 4 0 100%
tests/test_auth.py 79 0 20 0 100%
tests/test_auth_plugins.py 76 0 4 1 99%
tests/test_binary.py 32 0 2 0 100%
tests/test_cli.py 200 0 10 0 100%
tests/test_cli_ui.py 20 0 4 0 100%
tests/test_cli_utils.py 42 0 4 0 100%
tests/test_compress.py 60 0 0 0 100%
tests/test_config.py 72 2 10 0 98%
tests/test_cookie.py 26 0 0 0 100%
tests/test_cookie_on_redirects.py 63 0 26 0 100%
tests/test_defaults.py 79 0 0 0 100%
tests/test_downloads.py 129 0 30 0 100%
tests/test_encoding.py 111 0 40 0 100%
tests/test_errors.py 45 0 14 0 100%
tests/test_exit_status.py 42 0 4 0 100%
tests/test_httpie.py 180 4 22 0 98%
tests/test_httpie_cli.py 63 0 28 0 100%
tests/test_json.py 76 0 36 2 98%
tests/test_meta.py 12 0 2 0 100%
tests/test_offline.py 36 0 0 0 100%
tests/test_output.py 249 1 65 1 99%
tests/test_parser_schema.py 11 0 2 0 100%
tests/test_plugins_cli.py 89 0 44 0 100%
tests/test_redirects.py 50 1 16 0 98%
tests/test_regressions.py 18 0 2 0 100%
tests/test_sessions.py 339 1 97 2 99%
tests/test_ssl.py 108 8 40 4 91%
tests/test_stream.py 66 0 20 0 100%
tests/test_tokens.py 63 0 0 0 100%
tests/test_transport_plugin.py 30 0 0 0 100%
tests/test_update_warnings.py 117 1 36 1 99%
tests/test_uploads.py 182 6 40 0 97%
tests/test_windows.py 15 1 4 0 95%
tests/test_xml.py 41 1 22 1 97%
tests/utils/__init__.py 236 18 63 8 90%
tests/utils/http_server.py 101 1 42 2 98%
tests/utils/matching/__init__.py 10 0 2 0 100%
tests/utils/matching/parsing.py 49 1 20 2 96%
tests/utils/matching/test_matching.py 46 0 0 0 100%
tests/utils/matching/tokens.py 17 0 0 0 100%
tests/utils/plugins_cli.py 125 1 50 2 98%
---------------------------------------------------------------------------------
TOTAL 7642 399 2277 147 93%

View File

@ -64,9 +64,6 @@ def raw_main(
if len(args) < 2:
print("No template name was specified")
return ExitStatus.ERROR
if len(args) > 2:
print("Too many arguments, http runt <template name> expected.")
return ExitStatus.ERROR
from httpie.cli.argtemplate import store_json_template, load_template
args = load_template(args[1])
elif (args[0] == "editt"):
@ -85,11 +82,8 @@ def raw_main(
if len(args) < 2:
print("No template name was specified")
return ExitStatus.ERROR
if len(args) > 2:
print("Too many arguments, http delt <template name> expected.")
return ExitStatus.ERROR
from httpie.cli.argtemplate import delete_template
args = delete_template(args[1])
delete_template(args[1])
return ExitStatus.SUCCESS
include_debug_info = '--debug' in args

1273
test_log_after.txt Normal file

File diff suppressed because it is too large Load Diff

View File

@ -12,6 +12,9 @@ from httpie.context import Environment
from httpie.encoding import UTF8
from httpie.status import ExitStatus
from .utils import HTTP_OK, MockEnvironment, StdinBytesIO, http
import httpie.cli.argtemplate
import tempfile
import json
def test_main_entry_point():
@ -362,3 +365,57 @@ def test_options_dropping_redundant_content_length(httpbin, method):
httpbin + '/anything'
)
assert 'Content-Length' not in r
def test_store_template():
"""
Tests that a template can be stored with the command 'http template <name> <method> <url> ...'
"""
with tempfile.NamedTemporaryFile('w+', delete=False) as temp_fp:
httpie.cli.argtemplate.TEMPLATE_FILE = temp_fp.name
http('template', 'test_template', 'GET', 'https://catfact.ninja/fact', '--traceback', '--timeout=3')
template = json.load(temp_fp)
assert 'test_template' in template
def test_run_template(httpbin_both):
"""
Tests that a template can be loaded with the command 'http runt <template>'
"""
with tempfile.NamedTemporaryFile('w+', delete=False) as temp_fp:
httpie.cli.argtemplate.TEMPLATE_FILE = temp_fp.name
r = http('template', 'test_template', 'GET', httpbin_both + '/get', '--debug') # store template
r = http('runt', 'test_template', '--traceback', '--timeout=3', tolerate_error_exit_status=True) # run it
assert HTTP_OK in r
def test_delete_template():
"""
Tests that a template can be deleted with the command 'http delt <template>'
"""
with tempfile.NamedTemporaryFile('w+', delete=False) as temp_fp:
httpie.cli.argtemplate.TEMPLATE_FILE = temp_fp.name
http('template', 'test_template', 'GET', 'https://catfact.ninja/fact', '--traceback', '--timeout=3') # store template
http('delt', 'test_template', '--traceback', '--timeout=3', tolerate_error_exit_status=True) # delete it
stored_templates = json.load(temp_fp)
assert 'test_template' not in stored_templates
def test_edit_template():
"""
Tests that a template can be edited with the command 'http editt <template>'
"""
with tempfile.NamedTemporaryFile('w+', delete=False) as temp_fp:
httpie.cli.argtemplate.TEMPLATE_FILE = temp_fp.name
http('template', 'test_template', 'GET', 'https://catfact.ninja/fact', '--traceback', '--timeout=3') # store template
http('editt', 'test_template', 'param', 'value', '--debug') # edit it
stored_templates = json.load(temp_fp)
assert 'param' in stored_templates['test_template']['data']