masstack-python-client 0.0.1__tar.gz → 0.0.2__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.
- {masstack_python_client-0.0.1/src/masstack_python_client.egg-info → masstack_python_client-0.0.2}/PKG-INFO +1 -1
- {masstack_python_client-0.0.1 → masstack_python_client-0.0.2}/pyproject.toml +7 -3
- {masstack_python_client-0.0.1 → masstack_python_client-0.0.2}/src/masstack_python_client/__init__.py +1 -1
- {masstack_python_client-0.0.1 → masstack_python_client-0.0.2}/src/masstack_python_client/auth/token_manager.py +6 -5
- {masstack_python_client-0.0.1 → masstack_python_client-0.0.2}/src/masstack_python_client/exceptions.py +8 -6
- {masstack_python_client-0.0.1 → masstack_python_client-0.0.2/src/masstack_python_client.egg-info}/PKG-INFO +1 -1
- {masstack_python_client-0.0.1 → masstack_python_client-0.0.2}/src/masstack_python_client.egg-info/SOURCES.txt +2 -1
- {masstack_python_client-0.0.1 → masstack_python_client-0.0.2}/tests/test_client.py +4 -13
- masstack_python_client-0.0.2/tests/test_exceptions.py +14 -0
- {masstack_python_client-0.0.1 → masstack_python_client-0.0.2}/LICENSE +0 -0
- {masstack_python_client-0.0.1 → masstack_python_client-0.0.2}/MANIFEST.in +0 -0
- {masstack_python_client-0.0.1 → masstack_python_client-0.0.2}/README.md +0 -0
- {masstack_python_client-0.0.1 → masstack_python_client-0.0.2}/setup.cfg +0 -0
- {masstack_python_client-0.0.1 → masstack_python_client-0.0.2}/src/masstack_python_client/auth/__init__.py +0 -0
- {masstack_python_client-0.0.1 → masstack_python_client-0.0.2}/src/masstack_python_client/auth/token.py +0 -0
- {masstack_python_client-0.0.1 → masstack_python_client-0.0.2}/src/masstack_python_client/auth/token_store.py +0 -0
- {masstack_python_client-0.0.1 → masstack_python_client-0.0.2}/src/masstack_python_client/client.py +0 -0
- {masstack_python_client-0.0.1 → masstack_python_client-0.0.2}/src/masstack_python_client/data/data_utils.py +0 -0
- {masstack_python_client-0.0.1 → masstack_python_client-0.0.2}/src/masstack_python_client/data/province_translation.csv +0 -0
- {masstack_python_client-0.0.1 → masstack_python_client-0.0.2}/src/masstack_python_client/data/street_type_translation.csv +0 -0
- {masstack_python_client-0.0.1 → masstack_python_client-0.0.2}/src/masstack_python_client/data/unit_translation.csv +0 -0
- {masstack_python_client-0.0.1 → masstack_python_client-0.0.2}/src/masstack_python_client/resources/__init__.py +0 -0
- {masstack_python_client-0.0.1 → masstack_python_client-0.0.2}/src/masstack_python_client/resources/feasibility.py +0 -0
- {masstack_python_client-0.0.1 → masstack_python_client-0.0.2}/src/masstack_python_client/resources/models/address.py +0 -0
- {masstack_python_client-0.0.1 → masstack_python_client-0.0.2}/src/masstack_python_client.egg-info/dependency_links.txt +0 -0
- {masstack_python_client-0.0.1 → masstack_python_client-0.0.2}/src/masstack_python_client.egg-info/requires.txt +0 -0
- {masstack_python_client-0.0.1 → masstack_python_client-0.0.2}/src/masstack_python_client.egg-info/top_level.txt +0 -0
|
@@ -74,7 +74,6 @@ requires = ["tox>=4.20"]
|
|
|
74
74
|
env_list = [
|
|
75
75
|
"style",
|
|
76
76
|
"py3119",
|
|
77
|
-
"coverage",
|
|
78
77
|
"pep8"
|
|
79
78
|
]
|
|
80
79
|
|
|
@@ -90,9 +89,9 @@ commands = [
|
|
|
90
89
|
["pre-commit", "run", "--all-files", "--show-diff-on-failure"],
|
|
91
90
|
]
|
|
92
91
|
|
|
93
|
-
[tool.tox.env.
|
|
92
|
+
[tool.tox.env.py3119]
|
|
94
93
|
commands = [
|
|
95
|
-
["pytest", "--cov", "--cov-report
|
|
94
|
+
["pytest", "--cov=masstack_python_client", "--cov-report=term:skip-covered", "--cov-report=html", "--cov-report=term-missing"],
|
|
96
95
|
]
|
|
97
96
|
|
|
98
97
|
[tool.tox.env.pep8]
|
|
@@ -100,3 +99,8 @@ deps = ["flake8"]
|
|
|
100
99
|
commands = [
|
|
101
100
|
["flake8"],
|
|
102
101
|
]
|
|
102
|
+
|
|
103
|
+
[tool.tox.env.coverage]
|
|
104
|
+
commands = [
|
|
105
|
+
["pytest", "--cov=masstack_python_client", "--cov-report=term-missing", "--cov-fail-under=95"],
|
|
106
|
+
]
|
|
@@ -56,17 +56,18 @@ class TokenManager:
|
|
|
56
56
|
try:
|
|
57
57
|
key = RSAKey.import_key(self._private_key)
|
|
58
58
|
assertion = jwt.encode(jwt_header, claims, key)
|
|
59
|
+
data = {
|
|
60
|
+
"assertion": assertion,
|
|
61
|
+
"grant_type": "urn:ietf:params:oauth:grant-type:jwt-bearer",
|
|
62
|
+
}
|
|
59
63
|
response = requests.post(
|
|
60
64
|
self._token_uri,
|
|
61
|
-
data=
|
|
62
|
-
"assertion": assertion,
|
|
63
|
-
"grant_type": "urn:ietf:params:oauth:grant-type:jwt-bearer",
|
|
64
|
-
},
|
|
65
|
+
data=data,
|
|
65
66
|
headers={"Content-Type": "application/x-www-form-urlencoded"},
|
|
66
67
|
)
|
|
67
68
|
response.raise_for_status()
|
|
68
69
|
except HTTPError:
|
|
69
|
-
raise ErrorFetchingToKen(response.status_code, response.text)
|
|
70
|
+
raise ErrorFetchingToKen(response.status_code, response.text, data)
|
|
70
71
|
except Exception as e:
|
|
71
72
|
raise ErrorFetchingToKen(500, str(e))
|
|
72
73
|
data = response.json()
|
|
@@ -8,19 +8,19 @@ class MasstackClientException(Exception):
|
|
|
8
8
|
_message: Optional[str] = None
|
|
9
9
|
|
|
10
10
|
def __init__(self, status_code: int, message: str):
|
|
11
|
-
super(
|
|
11
|
+
super(MasstackClientException, self).__init__(message)
|
|
12
12
|
self._message = message
|
|
13
13
|
self._status_code = status_code
|
|
14
14
|
|
|
15
15
|
@property
|
|
16
16
|
def status_code(self) -> int:
|
|
17
17
|
"""The status_code property."""
|
|
18
|
-
return self._status_code
|
|
18
|
+
return 0 if self._status_code is None else self._status_code
|
|
19
19
|
|
|
20
20
|
@property
|
|
21
21
|
def message(self) -> str:
|
|
22
22
|
"""The error message property."""
|
|
23
|
-
return self._message
|
|
23
|
+
return "" if self._message is None else self._message
|
|
24
24
|
|
|
25
25
|
def _params_to_string(self, params):
|
|
26
26
|
if not params or len(params) == 0:
|
|
@@ -32,9 +32,11 @@ class MasstackClientException(Exception):
|
|
|
32
32
|
|
|
33
33
|
|
|
34
34
|
class ErrorFetchingToKen(MasstackClientException):
|
|
35
|
-
def __init__(self, status_code: int, error_msg: str):
|
|
36
|
-
message =
|
|
37
|
-
|
|
35
|
+
def __init__(self, status_code: int, error_msg: str, body: Optional[dict] = None):
|
|
36
|
+
message = (
|
|
37
|
+
"Error fetching token with the next error message: {}\nBody:\n{}".format(
|
|
38
|
+
error_msg, self._params_to_string(body)
|
|
39
|
+
)
|
|
38
40
|
)
|
|
39
41
|
super(ErrorFetchingToKen, self).__init__(status_code, message)
|
|
40
42
|
|
|
@@ -21,4 +21,5 @@ src/masstack_python_client/data/unit_translation.csv
|
|
|
21
21
|
src/masstack_python_client/resources/__init__.py
|
|
22
22
|
src/masstack_python_client/resources/feasibility.py
|
|
23
23
|
src/masstack_python_client/resources/models/address.py
|
|
24
|
-
tests/test_client.py
|
|
24
|
+
tests/test_client.py
|
|
25
|
+
tests/test_exceptions.py
|
|
@@ -25,7 +25,6 @@ class ClientTestCase(unittest.TestCase):
|
|
|
25
25
|
self.version = "v1"
|
|
26
26
|
self.endpoint = "testapi"
|
|
27
27
|
self.params = {"param1": "value1", "param2": "value2"}
|
|
28
|
-
self.header = {"Custom-Header": "HeaderValue"}
|
|
29
28
|
|
|
30
29
|
"""
|
|
31
30
|
test get
|
|
@@ -36,9 +35,7 @@ class ClientTestCase(unittest.TestCase):
|
|
|
36
35
|
status_code=200, json=lambda: {"data": "test_data"}
|
|
37
36
|
)
|
|
38
37
|
self.assertEqual(
|
|
39
|
-
MasstackClient().get(
|
|
40
|
-
self.api, self.version, self.endpoint, self.params, self.header
|
|
41
|
-
),
|
|
38
|
+
MasstackClient().get(self.api, self.version, self.endpoint, self.params),
|
|
42
39
|
{"data": "test_data"},
|
|
43
40
|
)
|
|
44
41
|
mock_token_manager.assert_called_once()
|
|
@@ -48,7 +45,6 @@ class ClientTestCase(unittest.TestCase):
|
|
|
48
45
|
headers={
|
|
49
46
|
"Authorization": "Bearer test_token",
|
|
50
47
|
"Accept": "application/json",
|
|
51
|
-
**self.header,
|
|
52
48
|
},
|
|
53
49
|
json=None,
|
|
54
50
|
params=self.params,
|
|
@@ -65,7 +61,6 @@ class ClientTestCase(unittest.TestCase):
|
|
|
65
61
|
self.version,
|
|
66
62
|
self.endpoint,
|
|
67
63
|
self.params,
|
|
68
|
-
self.header,
|
|
69
64
|
)
|
|
70
65
|
|
|
71
66
|
"""
|
|
@@ -73,16 +68,13 @@ class ClientTestCase(unittest.TestCase):
|
|
|
73
68
|
"""
|
|
74
69
|
|
|
75
70
|
def test_post_ok(self, mock_request, mock_token_manager):
|
|
71
|
+
extra_header = {"Custom-Header": "HeaderValue"}
|
|
76
72
|
mock_request.return_value = Mock(
|
|
77
73
|
status_code=200, json=lambda: {"data": "test_data"}
|
|
78
74
|
)
|
|
79
75
|
self.assertEqual(
|
|
80
76
|
MasstackClient().post(
|
|
81
|
-
self.api,
|
|
82
|
-
self.version,
|
|
83
|
-
self.endpoint,
|
|
84
|
-
self.params,
|
|
85
|
-
self.header,
|
|
77
|
+
self.api, self.version, self.endpoint, self.params, extra_header
|
|
86
78
|
),
|
|
87
79
|
{"data": "test_data"},
|
|
88
80
|
)
|
|
@@ -93,7 +85,7 @@ class ClientTestCase(unittest.TestCase):
|
|
|
93
85
|
headers={
|
|
94
86
|
"Authorization": "Bearer test_token",
|
|
95
87
|
"Accept": "application/json",
|
|
96
|
-
**
|
|
88
|
+
**extra_header,
|
|
97
89
|
},
|
|
98
90
|
json=self.params,
|
|
99
91
|
params=None,
|
|
@@ -110,5 +102,4 @@ class ClientTestCase(unittest.TestCase):
|
|
|
110
102
|
self.version,
|
|
111
103
|
self.endpoint,
|
|
112
104
|
self.params,
|
|
113
|
-
self.header,
|
|
114
105
|
)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
|
|
3
|
+
from masstack_python_client.exceptions import MasstackClientException
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class MasstackClientExceptionTestCase(unittest.TestCase):
|
|
7
|
+
def test_exception_fallback_properties(self):
|
|
8
|
+
exc = MasstackClientException(0, "")
|
|
9
|
+
|
|
10
|
+
exc._status_code = None
|
|
11
|
+
exc._message = None
|
|
12
|
+
|
|
13
|
+
self.assertEqual(exc.status_code, 0)
|
|
14
|
+
self.assertEqual(exc.message, "")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{masstack_python_client-0.0.1 → masstack_python_client-0.0.2}/src/masstack_python_client/client.py
RENAMED
|
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
|