Skip to content

Commit 94f7321

Browse files
authored
test: minor updates to a few testcases (#195)
This commit makes some minor changes to a few testcases: 1. test_api_exception.py: add tests for some requests.Response operations 2. test_token_manager.py/test_jwt_token_manager.py: modified the abstract base class checks to work in Python 3.12 by matching only part of the error message that appears in the exception 3. I also added python 3.12 to the travis build definition since I found and fixed a couple of unit test errors when using python 3.12 Signed-off-by: Phil Adams <[email protected]>
1 parent 56352ba commit 94f7321

File tree

4 files changed

+8
-10
lines changed

4 files changed

+8
-10
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ dist: jammy
55
matrix:
66
include:
77
- python: 3.8
8-
- python: 3.9
98
- python: 3.10
109
- python: 3.11
10+
- python: 3.12
1111

1212
cache: pip3
1313

test/test_api_exception.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ def test_api_exception():
7474
mock_response = requests.get('https://test-errormessage.com', timeout=None)
7575
exception = ApiException(500, http_response=mock_response)
7676
assert exception.message == 'IAM error message'
77+
assert exception.http_response.text == '{"errorMessage": "IAM error message"}'
78+
assert exception.http_response.content == b'{"errorMessage": "IAM error message"}'
79+
assert exception.http_response.json() == {'errorMessage': 'IAM error message'}
7780

7881
responses.add(
7982
responses.GET,
@@ -86,3 +89,5 @@ def test_api_exception():
8689
exception = ApiException(500, http_response=mock_response)
8790
assert exception.message == 'plain text error'
8891
assert str(exception) == 'Error: plain text error, Status code: 500 , X-global-transaction-id: xx'
92+
assert exception.http_response.text == 'plain text error'
93+
assert exception.http_response.content == b'plain text error'

test/test_jwt_token_manager.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,8 @@ def test_is_token_expired():
9797

9898

9999
def test_abstract_class_instantiation():
100-
with pytest.raises(TypeError) as err:
100+
with pytest.raises(TypeError, match=r"^Can't instantiate abstract class JWTTokenManager.*$"):
101101
JWTTokenManager(None)
102-
assert str(err.value).startswith("Can't instantiate abstract class JWTTokenManager with abstract")
103102

104103

105104
def test_disable_ssl_verification():

test/test_token_manager.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,8 @@ def _save_token_info(self, token_response: dict) -> None:
3434

3535

3636
def test_abstract_class_instantiation():
37-
with pytest.raises(TypeError) as err:
37+
with pytest.raises(TypeError, match=r"^Can't instantiate abstract class TokenManager.*$"):
3838
TokenManager(None)
39-
assert (
40-
str(err.value) == "Can't instantiate abstract class "
41-
"TokenManager with abstract methods "
42-
"_save_token_info, "
43-
"request_token"
44-
)
4539

4640

4741
def requests_request_spy(*args, **kwargs):

0 commit comments

Comments
 (0)