forked from openapi-generators/openapi-python-client
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
655 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
""" Generate a complete client and verify that it is correct """ | ||
import pytest | ||
|
||
pytest.register_assert_rewrite('end_to_end_tests.end_to_end_live_tests') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import importlib | ||
from typing import Any | ||
|
||
import pytest | ||
|
||
|
||
def live_tests_3_x(): | ||
_test_model_with_discriminated_union() | ||
|
||
|
||
def _import_model(module_name, class_name: str) -> Any: | ||
module = importlib.import_module(f"my_test_api_client.models.{module_name}") | ||
module = importlib.reload(module) # avoid test contamination from previous import | ||
return getattr(module, class_name) | ||
|
||
|
||
def _test_model_with_discriminated_union(): | ||
ModelType1Class = _import_model("a_discriminated_union_type_1", "ADiscriminatedUnionType1") | ||
ModelType2Class = _import_model("a_discriminated_union_type_2", "ADiscriminatedUnionType2") | ||
ModelClass = _import_model("model_with_discriminated_union", "ModelWithDiscriminatedUnion") | ||
|
||
assert ( | ||
ModelClass.from_dict({"discriminated_union": {"modelType": "type1"}}) == | ||
ModelClass(discriminated_union=ModelType1Class.from_dict({"modelType": "type1"})) | ||
) | ||
assert ( | ||
ModelClass.from_dict({"discriminated_union": {"modelType": "type2"}}) == | ||
ModelClass(discriminated_union=ModelType2Class.from_dict({"modelType": "type2"})) | ||
) | ||
with pytest.raises(TypeError): | ||
ModelClass.from_dict({"discriminated_union": {"modelType": "type3"}}) | ||
with pytest.raises(TypeError): | ||
ModelClass.from_dict({"discriminated_union": {}}) |
18 changes: 9 additions & 9 deletions
18
end_to_end_tests/golden-record/my_test_api_client/models/a_discriminated_union_type_1.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 9 additions & 9 deletions
18
end_to_end_tests/golden-record/my_test_api_client/models/a_discriminated_union_type_2.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.