diff --git a/coverage_after.txt b/coverage_after.txt new file mode 100644 index 0000000000..83b4525ff3 --- /dev/null +++ b/coverage_after.txt @@ -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% diff --git a/coverage_before.txt b/coverage_before.txt new file mode 100644 index 0000000000..ef763eeecc --- /dev/null +++ b/coverage_before.txt @@ -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% diff --git a/httpie/cli/argtemplate.py b/httpie/cli/argtemplate.py new file mode 100644 index 0000000000..2c0255cb59 --- /dev/null +++ b/httpie/cli/argtemplate.py @@ -0,0 +1,156 @@ +import json +import os + + +TEMPLATE_FILE = "httpie/cli/templates.json" + + +def store_json_template(args): + """ + Store a template as a string in templates.json, the format for running this is: + http template || login=testuser password=testpassword ... + """ + template_name = args.pop(0) + template_method = None + template_url = None + template_variables = {} + + if ["CONNECT", "DELETE", "GET", "HEAD", "OPTIONS", "POST", "PUT", "TRACE", "PATCH"].__contains__(args[0].upper()): + template_method = args.pop(0) + template_url = args.pop(0) + else: + temp = args.pop(0) + print(f"'{temp}' is not a valid http method, defaulting to null...") + template_url = args.pop(0) + + for arg in args: + if '=' in arg: + variable_name, variable_value = arg.split("=") + template_variables[variable_name] = variable_value + + template = {} + template['method'] = template_method + template['url'] = template_url + template['data'] = template_variables + + # Check if the templates.json file exists + if not os.path.isfile(TEMPLATE_FILE): + open(TEMPLATE_FILE, "w").close() + + with open(TEMPLATE_FILE, "r+") as f: + stored_templates = {} + try: + stored_templates = json.load(f) + except json.JSONDecodeError: + pass + if template_name in stored_templates: + stored_templates.pop(template_name) + stored_templates[template_name] = template + f.seek(0) + json.dump(stored_templates, f) + f.truncate() + + +def edit_json_template(args): + """ + Edit a template in templates.json, the format for running this is: + http editt + """ + stored_templates = {} + + # Check if the templates.json file exists + if not os.path.isfile(TEMPLATE_FILE): + open(TEMPLATE_FILE, "w").close() + + with open(TEMPLATE_FILE, "r+") as f: + try: + stored_templates = json.load(f) + except json.JSONDecodeError: + pass + + template_name = args.pop(0) + template_item = args.pop(0) + template_value = args.pop(0) + + # Check if the template exists + if template_name not in stored_templates: + print(f"Template '{template_name}' does not exist.") + return + + # Update the HTTP method + if template_item == 'method': + stored_templates[template_name]['method'] = template_value.upper() + # Update the URL + elif template_item == 'url': + stored_templates[template_name]['url'] = template_value + # Update a key-value pair in the data dictionary + elif template_item in stored_templates[template_name]['data']: + stored_templates[template_name]['data'][template_item] = template_value + # Add a new key-value pair to the data dictionary + else: + stored_templates[template_name]['data'][template_item] = template_value + + # Save the updated template to file + f.seek(0) + json.dump(stored_templates, f) + f.truncate() + + +def delete_template(arg): + """ + Tries to delete the template with name 'arg' + Usage format: http delt + """ + stored_templates = {} + + # Check if the templates.json file exists + if not os.path.isfile(TEMPLATE_FILE): + open(TEMPLATE_FILE, "w").close() + + with open(TEMPLATE_FILE, "r+") as f: + try: + stored_templates = json.load(f) + except json.JSONDecodeError: + pass + + # Check if the template exists + if arg not in stored_templates: + print(f"Template '{arg}' does not exist.") + return + del stored_templates[arg] + # Save the updated template to file + f.seek(0) + json.dump(stored_templates, f) + f.truncate() + + +def load_template(arg): + """ + Load a template from templates.json and return a list of arguments to be passed to the main function + the format for running this is: + http runt