http2py 0.1.40__tar.gz → 0.1.41__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. {http2py-0.1.40 → http2py-0.1.41}/PKG-INFO +1 -1
  2. {http2py-0.1.40 → http2py-0.1.41}/pyproject.toml +1 -1
  3. http2py-0.1.41/tests/test_coverage_pass.py +115 -0
  4. {http2py-0.1.40 → http2py-0.1.41}/.gitattributes +0 -0
  5. {http2py-0.1.40 → http2py-0.1.41}/.github/workflows/ci.yml +0 -0
  6. {http2py-0.1.40 → http2py-0.1.41}/.gitignore +0 -0
  7. {http2py-0.1.40 → http2py-0.1.41}/LICENSE +0 -0
  8. {http2py-0.1.40 → http2py-0.1.41}/README.md +0 -0
  9. {http2py-0.1.40 → http2py-0.1.41}/conftest.py +0 -0
  10. {http2py-0.1.40 → http2py-0.1.41}/http2py/__init__.py +0 -0
  11. {http2py-0.1.40 → http2py-0.1.41}/http2py/api_pkg_maker.py +0 -0
  12. {http2py-0.1.40 → http2py-0.1.41}/http2py/authentication.py +0 -0
  13. {http2py-0.1.40 → http2py-0.1.41}/http2py/cli_maker.py +0 -0
  14. {http2py-0.1.40 → http2py-0.1.41}/http2py/client.py +0 -0
  15. {http2py-0.1.40 → http2py-0.1.41}/http2py/constants.py +0 -0
  16. {http2py-0.1.40 → http2py-0.1.41}/http2py/decorators.py +0 -0
  17. {http2py-0.1.40 → http2py-0.1.41}/http2py/default_configs.py +0 -0
  18. {http2py-0.1.40 → http2py-0.1.41}/http2py/example_cli.py +0 -0
  19. {http2py-0.1.40 → http2py-0.1.41}/http2py/global_state.py +0 -0
  20. {http2py-0.1.40 → http2py-0.1.41}/http2py/http2py_cls.py +0 -0
  21. {http2py-0.1.40 → http2py-0.1.41}/http2py/py2request.py +0 -0
  22. {http2py-0.1.40 → http2py-0.1.41}/http2py/resources/module_maker/func_tpl.txt +0 -0
  23. {http2py-0.1.40 → http2py-0.1.41}/http2py/testing_utils.py +0 -0
  24. {http2py-0.1.40 → http2py-0.1.41}/http2py/tests/__init__.py +0 -0
  25. {http2py-0.1.40 → http2py-0.1.41}/http2py/tests/api_pkg_maker_test.py +0 -0
  26. {http2py-0.1.40 → http2py-0.1.41}/http2py/tests/conftest.py +0 -0
  27. {http2py-0.1.40 → http2py-0.1.41}/http2py/tests/test_requirements.txt +0 -0
  28. {http2py-0.1.40 → http2py-0.1.41}/http2py/util.py +0 -0
  29. {http2py-0.1.40 → http2py-0.1.41}/tests/cli_goldens/mk_cli.json +0 -0
  30. {http2py-0.1.40 → http2py-0.1.41}/tests/spec_fixture.py +0 -0
  31. {http2py-0.1.40 → http2py-0.1.41}/tests/test_binary_payloads.py +0 -0
  32. {http2py-0.1.40 → http2py-0.1.41}/tests/test_ci_collection_contract.py +0 -0
  33. {http2py-0.1.40 → http2py-0.1.41}/tests/test_cli_surface.py +0 -0
  34. {http2py-0.1.40 → http2py-0.1.41}/tests/test_error_statuses.py +0 -0
  35. {http2py-0.1.40 → http2py-0.1.41}/tests/test_generated_clients.py +0 -0
  36. {http2py-0.1.40 → http2py-0.1.41}/tests/test_response_decoding.py +0 -0
  37. {http2py-0.1.40 → http2py-0.1.41}/tests/test_route_namespace.py +0 -0
  38. {http2py-0.1.40 → http2py-0.1.41}/tests/test_smoke.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: http2py
3
- Version: 0.1.40
3
+ Version: 0.1.41
4
4
  Summary: Tools to create python binders to http web services.
5
5
  Project-URL: Homepage, https://github.com/i2mint/http2py
6
6
  Project-URL: Repository, https://github.com/i2mint/http2py
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
6
6
 
7
7
  [project]
8
8
  name = "http2py"
9
- version = "0.1.40"
9
+ version = "0.1.41"
10
10
  description = "Tools to create python binders to http web services."
11
11
  readme = "README.md"
12
12
  requires-python = ">=3.10"
