Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Hallett committed Oct 25, 2023
1 parent 3fe6ac9 commit 008ac25
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ clean: ## Clear any cache files and test files
rm -rf **/*.pyc

test: ## Run tests
pytest -vv
pytest -vvv

shell: ## Run an ipython shell
poetry run ipython
Expand Down
19 changes: 16 additions & 3 deletions tests/test_async_generated_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
Identical to the normal tests but just using
the async client instead
"""
import json

from decimal import Decimal

import pytest
from httpx import Response
Expand Down Expand Up @@ -143,6 +144,7 @@ async def test_complex_model_request_complex_model_request_get(respx_mock: MockR
"a_list_of_other_models": [{"key": "first"}],
"a_list_of_strings": ["hello", "world"],
"a_number": 13,
"a_decimal": 0.4,
"a_string": "hello world",
"another_model": {"key": "value"},
}
Expand All @@ -154,8 +156,19 @@ async def test_complex_model_request_complex_model_request_get(respx_mock: MockR
response = await client.complex_model_request_complex_model_request_get()
# Then
assert isinstance(response, schemas.ComplexModelResponse)
# Get around the enums
json.loads(json.dumps(response.model_dump())) == mocked_response
expected_dump_data = {
"a_dict_response": {"dict": "response"},
"a_enum": schemas.ExampleEnum.ONE,
"a_list_of_enums": [schemas.ExampleEnum.ONE, schemas.ExampleEnum.TWO],
"a_list_of_numbers": [1, 2, 3],
"a_list_of_other_models": [{"key": "first"}],
"a_list_of_strings": ["hello", "world"],
"a_number": 13,
"a_decimal": Decimal("0.4"),
"a_string": "hello world",
"another_model": {"key": "value"},
}
assert response.model_dump() == expected_dump_data
assert len(respx_mock.calls) == 1
call = respx_mock.calls[0]
assert call.request.url == BASE_URL + mock_path
Expand Down
18 changes: 15 additions & 3 deletions tests/test_generated_client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import json
from decimal import Decimal

import pytest
from httpx import Response
Expand Down Expand Up @@ -129,6 +129,7 @@ def test_complex_model_request_complex_model_request_get(respx_mock: MockRouter)
"a_list_of_other_models": [{"key": "first"}],
"a_list_of_strings": ["hello", "world"],
"a_number": 13,
"a_decimal": 0.4,
"a_string": "hello world",
"another_model": {"key": "value"},
}
Expand All @@ -140,8 +141,19 @@ def test_complex_model_request_complex_model_request_get(respx_mock: MockRouter)
response = client.complex_model_request_complex_model_request_get()
# Then
assert isinstance(response, schemas.ComplexModelResponse)
# Get around the enums
json.loads(json.dumps(response.model_dump())) == mocked_response
expected_dump_data = {
"a_dict_response": {"dict": "response"},
"a_enum": schemas.ExampleEnum.ONE,
"a_list_of_enums": [schemas.ExampleEnum.ONE, schemas.ExampleEnum.TWO],
"a_list_of_numbers": [1, 2, 3],
"a_list_of_other_models": [{"key": "first"}],
"a_list_of_strings": ["hello", "world"],
"a_number": 13,
"a_decimal": Decimal("0.4"),
"a_string": "hello world",
"another_model": {"key": "value"},
}
assert response.model_dump() == expected_dump_data
assert len(respx_mock.calls) == 1
call = respx_mock.calls[0]
assert call.request.url == BASE_URL + mock_path
Expand Down

0 comments on commit 008ac25

Please sign in to comment.