@@ -0,0 +1,115 @@
1
+ """Offline tests of http2py's error mapping, loads validation, util helpers and ``mk_auth``."""
2
+
3
+ import json
4
+ import pickle
5
+ import warnings
6
+
7
+ import pytest
8
+ from i2.errors import (
9
+ AuthorizationError,
10
+ DuplicateRecordError,
11
+ ForbiddenError,
12
+ InputError,
13
+ NotFoundError,
14
+ )
15
+
16
+ from http2py.authentication import mk_auth
17
+ from http2py.decorators import (
18
+ _handle_error,
19
+ _handle_resp,
20
+ check_loads,
21
+ unsafe_pickle_loads,
22
+ )
23
+ from http2py.constants import JSON_CONTENT_TYPE, RAW_CONTENT_TYPE
24
+ from http2py.util import (
25
+ I2mintModuleNotFoundErrorNiceMessage,
26
+ ModuleNotFoundErrorNiceMessage,
27
+ add_defaults,
28
+ is_jsonable,
29
+ )
30
+
31
+
32
+ class Resp:
33
+ def __init__(self, status_code=200, reason="", text="msg", content=b"", payload=None):
34
+ self.status_code, self.reason, self.text = status_code, reason, text
35
+ self.content, self._payload = content, payload
36
+
37
+ def json(self):
38
+ return self._payload
39
+
40
+
41
+ @pytest.mark.parametrize(
42
+ "status, reason, exc",
43
+ [
44
+ (400, "AuthorizationError", AuthorizationError),
45
+ (400, "InputError", InputError),
46
+ (400, "DuplicateRecordError", DuplicateRecordError),
47
+ (401, "", AuthorizationError),
48
+ (403, "", ForbiddenError),
49
+ (404, "", NotFoundError),
50
+ (400, "Other", RuntimeError),
51
+ (500, "", RuntimeError),
52
+ ],
53
+ )
54
+ def test_handle_error_maps_status_to_exception(status, reason, exc):
55
+ with pytest.raises(exc):
56
+ _handle_error(Resp(status, reason))
57
+
58
+
59
+ def test_handle_resp_json_raw_and_unsupported_types():
60
+ assert _handle_resp(lambda x: x, JSON_CONTENT_TYPE)(Resp(payload={"a": 1})) == {"a": 1}
61
+ assert _handle_resp(lambda x: x, RAW_CONTENT_TYPE)(Resp(text="hi")) == "hi"
62
+ with pytest.raises(NotImplementedError):
63
+ _handle_resp(lambda x: x, "text/weird")(Resp())
64
+ with pytest.raises(NotFoundError):
65
+ _handle_resp(lambda x: x, RAW_CONTENT_TYPE)(Resp(404))
66
+
67
+
68
+ def test_check_loads_validation_and_pickle_warning():
69
+ check_loads(None)
70
+ check_loads(bytes)
71
+ with pytest.raises(TypeError):
72
+ check_loads("not callable")
73
+ with pytest.warns(UserWarning, match="unsafe_pickle_loads"):
74
+ check_loads(pickle.loads)
75
+ with warnings.catch_warnings():
76
+ warnings.simplefilter("error")
77
+ check_loads(unsafe_pickle_loads)
78
+ assert unsafe_pickle_loads(pickle.dumps([1, 2])) == [1, 2]
79
+
80
+
81
+ def test_add_defaults_fills_only_missing_keys():
82
+ d = {"a": {"x": 1}, "b": {}}
83
+ assert add_defaults(d, {"x": 0, "y": 2}) == {"a": {"x": 1, "y": 2}, "b": {"x": 0, "y": 2}}
84
+
85
+
86
+ def test_is_jsonable():
87
+ assert is_jsonable({"a": [1, 2]}) and not is_jsonable(object())
88
+
89
+
90
+ @pytest.mark.parametrize(
91
+ "cm, hint", [(ModuleNotFoundErrorNiceMessage, "pip install nopkg"), (I2mintModuleNotFoundErrorNiceMessage, "git clone")]
92
+ )
93
+ def test_nice_module_not_found_messages(cm, hint):
94
+ with pytest.raises(ModuleNotFoundError, match=hint):
95
+ with cm():
96
+ import nopkg_does_not_exist # noqa: F401
97
+
98
+ with pytest.raises(ModuleNotFoundError) as e:
99
+ with cm():
100
+ raise ModuleNotFoundError(name="nopkg")
101
+ assert "nopkg" in str(e.value)
102
+ with cm(): # other outcomes pass through
103
+ pass
104
+
105
+
106
+ def test_mk_auth_fills_missing_values_from_the_credentials_file(tmp_path):
107
+ cfg = tmp_path / "c.json"
108
+ cfg.write_text(json.dumps({"default": {"key": "d"}, "work": {"key": "w", "secret": "s"}}))
109
+ assert mk_auth({"key": "given"}, ["key"], cfg) == {"key": "given"}
110
+ assert mk_auth({}, ["key"], cfg) == {"key": "d"}
111
+ assert mk_auth({}, ["key", "secret"], cfg, profile="work") == {"key": "w", "secret": "s"}
112
+ assert mk_auth({}, ["key"], cfg, profile="missing") == {"key": "d"}
113
+ flat = tmp_path / "f.json"
114
+ flat.write_text(json.dumps({"key": "flat"}))
115
+ assert mk_auth({}, ["key", "other"], flat) == {"key": "flat", "other": ""}
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes