From 6653cedcc7ba83ec536467b19d51c733c3d072d4 Mon Sep 17 00:00:00 2001 From: TIm Clark Date: Tue, 11 Aug 2020 21:38:58 -0400 Subject: [PATCH] [python-experimental] Fix model tests (#7139) * [python-experimental] Fix model tests * Fixes model tests to template off the classname instead of the model's description. * Uses python-experimental templates when generating python-experimental samples * Fix sample file manifest * Restore remaining tests --- .../python-experimental/model_test.mustache | 12 +- ...odels-for-testing-with-http-signature.yaml | 3 +- .../petstore/python-experimental/docs/Pet.md | 1 + ...ditional_properties_with_array_of_enums.py | 7 +- .../python-experimental/test/test_animal.py | 14 +- .../test/test_animal_farm.py | 7 +- .../test/test_array_of_enums.py | 7 +- .../test/test_array_test.py | 7 +- .../python-experimental/test/test_cat.py | 21 +- .../test/test_child_cat.py | 14 +- .../test/test_complex_quadrilateral.py | 14 +- ...composed_one_of_number_with_validations.py | 19 +- .../python-experimental/test/test_dog.py | 14 +- .../python-experimental/test/test_drawing.py | 151 +-------- .../test/test_enum_test.py | 35 +- .../test/test_equilateral_triangle.py | 14 +- .../python-experimental/test/test_fake_api.py | 217 ++---------- .../test/test_file_schema_test_class.py | 7 +- .../python-experimental/test/test_fruit.py | 194 +---------- .../test/test_fruit_req.py | 156 +-------- .../python-experimental/test/test_gm_fruit.py | 203 +----------- .../test/test_grandparent_animal.py | 14 +- .../test/test_inline_response_default.py | 7 +- .../test/test_integer_enum_one_value.py | 11 +- .../test/test_isosceles_triangle.py | 14 +- .../python-experimental/test/test_mammal.py | 24 +- .../python-experimental/test/test_map_test.py | 7 +- ...perties_and_additional_properties_class.py | 7 +- .../test/test_nullable_shape.py | 14 +- .../test/test_number_with_validations.py | 12 +- .../test/test_object_model_with_ref_props.py | 19 +- .../test/test_parent_pet.py | 23 +- .../python-experimental/test/test_pet.py | 14 +- .../python-experimental/test/test_pig.py | 14 +- .../test/test_quadrilateral.py | 21 +- .../test/test_scalene_triangle.py | 14 +- .../python-experimental/test/test_shape.py | 81 +---- .../test/test_shape_or_null.py | 14 +- .../test/test_simple_quadrilateral.py | 14 +- .../test/test_string_enum.py | 19 +- .../python-experimental/test/test_triangle.py | 30 +- .../{tests => tests_manual}/__init__.py | 0 .../test_api_validation.py | 0 ...composed_one_of_number_with_validations.py | 46 +++ .../test_deserialization.py | 0 .../test_discard_unknown_properties.py | 0 .../tests_manual/test_drawing.py | 170 ++++++++++ .../tests_manual/test_fake_api.py | 310 ++++++++++++++++++ .../tests_manual/test_fruit.py | 221 +++++++++++++ .../tests_manual/test_fruit_req.py | 183 +++++++++++ .../tests_manual/test_gm_fruit.py | 230 +++++++++++++ .../test_http_signature.py | 0 .../test_integer_enum_one_value.py | 42 +++ .../tests_manual/test_mammal.py | 49 +++ .../test_number_with_validations.py | 43 +++ .../test_object_model_with_ref_props.py | 48 +++ .../tests_manual/test_parent_pet.py | 50 +++ .../tests_manual/test_quadrilateral.py | 48 +++ .../tests_manual/test_shape.py | 108 ++++++ .../tests_manual/test_string_enum.py | 50 +++ .../tests_manual/test_triangle.py | 55 ++++ .../{tests => tests_manual}/util.py | 0 62 files changed, 1870 insertions(+), 1273 deletions(-) rename samples/openapi3/client/petstore/python-experimental/{tests => tests_manual}/__init__.py (100%) rename samples/openapi3/client/petstore/python-experimental/{tests => tests_manual}/test_api_validation.py (100%) create mode 100644 samples/openapi3/client/petstore/python-experimental/tests_manual/test_composed_one_of_number_with_validations.py rename samples/openapi3/client/petstore/python-experimental/{tests => tests_manual}/test_deserialization.py (100%) rename samples/openapi3/client/petstore/python-experimental/{tests => tests_manual}/test_discard_unknown_properties.py (100%) create mode 100644 samples/openapi3/client/petstore/python-experimental/tests_manual/test_drawing.py create mode 100644 samples/openapi3/client/petstore/python-experimental/tests_manual/test_fake_api.py create mode 100644 samples/openapi3/client/petstore/python-experimental/tests_manual/test_fruit.py create mode 100644 samples/openapi3/client/petstore/python-experimental/tests_manual/test_fruit_req.py create mode 100644 samples/openapi3/client/petstore/python-experimental/tests_manual/test_gm_fruit.py rename samples/openapi3/client/petstore/python-experimental/{tests => tests_manual}/test_http_signature.py (100%) create mode 100644 samples/openapi3/client/petstore/python-experimental/tests_manual/test_integer_enum_one_value.py create mode 100644 samples/openapi3/client/petstore/python-experimental/tests_manual/test_mammal.py create mode 100644 samples/openapi3/client/petstore/python-experimental/tests_manual/test_number_with_validations.py create mode 100644 samples/openapi3/client/petstore/python-experimental/tests_manual/test_object_model_with_ref_props.py create mode 100644 samples/openapi3/client/petstore/python-experimental/tests_manual/test_parent_pet.py create mode 100644 samples/openapi3/client/petstore/python-experimental/tests_manual/test_quadrilateral.py create mode 100644 samples/openapi3/client/petstore/python-experimental/tests_manual/test_shape.py create mode 100644 samples/openapi3/client/petstore/python-experimental/tests_manual/test_string_enum.py create mode 100644 samples/openapi3/client/petstore/python-experimental/tests_manual/test_triangle.py rename samples/openapi3/client/petstore/python-experimental/{tests => tests_manual}/util.py (100%) diff --git a/modules/openapi-generator/src/main/resources/python/python-experimental/model_test.mustache b/modules/openapi-generator/src/main/resources/python/python-experimental/model_test.mustache index c5ffe2c2557..669cc12185f 100644 --- a/modules/openapi-generator/src/main/resources/python/python-experimental/model_test.mustache +++ b/modules/openapi-generator/src/main/resources/python/python-experimental/model_test.mustache @@ -11,11 +11,11 @@ import {{packageName}} {{#imports}} {{{.}}} {{/imports}} -from {{modelPackage}}.{{classFilename}} import {{unescapedDescription}} +from {{modelPackage}}.{{classFilename}} import {{classname}} -class Test{{unescapedDescription}}(unittest.TestCase): - """{{unescapedDescription}} unit test stubs""" +class Test{{classname}}(unittest.TestCase): + """{{classname}} unit test stubs""" def setUp(self): pass @@ -23,10 +23,10 @@ class Test{{unescapedDescription}}(unittest.TestCase): def tearDown(self): pass - def test{{unescapedDescription}}(self): - """Test {{unescapedDescription}}""" + def test{{classname}}(self): + """Test {{classname}}""" # FIXME: construct object with mandatory attributes with example values - # model = {{unescapedDescription}}() # noqa: E501 + # model = {{classname}}() # noqa: E501 pass {{/model}} diff --git a/modules/openapi-generator/src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml b/modules/openapi-generator/src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml index 470f26a611b..32de15d04b8 100644 --- a/modules/openapi-generator/src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml @@ -1407,6 +1407,7 @@ components: name: Tag Pet: type: object + description: Pet object that needs to be added to the store required: - name - photoUrls @@ -2216,4 +2217,4 @@ components: type: string default: '2010-01-01T10:10:10.000111+01:00' example: '2010-01-01T10:10:10.000111+01:00' - format: date-time \ No newline at end of file + format: date-time diff --git a/samples/openapi3/client/petstore/python-experimental/docs/Pet.md b/samples/openapi3/client/petstore/python-experimental/docs/Pet.md index ce09d401c89..1d3349fa9b4 100644 --- a/samples/openapi3/client/petstore/python-experimental/docs/Pet.md +++ b/samples/openapi3/client/petstore/python-experimental/docs/Pet.md @@ -1,5 +1,6 @@ # Pet +Pet object that needs to be added to the store ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_additional_properties_with_array_of_enums.py b/samples/openapi3/client/petstore/python-experimental/test/test_additional_properties_with_array_of_enums.py index f3a248e0da0..fc47f87b365 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_additional_properties_with_array_of_enums.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_additional_properties_with_array_of_enums.py @@ -14,11 +14,8 @@ import sys import unittest import petstore_api -try: - from petstore_api.model import enum_class -except ImportError: - enum_class = sys.modules[ - 'petstore_api.model.enum_class'] +from petstore_api.model.enum_class import EnumClass +globals()['EnumClass'] = EnumClass from petstore_api.model.additional_properties_with_array_of_enums import AdditionalPropertiesWithArrayOfEnums diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_animal.py b/samples/openapi3/client/petstore/python-experimental/test/test_animal.py index 0e1f8507373..a35e4c3469e 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_animal.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_animal.py @@ -14,16 +14,10 @@ import sys import unittest import petstore_api -try: - from petstore_api.model import cat -except ImportError: - cat = sys.modules[ - 'petstore_api.model.cat'] -try: - from petstore_api.model import dog -except ImportError: - dog = sys.modules[ - 'petstore_api.model.dog'] +from petstore_api.model.cat import Cat +from petstore_api.model.dog import Dog +globals()['Cat'] = Cat +globals()['Dog'] = Dog from petstore_api.model.animal import Animal diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_animal_farm.py b/samples/openapi3/client/petstore/python-experimental/test/test_animal_farm.py index f473c465d73..c91e9a0585a 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_animal_farm.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_animal_farm.py @@ -14,11 +14,8 @@ import sys import unittest import petstore_api -try: - from petstore_api.model import animal -except ImportError: - animal = sys.modules[ - 'petstore_api.model.animal'] +from petstore_api.model.animal import Animal +globals()['Animal'] = Animal from petstore_api.model.animal_farm import AnimalFarm diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_array_of_enums.py b/samples/openapi3/client/petstore/python-experimental/test/test_array_of_enums.py index 6d28903bf7e..c33f7189035 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_array_of_enums.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_array_of_enums.py @@ -14,11 +14,8 @@ import sys import unittest import petstore_api -try: - from petstore_api.model import string_enum -except ImportError: - string_enum = sys.modules[ - 'petstore_api.model.string_enum'] +from petstore_api.model.string_enum import StringEnum +globals()['StringEnum'] = StringEnum from petstore_api.model.array_of_enums import ArrayOfEnums diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_array_test.py b/samples/openapi3/client/petstore/python-experimental/test/test_array_test.py index f966f4c0d85..19042d9c461 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_array_test.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_array_test.py @@ -14,11 +14,8 @@ import sys import unittest import petstore_api -try: - from petstore_api.model import read_only_first -except ImportError: - read_only_first = sys.modules[ - 'petstore_api.model.read_only_first'] +from petstore_api.model.read_only_first import ReadOnlyFirst +globals()['ReadOnlyFirst'] = ReadOnlyFirst from petstore_api.model.array_test import ArrayTest diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_cat.py b/samples/openapi3/client/petstore/python-experimental/test/test_cat.py index 8990ae4457f..9008ab8f9a9 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_cat.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_cat.py @@ -14,21 +14,12 @@ import sys import unittest import petstore_api -try: - from petstore_api.model import address -except ImportError: - address = sys.modules[ - 'petstore_api.model.address'] -try: - from petstore_api.model import animal -except ImportError: - animal = sys.modules[ - 'petstore_api.model.animal'] -try: - from petstore_api.model import cat_all_of -except ImportError: - cat_all_of = sys.modules[ - 'petstore_api.model.cat_all_of'] +from petstore_api.model.address import Address +from petstore_api.model.animal import Animal +from petstore_api.model.cat_all_of import CatAllOf +globals()['Address'] = Address +globals()['Animal'] = Animal +globals()['CatAllOf'] = CatAllOf from petstore_api.model.cat import Cat diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_child_cat.py b/samples/openapi3/client/petstore/python-experimental/test/test_child_cat.py index ba3c16543d8..4fd3c6d254c 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_child_cat.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_child_cat.py @@ -14,16 +14,10 @@ import sys import unittest import petstore_api -try: - from petstore_api.model import child_cat_all_of -except ImportError: - child_cat_all_of = sys.modules[ - 'petstore_api.model.child_cat_all_of'] -try: - from petstore_api.model import parent_pet -except ImportError: - parent_pet = sys.modules[ - 'petstore_api.model.parent_pet'] +from petstore_api.model.child_cat_all_of import ChildCatAllOf +from petstore_api.model.parent_pet import ParentPet +globals()['ChildCatAllOf'] = ChildCatAllOf +globals()['ParentPet'] = ParentPet from petstore_api.model.child_cat import ChildCat diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_complex_quadrilateral.py b/samples/openapi3/client/petstore/python-experimental/test/test_complex_quadrilateral.py index 8fb2a290d8a..20f367840e1 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_complex_quadrilateral.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_complex_quadrilateral.py @@ -14,16 +14,10 @@ import sys import unittest import petstore_api -try: - from petstore_api.model import quadrilateral_interface -except ImportError: - quadrilateral_interface = sys.modules[ - 'petstore_api.model.quadrilateral_interface'] -try: - from petstore_api.model import shape_interface -except ImportError: - shape_interface = sys.modules[ - 'petstore_api.model.shape_interface'] +from petstore_api.model.quadrilateral_interface import QuadrilateralInterface +from petstore_api.model.shape_interface import ShapeInterface +globals()['QuadrilateralInterface'] = QuadrilateralInterface +globals()['ShapeInterface'] = ShapeInterface from petstore_api.model.complex_quadrilateral import ComplexQuadrilateral diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_composed_one_of_number_with_validations.py b/samples/openapi3/client/petstore/python-experimental/test/test_composed_one_of_number_with_validations.py index dde99076977..1d19b30d508 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_composed_one_of_number_with_validations.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_composed_one_of_number_with_validations.py @@ -14,11 +14,10 @@ import sys import unittest import petstore_api -try: - from petstore_api.model import animal -except ImportError: - animal = sys.modules[ - 'petstore_api.model.animal'] +from petstore_api.model.animal import Animal +from petstore_api.model.number_with_validations import NumberWithValidations +globals()['Animal'] = Animal +globals()['NumberWithValidations'] = NumberWithValidations from petstore_api.model.composed_one_of_number_with_validations import ComposedOneOfNumberWithValidations @@ -33,13 +32,9 @@ class TestComposedOneOfNumberWithValidations(unittest.TestCase): def testComposedOneOfNumberWithValidations(self): """Test ComposedOneOfNumberWithValidations""" - # we can make an instance that stores float data - inst = ComposedOneOfNumberWithValidations(10.0) - from petstore_api.model import number_with_validations - assert isinstance(inst, number_with_validations.NumberWithValidations) - # we can make an instance that stores object (dict) data - inst = ComposedOneOfNumberWithValidations(class_name="Cat", color="black") - assert isinstance(inst, ComposedOneOfNumberWithValidations) + # FIXME: construct object with mandatory attributes with example values + # model = ComposedOneOfNumberWithValidations() # noqa: E501 + pass if __name__ == '__main__': diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_dog.py b/samples/openapi3/client/petstore/python-experimental/test/test_dog.py index 32633cce7cb..cfd84be5668 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_dog.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_dog.py @@ -14,16 +14,10 @@ import sys import unittest import petstore_api -try: - from petstore_api.model import animal -except ImportError: - animal = sys.modules[ - 'petstore_api.model.animal'] -try: - from petstore_api.model import dog_all_of -except ImportError: - dog_all_of = sys.modules[ - 'petstore_api.model.dog_all_of'] +from petstore_api.model.animal import Animal +from petstore_api.model.dog_all_of import DogAllOf +globals()['Animal'] = Animal +globals()['DogAllOf'] = DogAllOf from petstore_api.model.dog import Dog diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_drawing.py b/samples/openapi3/client/petstore/python-experimental/test/test_drawing.py index 327e01fb849..9148df075d0 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_drawing.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_drawing.py @@ -14,21 +14,14 @@ import sys import unittest import petstore_api -try: - from petstore_api.model import nullable_shape -except ImportError: - nullable_shape = sys.modules[ - 'petstore_api.model.nullable_shape'] -try: - from petstore_api.model import shape -except ImportError: - shape = sys.modules[ - 'petstore_api.model.shape'] -try: - from petstore_api.model import shape_or_null -except ImportError: - shape_or_null = sys.modules[ - 'petstore_api.model.shape_or_null'] +from petstore_api.model.fruit import Fruit +from petstore_api.model.nullable_shape import NullableShape +from petstore_api.model.shape import Shape +from petstore_api.model.shape_or_null import ShapeOrNull +globals()['Fruit'] = Fruit +globals()['NullableShape'] = NullableShape +globals()['Shape'] = Shape +globals()['ShapeOrNull'] = ShapeOrNull from petstore_api.model.drawing import Drawing @@ -41,130 +34,12 @@ class TestDrawing(unittest.TestCase): def tearDown(self): pass - def test_create_instances(self): - """ - Validate instance can be created using pythonic name or OAS names. - """ + def testDrawing(self): + """Test Drawing""" + # FIXME: construct object with mandatory attributes with example values + # model = Drawing() # noqa: E501 + pass - # Validate object can be created using pythonic names. - inst = shape.Shape( - shape_type="Triangle", - triangle_type="IsoscelesTriangle" - ) - from petstore_api.model.isosceles_triangle import IsoscelesTriangle - assert isinstance(inst, IsoscelesTriangle) - - # Validate object can be created using OAS names. - # For example, this can be used to construct objects on the client - # when the input data is available as JSON documents. - data = { - 'shapeType': "Triangle", - 'triangleType': "IsoscelesTriangle" - } - inst = shape.Shape(_spec_property_naming=True, **data) - assert isinstance(inst, IsoscelesTriangle) - - def test_deserialize_oneof_reference(self): - """ - Validate the scenario when the type of a OAS property is 'oneOf', and the 'oneOf' - schema is specified as a reference ($ref), not an inline 'oneOf' schema. - """ - isosceles_triangle = shape.Shape( - shape_type="Triangle", - triangle_type="IsoscelesTriangle" - ) - from petstore_api.model.isosceles_triangle import IsoscelesTriangle - from petstore_api.model.triangle import Triangle - from petstore_api.model.equilateral_triangle import EquilateralTriangle - - assert isinstance(isosceles_triangle, IsoscelesTriangle) - inst = Drawing( - # 'main_shape' has type 'Shape', which is a oneOf [triangle, quadrilateral] - # composed schema. So we should be able to assign a petstore_api.Triangle - # to a 'main_shape'. - main_shape=isosceles_triangle, - shapes=[ - shape.Shape( - shape_type="Triangle", - triangle_type="EquilateralTriangle" - ), - Triangle( - shape_type="Triangle", - triangle_type="IsoscelesTriangle" - ), - EquilateralTriangle( - shape_type="Triangle", - triangle_type="EquilateralTriangle" - ), - shape.Shape( - shape_type="Quadrilateral", - quadrilateral_type="ComplexQuadrilateral" - ), - ], - ) - from petstore_api.model.complex_quadrilateral import ComplexQuadrilateral - assert isinstance(inst, Drawing) - assert isinstance(inst.main_shape, IsoscelesTriangle) - self.assertEqual(len(inst.shapes), 4) - assert isinstance(inst.shapes[0], EquilateralTriangle) - assert isinstance(inst.shapes[1], IsoscelesTriangle) - assert isinstance(inst.shapes[2], EquilateralTriangle) - assert isinstance(inst.shapes[3], ComplexQuadrilateral) - - # Validate we cannot assign the None value to main_shape because the 'null' type - # is not one of the allowed types in the 'Shape' schema. - err_msg = (r"Invalid type for variable '{}'. " - r"Required value type is {} and passed type was {} at {}") - with self.assertRaisesRegex( - petstore_api.ApiTypeError, - err_msg.format(r"main_shape", r"one of \[ComplexQuadrilateral, EquilateralTriangle, IsoscelesTriangle, ScaleneTriangle, SimpleQuadrilateral\]", r"NoneType", r"\['main_shape'\]") - ): - inst = Drawing( - # 'main_shape' has type 'Shape', which is a oneOf [triangle, quadrilateral] - # So the None value should not be allowed and an exception should be raised. - main_shape=None, - ) - - - def test_deserialize_oneof_reference_with_null_type(self): - """ - Validate the scenario when the type of a OAS property is 'oneOf', and the 'oneOf' - schema is specified as a reference ($ref), not an inline 'oneOf' schema. - Further, the 'oneOf' schema has a 'null' type child schema (as introduced in - OpenAPI 3.1). - """ - - # Validate we can assign the None value to shape_or_null, because the 'null' type - # is one of the allowed types in the 'ShapeOrNull' schema. - inst = Drawing( - # 'shape_or_null' has type 'ShapeOrNull', which is a oneOf [null, triangle, quadrilateral] - shape_or_null=None, - ) - assert isinstance(inst, Drawing) - self.assertFalse(hasattr(inst, 'main_shape')) - self.assertTrue(hasattr(inst, 'shape_or_null')) - self.assertIsNone(inst.shape_or_null) - - - def test_deserialize_oneof_reference_with_nullable_type(self): - """ - Validate the scenario when the type of a OAS property is 'oneOf', and the 'oneOf' - schema is specified as a reference ($ref), not an inline 'oneOf' schema. - Further, the 'oneOf' schema has the 'nullable' attribute (as introduced in - OpenAPI 3.0 and deprecated in 3.1). - """ - - # Validate we can assign the None value to nullable_shape, because the NullableShape - # has the 'nullable: true' attribute. - inst = Drawing( - # 'nullable_shape' has type 'NullableShape', which is a oneOf [triangle, quadrilateral] - # and the 'nullable: true' attribute. - nullable_shape=None, - ) - assert isinstance(inst, Drawing) - self.assertFalse(hasattr(inst, 'main_shape')) - self.assertTrue(hasattr(inst, 'nullable_shape')) - self.assertIsNone(inst.nullable_shape) if __name__ == '__main__': unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_enum_test.py b/samples/openapi3/client/petstore/python-experimental/test/test_enum_test.py index 88190693a3b..7b0599f5a98 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_enum_test.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_enum_test.py @@ -14,31 +14,16 @@ import sys import unittest import petstore_api -try: - from petstore_api.model import integer_enum -except ImportError: - integer_enum = sys.modules[ - 'petstore_api.model.integer_enum'] -try: - from petstore_api.model import integer_enum_one_value -except ImportError: - integer_enum_one_value = sys.modules[ - 'petstore_api.model.integer_enum_one_value'] -try: - from petstore_api.model import integer_enum_with_default_value -except ImportError: - integer_enum_with_default_value = sys.modules[ - 'petstore_api.model.integer_enum_with_default_value'] -try: - from petstore_api.model import string_enum -except ImportError: - string_enum = sys.modules[ - 'petstore_api.model.string_enum'] -try: - from petstore_api.model import string_enum_with_default_value -except ImportError: - string_enum_with_default_value = sys.modules[ - 'petstore_api.model.string_enum_with_default_value'] +from petstore_api.model.integer_enum import IntegerEnum +from petstore_api.model.integer_enum_one_value import IntegerEnumOneValue +from petstore_api.model.integer_enum_with_default_value import IntegerEnumWithDefaultValue +from petstore_api.model.string_enum import StringEnum +from petstore_api.model.string_enum_with_default_value import StringEnumWithDefaultValue +globals()['IntegerEnum'] = IntegerEnum +globals()['IntegerEnumOneValue'] = IntegerEnumOneValue +globals()['IntegerEnumWithDefaultValue'] = IntegerEnumWithDefaultValue +globals()['StringEnum'] = StringEnum +globals()['StringEnumWithDefaultValue'] = StringEnumWithDefaultValue from petstore_api.model.enum_test import EnumTest diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_equilateral_triangle.py b/samples/openapi3/client/petstore/python-experimental/test/test_equilateral_triangle.py index f611501c443..1f371b35930 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_equilateral_triangle.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_equilateral_triangle.py @@ -14,16 +14,10 @@ import sys import unittest import petstore_api -try: - from petstore_api.model import shape_interface -except ImportError: - shape_interface = sys.modules[ - 'petstore_api.model.shape_interface'] -try: - from petstore_api.model import triangle_interface -except ImportError: - triangle_interface = sys.modules[ - 'petstore_api.model.triangle_interface'] +from petstore_api.model.shape_interface import ShapeInterface +from petstore_api.model.triangle_interface import TriangleInterface +globals()['ShapeInterface'] = ShapeInterface +globals()['TriangleInterface'] = TriangleInterface from petstore_api.model.equilateral_triangle import EquilateralTriangle diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_fake_api.py b/samples/openapi3/client/petstore/python-experimental/test/test_fake_api.py index 60dcbd549df..48230221f42 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_fake_api.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_fake_api.py @@ -9,25 +9,11 @@ Generated by: https://openapi-generator.tech """ -from collections import namedtuple + import unittest -import json -from unittest.mock import patch import petstore_api from petstore_api.api.fake_api import FakeApi # noqa: E501 -from petstore_api.rest import RESTClientObject, RESTResponse - -HTTPResponse = namedtuple( - 'urllib3_response_HTTPResponse', - ['status', 'reason', 'data', 'getheaders', 'getheader'] -) - -headers = {'Content-Type': 'application/json'} -def get_headers(): - return {} -def get_header(name, default=None): - return {}.get(name, default) class TestFakeApi(unittest.TestCase): @@ -39,72 +25,6 @@ class TestFakeApi(unittest.TestCase): def tearDown(self): pass - @staticmethod - def mock_response(body_value): - http_response = HTTPResponse( - status=200, - reason='OK', - data=json.dumps(body_value).encode('utf-8'), - getheaders=get_headers, - getheader=get_header - ) - return RESTResponse(http_response) - - @staticmethod - def assert_request_called_with(mock_method, url, value): - mock_method.assert_called_with( - 'POST', - url, - _preload_content=True, - _request_timeout=None, - body=value, - headers={ - 'Accept': 'application/json', - 'User-Agent': 'OpenAPI-Generator/1.0.0/python', - 'Content-Type': 'application/json' - }, - post_params=[], - query_params=[] - ) - - - def test_array_model(self): - """Test case for array_model - - """ - from petstore_api.model import animal_farm, animal - endpoint = self.api.array_model - assert endpoint.openapi_types['body'] == (animal_farm.AnimalFarm,) - assert endpoint.settings['response_type'] == (animal_farm.AnimalFarm,) - - # serialization + deserialization works - with patch.object(RESTClientObject, 'request') as mock_method: - cat = animal.Animal(class_name="Cat", color="black") - body = animal_farm.AnimalFarm([cat]) - json_data = [{"className": "Cat", "color": "black"}] - mock_method.return_value = self.mock_response(json_data) - - response = endpoint(body=body) - self.assert_request_called_with(mock_method, 'http://petstore.swagger.io:80/v2/fake/refs/arraymodel', json_data) - - assert isinstance(response, animal_farm.AnimalFarm) - assert response == body - - def test_boolean(self): - """Test case for boolean - - """ - endpoint = self.api.boolean - assert endpoint.openapi_types['body'] == (bool,) - assert endpoint.settings['response_type'] == (bool,) - - def test_fake_health_get(self): - """Test case for fake_health_get - - Health check endpoint # noqa: E501 - """ - pass - def test_additional_properties_with_array_of_enums(self): """Test case for additional_properties_with_array_of_enums @@ -112,138 +32,61 @@ class TestFakeApi(unittest.TestCase): """ pass + def test_array_model(self): + """Test case for array_model + + """ + pass + def test_array_of_enums(self): """Test case for array_of_enums Array of Enums # noqa: E501 """ - from petstore_api.model import array_of_enums, string_enum - endpoint = self.api.array_of_enums - assert endpoint.openapi_types['array_of_enums'] == (array_of_enums.ArrayOfEnums,) - assert endpoint.settings['response_type'] == (array_of_enums.ArrayOfEnums,) + pass - # serialization + deserialization works - with patch.object(RESTClientObject, 'request') as mock_method: - value = [string_enum.StringEnum("placed")] - body = array_of_enums.ArrayOfEnums(value) - value_simple = ["placed"] - mock_method.return_value = self.mock_response(value_simple) - - response = endpoint(array_of_enums=body) - self.assert_request_called_with(mock_method, 'http://petstore.swagger.io:80/v2/fake/refs/array-of-enums', value_simple) - - assert isinstance(response, array_of_enums.ArrayOfEnums) - assert response.value == value - - def test_number_with_validations(self): - """Test case for number_with_validations + def test_boolean(self): + """Test case for boolean """ - from petstore_api.model import number_with_validations - endpoint = self.api.number_with_validations - assert endpoint.openapi_types['body'] == (number_with_validations.NumberWithValidations,) - assert endpoint.settings['response_type'] == (number_with_validations.NumberWithValidations,) - - # serialization + deserialization works - with patch.object(RESTClientObject, 'request') as mock_method: - value = 10.0 - body = number_with_validations.NumberWithValidations(value) - mock_method.return_value = self.mock_response(value) - - response = endpoint(body=body) - self.assert_request_called_with(mock_method, 'http://petstore.swagger.io:80/v2/fake/refs/number', value) - - assert isinstance(response, number_with_validations.NumberWithValidations) - assert response.value == value - - def test_object_model_with_ref_props(self): - """Test case for object_model_with_ref_props - - """ - from petstore_api.model import object_model_with_ref_props - endpoint = self.api.object_model_with_ref_props - assert endpoint.openapi_types['body'] == (object_model_with_ref_props.ObjectModelWithRefProps,) - assert endpoint.settings['response_type'] == (object_model_with_ref_props.ObjectModelWithRefProps,) + pass def test_composed_one_of_number_with_validations(self): """Test case for composed_one_of_number_with_validations """ - from petstore_api.model import animal, composed_one_of_number_with_validations, number_with_validations - endpoint = self.api.composed_one_of_number_with_validations - assert endpoint.openapi_types['composed_one_of_number_with_validations'] == ( - composed_one_of_number_with_validations.ComposedOneOfNumberWithValidations,) - assert endpoint.settings['response_type'] == ( - composed_one_of_number_with_validations.ComposedOneOfNumberWithValidations,) + pass - # serialization + deserialization works - num_with_validations = number_with_validations.NumberWithValidations(10.0) - cat_in_composed = composed_one_of_number_with_validations.ComposedOneOfNumberWithValidations( - class_name="Cat", color="black" - ) - import datetime - date = datetime.date(1970, 1, 1) - body_value_simple = [ - (num_with_validations, 10.0), - (cat_in_composed, {"className": "Cat", "color": "black"}), - (None, None), - (date, '1970-01-01'), - ] - for (body, value_simple) in body_value_simple: - with patch.object(RESTClientObject, 'request') as mock_method: - mock_method.return_value = self.mock_response(value_simple) + def test_fake_health_get(self): + """Test case for fake_health_get - response = endpoint(composed_one_of_number_with_validations=body) - self.assert_request_called_with( - mock_method, - 'http://petstore.swagger.io:80/v2/fake/refs/composed_one_of_number_with_validations', - value_simple - ) + Health check endpoint # noqa: E501 + """ + pass - assert isinstance(response, body.__class__) - assert response == body + def test_number_with_validations(self): + """Test case for number_with_validations + + """ + pass + + def test_object_model_with_ref_props(self): + """Test case for object_model_with_ref_props + + """ + pass def test_string(self): """Test case for string """ - endpoint = self.api.string - assert endpoint.openapi_types['body'] == (str,) - assert endpoint.settings['response_type'] == (str,) - - # serialization + deserialization works - with patch.object(RESTClientObject, 'request') as mock_method: - body = "blah" - value_simple = body - mock_method.return_value = self.mock_response(value_simple) - - response = endpoint(body=body) - self.assert_request_called_with(mock_method, 'http://petstore.swagger.io:80/v2/fake/refs/string', value_simple) - - assert isinstance(response, str) - assert response == value_simple + pass def test_string_enum(self): """Test case for string_enum """ - from petstore_api.model import string_enum - endpoint = self.api.string_enum - assert endpoint.openapi_types['body'] == (string_enum.StringEnum,) - assert endpoint.settings['response_type'] == (string_enum.StringEnum,) - - # serialization + deserialization works - from petstore_api.rest import RESTClientObject, RESTResponse - with patch.object(RESTClientObject, 'request') as mock_method: - value = "placed" - body = string_enum.StringEnum(value) - mock_method.return_value = self.mock_response(value) - - response = endpoint(body=body) - self.assert_request_called_with(mock_method, 'http://petstore.swagger.io:80/v2/fake/refs/enum', value) - - assert isinstance(response, string_enum.StringEnum) - assert response.value == value + pass def test_test_body_with_file_schema(self): """Test case for test_body_with_file_schema diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_file_schema_test_class.py b/samples/openapi3/client/petstore/python-experimental/test/test_file_schema_test_class.py index ec38c523c7d..6366cd33470 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_file_schema_test_class.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_file_schema_test_class.py @@ -14,11 +14,8 @@ import sys import unittest import petstore_api -try: - from petstore_api.model import file -except ImportError: - file = sys.modules[ - 'petstore_api.model.file'] +from petstore_api.model.file import File +globals()['File'] = File from petstore_api.model.file_schema_test_class import FileSchemaTestClass diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_fruit.py b/samples/openapi3/client/petstore/python-experimental/test/test_fruit.py index fac0319663e..6527951571c 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_fruit.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_fruit.py @@ -14,16 +14,10 @@ import sys import unittest import petstore_api -try: - from petstore_api.model import apple -except ImportError: - apple = sys.modules[ - 'petstore_api.model.apple'] -try: - from petstore_api.model import banana -except ImportError: - banana = sys.modules[ - 'petstore_api.model.banana'] +from petstore_api.model.apple import Apple +from petstore_api.model.banana import Banana +globals()['Apple'] = Apple +globals()['Banana'] = Banana from petstore_api.model.fruit import Fruit @@ -38,184 +32,10 @@ class TestFruit(unittest.TestCase): def testFruit(self): """Test Fruit""" + # FIXME: construct object with mandatory attributes with example values + # model = Fruit() # noqa: E501 + pass - # make an instance of Fruit, a composed schema oneOf model - # banana test - length_cm = 20.3 - color = 'yellow' - fruit = Fruit(length_cm=length_cm, color=color) - # check its properties - self.assertEqual(fruit.length_cm, length_cm) - self.assertEqual(fruit['length_cm'], length_cm) - self.assertEqual(getattr(fruit, 'length_cm'), length_cm) - self.assertEqual(fruit.color, color) - self.assertEqual(fruit['color'], color) - self.assertEqual(getattr(fruit, 'color'), color) - # check the dict representation - self.assertEqual( - fruit.to_dict(), - { - 'length_cm': length_cm, - 'color': color - } - ) - # setting a value that doesn't exist raises an exception - # with a key - with self.assertRaises(AttributeError): - fruit['invalid_variable'] = 'some value' - - # Assert that we can call the builtin hasattr() function. - # hasattr should return False for non-existent attribute. - # Internally hasattr catches the AttributeError exception. - self.assertFalse(hasattr(fruit, 'invalid_variable')) - - # Assert that we can call the builtin hasattr() function. - # hasattr should return True for existent attribute. - self.assertTrue(hasattr(fruit, 'color')) - - # with setattr - with self.assertRaises(AttributeError): - setattr(fruit, 'invalid_variable', 'some value') - - # getting a value that doesn't exist raises an exception - # with a key - with self.assertRaises(AttributeError): - invalid_variable = fruit['cultivar'] - # with getattr - # Per Python doc, if the named attribute does not exist, - # default is returned if provided. - self.assertEqual(getattr(fruit, 'cultivar', 'some value'), 'some value') - - # Per Python doc, if the named attribute does not exist, - # default is returned if provided, otherwise AttributeError is raised. - with self.assertRaises(AttributeError): - getattr(fruit, 'cultivar') - - # make sure that the ModelComposed class properties are correct - # model._composed_schemas stores the anyOf/allOf/oneOf info - self.assertEqual( - fruit._composed_schemas, - { - 'anyOf': [], - 'allOf': [], - 'oneOf': [ - apple.Apple, - banana.Banana, - ], - } - ) - # model._composed_instances is a list of the instances that were - # made from the anyOf/allOf/OneOf classes in model._composed_schemas - for composed_instance in fruit._composed_instances: - if composed_instance.__class__ == banana.Banana: - banana_instance = composed_instance - self.assertEqual( - fruit._composed_instances, - [banana_instance] - ) - # model._var_name_to_model_instances maps the variable name to the - # model instances which store that variable - self.assertEqual( - fruit._var_name_to_model_instances, - { - 'color': [fruit], - 'length_cm': [fruit, banana_instance], - 'cultivar': [fruit], - 'origin': [fruit], - } - ) - # model._additional_properties_model_instances stores a list of - # models which have the property additional_properties_type != None - self.assertEqual( - fruit._additional_properties_model_instances, [] - ) - - # if we modify one of the properties owned by multiple - # model_instances we get an exception when we try to access that - # property because the retrieved values are not all the same - banana_instance.length_cm = 4.56 - with self.assertRaises(petstore_api.ApiValueError): - some_length_cm = fruit.length_cm - - # including extra parameters raises an exception - with self.assertRaises(petstore_api.ApiValueError): - fruit = Fruit( - color=color, - length_cm=length_cm, - unknown_property='some value' - ) - - # including input parameters for two oneOf instances raise an exception - with self.assertRaises(petstore_api.ApiValueError): - fruit = Fruit( - length_cm=length_cm, - cultivar='granny smith' - ) - - # make an instance of Fruit, a composed schema oneOf model - # apple test - color = 'red' - cultivar = 'golden delicious' - fruit = Fruit(color=color, cultivar=cultivar) - # check its properties - self.assertEqual(fruit.color, color) - self.assertEqual(fruit['color'], color) - self.assertEqual(getattr(fruit, 'color'), color) - self.assertEqual(fruit.cultivar, cultivar) - self.assertEqual(fruit['cultivar'], cultivar) - self.assertEqual(getattr(fruit, 'cultivar'), cultivar) - # check the dict representation - self.assertEqual( - fruit.to_dict(), - { - 'color': color, - 'cultivar': cultivar - } - ) - - # model._composed_instances is a list of the instances that were - # made from the anyOf/allOf/OneOf classes in model._composed_schemas - for composed_instance in fruit._composed_instances: - if composed_instance.__class__ == apple.Apple: - apple_instance = composed_instance - self.assertEqual( - fruit._composed_instances, - [apple_instance] - ) - # model._var_name_to_model_instances maps the variable name to the - # model instances which store that variable - self.assertEqual( - fruit._var_name_to_model_instances, - { - 'color': [fruit], - 'length_cm': [fruit], - 'cultivar': [fruit, apple_instance], - 'origin': [fruit, apple_instance], - } - ) - # model._additional_properties_model_instances stores a list of - # models which have the property additional_properties_type != None - self.assertEqual( - fruit._additional_properties_model_instances, [] - ) - - def testFruitNullValue(self): - # Since 'apple' is nullable, validate we can create an apple with the 'null' value. - fruit = apple.Apple(None) - self.assertIsNone(fruit) - - # 'banana' is not nullable. - with self.assertRaises(petstore_api.ApiTypeError): - banana.Banana(None) - - # Since 'fruit' has oneOf 'apple', 'banana' and 'apple' is nullable, - # validate we can create a fruit with the 'null' value. - fruit = Fruit(None) - self.assertIsNone(fruit) - - # Redo the same thing, this time passing a null Apple to the Fruit constructor. - fruit = Fruit(apple.Apple(None)) - self.assertIsNone(fruit) if __name__ == '__main__': unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_fruit_req.py b/samples/openapi3/client/petstore/python-experimental/test/test_fruit_req.py index 3e637c3226a..8e6bebb0b5e 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_fruit_req.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_fruit_req.py @@ -14,16 +14,10 @@ import sys import unittest import petstore_api -try: - from petstore_api.model import apple_req -except ImportError: - apple_req = sys.modules[ - 'petstore_api.model.apple_req'] -try: - from petstore_api.model import banana_req -except ImportError: - banana_req = sys.modules[ - 'petstore_api.model.banana_req'] +from petstore_api.model.apple_req import AppleReq +from petstore_api.model.banana_req import BananaReq +globals()['AppleReq'] = AppleReq +globals()['BananaReq'] = BananaReq from petstore_api.model.fruit_req import FruitReq @@ -38,146 +32,10 @@ class TestFruitReq(unittest.TestCase): def testFruitReq(self): """Test FruitReq""" + # FIXME: construct object with mandatory attributes with example values + # model = FruitReq() # noqa: E501 + pass - # make an instance of Fruit, a composed schema oneOf model - # banana test - length_cm = 20.3 - fruit = FruitReq(length_cm=length_cm) - # check its properties - self.assertEqual(fruit.length_cm, length_cm) - self.assertEqual(fruit['length_cm'], length_cm) - self.assertEqual(getattr(fruit, 'length_cm'), length_cm) - # check the dict representation - self.assertEqual( - fruit.to_dict(), - { - 'length_cm': length_cm, - } - ) - # setting a value that doesn't exist raises an exception - # with a key - with self.assertRaises(AttributeError): - fruit['invalid_variable'] = 'some value' - # with setattr - with self.assertRaises(AttributeError): - setattr(fruit, 'invalid_variable', 'some value') - - # getting a value that doesn't exist raises an exception - # with a key - with self.assertRaises(AttributeError): - invalid_variable = fruit['cultivar'] - # with getattr - self.assertEqual(getattr(fruit, 'cultivar', 'some value'), 'some value') - - with self.assertRaises(AttributeError): - getattr(fruit, 'cultivar') - - # make sure that the ModelComposed class properties are correct - # model._composed_schemas stores the anyOf/allOf/oneOf info - self.assertEqual( - fruit._composed_schemas, - { - 'anyOf': [], - 'allOf': [], - 'oneOf': [ - apple_req.AppleReq, - banana_req.BananaReq, - type(None), - ], - } - ) - # model._composed_instances is a list of the instances that were - # made from the anyOf/allOf/OneOf classes in model._composed_schemas - for composed_instance in fruit._composed_instances: - if composed_instance.__class__ == banana_req.BananaReq: - banana_instance = composed_instance - self.assertEqual( - fruit._composed_instances, - [banana_instance] - ) - # model._var_name_to_model_instances maps the variable name to the - # model instances which store that variable - self.assertEqual( - fruit._var_name_to_model_instances, - { - 'length_cm': [fruit, banana_instance], - 'cultivar': [fruit], - 'mealy': [fruit], - 'sweet': [fruit, banana_instance], - } - ) - # model._additional_properties_model_instances stores a list of - # models which have the property additional_properties_type != None - self.assertEqual( - fruit._additional_properties_model_instances, [] - ) - - # if we modify one of the properties owned by multiple - # model_instances we get an exception when we try to access that - # property because the retrieved values are not all the same - banana_instance.length_cm = 4.56 - with self.assertRaises(petstore_api.ApiValueError): - some_length_cm = fruit.length_cm - - # including extra parameters raises an exception - with self.assertRaises(petstore_api.ApiValueError): - fruit = FruitReq( - length_cm=length_cm, - unknown_property='some value' - ) - - # including input parameters for two oneOf instances raise an exception - with self.assertRaises(petstore_api.ApiValueError): - fruit = FruitReq( - length_cm=length_cm, - cultivar='granny smith' - ) - - # make an instance of Fruit, a composed schema oneOf model - # apple test - cultivar = 'golden delicious' - fruit = FruitReq(cultivar=cultivar) - # check its properties - self.assertEqual(fruit.cultivar, cultivar) - self.assertEqual(fruit['cultivar'], cultivar) - self.assertEqual(getattr(fruit, 'cultivar'), cultivar) - # check the dict representation - self.assertEqual( - fruit.to_dict(), - { - 'cultivar': cultivar - } - ) - - # model._composed_instances is a list of the instances that were - # made from the anyOf/allOf/OneOf classes in model._composed_schemas - for composed_instance in fruit._composed_instances: - if composed_instance.__class__ == apple_req.AppleReq: - apple_instance = composed_instance - self.assertEqual( - fruit._composed_instances, - [apple_instance] - ) - # model._var_name_to_model_instances maps the variable name to the - # model instances which store that variable - self.assertEqual( - fruit._var_name_to_model_instances, - { - 'length_cm': [fruit], - 'cultivar': [fruit, apple_instance], - 'mealy': [fruit, apple_instance], - 'sweet': [fruit], - } - ) - # model._additional_properties_model_instances stores a list of - # models which have the property additional_properties_type != None - self.assertEqual( - fruit._additional_properties_model_instances, [] - ) - - # we can pass in None - fruit = FruitReq(None) - assert fruit is None if __name__ == '__main__': unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_gm_fruit.py b/samples/openapi3/client/petstore/python-experimental/test/test_gm_fruit.py index 85d0fcf9b1c..bae41bb7555 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_gm_fruit.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_gm_fruit.py @@ -14,16 +14,10 @@ import sys import unittest import petstore_api -try: - from petstore_api.model import apple -except ImportError: - apple = sys.modules[ - 'petstore_api.model.apple'] -try: - from petstore_api.model import banana -except ImportError: - banana = sys.modules[ - 'petstore_api.model.banana'] +from petstore_api.model.apple import Apple +from petstore_api.model.banana import Banana +globals()['Apple'] = Apple +globals()['Banana'] = Banana from petstore_api.model.gm_fruit import GmFruit @@ -38,193 +32,10 @@ class TestGmFruit(unittest.TestCase): def testGmFruit(self): """Test GmFruit""" + # FIXME: construct object with mandatory attributes with example values + # model = GmFruit() # noqa: E501 + pass - # make an instance of GmFruit, a composed schema anyOf model - # banana test - length_cm = 20.3 - color = 'yellow' - fruit = GmFruit(length_cm=length_cm, color=color) - # check its properties - self.assertEqual(fruit.length_cm, length_cm) - self.assertEqual(fruit['length_cm'], length_cm) - self.assertEqual(getattr(fruit, 'length_cm'), length_cm) - self.assertEqual(fruit.color, color) - self.assertEqual(fruit['color'], color) - self.assertEqual(getattr(fruit, 'color'), color) - # check the dict representation - self.assertEqual( - fruit.to_dict(), - { - 'length_cm': length_cm, - 'color': color - } - ) - # setting a value that doesn't exist raises an exception - # with a key - with self.assertRaises(AttributeError): - fruit['invalid_variable'] = 'some value' - # with setattr - with self.assertRaises(AttributeError): - setattr(fruit, 'invalid_variable', 'some value') - - # getting a value that doesn't exist raises an exception - # with a key - with self.assertRaises(AttributeError): - invalid_variable = fruit['cultivar'] - # with getattr - self.assertTrue(getattr(fruit, 'cultivar', 'some value'), 'some value') - - with self.assertRaises(AttributeError): - invalid_variable = getattr(fruit, 'cultivar') - - # make sure that the ModelComposed class properties are correct - # model._composed_schemas stores the anyOf/allOf/oneOf info - self.assertEqual( - fruit._composed_schemas, - { - 'anyOf': [ - apple.Apple, - banana.Banana, - ], - 'allOf': [], - 'oneOf': [], - } - ) - # model._composed_instances is a list of the instances that were - # made from the anyOf/allOf/OneOf classes in model._composed_schemas - for composed_instance in fruit._composed_instances: - if composed_instance.__class__ == banana.Banana: - banana_instance = composed_instance - self.assertEqual( - fruit._composed_instances, - [banana_instance] - ) - # model._var_name_to_model_instances maps the variable name to the - # model instances which store that variable - self.assertEqual( - fruit._var_name_to_model_instances, - { - 'color': [fruit], - 'length_cm': [fruit, banana_instance], - 'cultivar': [fruit], - 'origin': [fruit], - } - ) - # model._additional_properties_model_instances stores a list of - # models which have the property additional_properties_type != None - self.assertEqual( - fruit._additional_properties_model_instances, [] - ) - - # if we modify one of the properties owned by multiple - # model_instances we get an exception when we try to access that - # property because the retrieved values are not all the same - banana_instance.length_cm = 4.56 - with self.assertRaises(petstore_api.ApiValueError): - some_length_cm = fruit.length_cm - - # including extra parameters raises an exception - with self.assertRaises(petstore_api.ApiValueError): - fruit = GmFruit( - color=color, - length_cm=length_cm, - unknown_property='some value' - ) - - # including input parameters for both anyOf instances works - cultivar = 'banaple' - color = 'orange' - fruit = GmFruit( - color=color, - cultivar=cultivar, - length_cm=length_cm - ) - self.assertEqual(fruit.color, color) - self.assertEqual(fruit['color'], color) - self.assertEqual(getattr(fruit, 'color'), color) - self.assertEqual(fruit.cultivar, cultivar) - self.assertEqual(fruit['cultivar'], cultivar) - self.assertEqual(getattr(fruit, 'cultivar'), cultivar) - self.assertEqual(fruit.length_cm, length_cm) - self.assertEqual(fruit['length_cm'], length_cm) - self.assertEqual(getattr(fruit, 'length_cm'), length_cm) - - # model._composed_instances is a list of the instances that were - # made from the anyOf/allOf/OneOf classes in model._composed_schemas - for composed_instance in fruit._composed_instances: - if composed_instance.__class__ == apple.Apple: - apple_instance = composed_instance - elif composed_instance.__class__ == banana.Banana: - banana_instance = composed_instance - self.assertEqual( - fruit._composed_instances, - [apple_instance, banana_instance] - ) - # model._var_name_to_model_instances maps the variable name to the - # model instances which store that variable - self.assertEqual( - fruit._var_name_to_model_instances, - { - 'color': [fruit], - 'length_cm': [fruit, banana_instance], - 'cultivar': [fruit, apple_instance], - 'origin': [fruit, apple_instance], - } - ) - - # make an instance of GmFruit, a composed schema anyOf model - # apple test - color = 'red' - cultivar = 'golden delicious' - origin = 'California' - fruit = GmFruit(color=color, cultivar=cultivar, origin=origin) - # check its properties - self.assertEqual(fruit.color, color) - self.assertEqual(fruit['color'], color) - self.assertEqual(getattr(fruit, 'color'), color) - self.assertEqual(fruit.cultivar, cultivar) - self.assertEqual(fruit['cultivar'], cultivar) - self.assertEqual(getattr(fruit, 'cultivar'), cultivar) - - self.assertEqual(fruit.origin, origin) - self.assertEqual(fruit['origin'], origin) - self.assertEqual(getattr(fruit, 'origin'), origin) - - # check the dict representation - self.assertEqual( - fruit.to_dict(), - { - 'color': color, - 'cultivar': cultivar, - 'origin': origin, - } - ) - - # model._composed_instances is a list of the instances that were - # made from the anyOf/allOf/OneOf classes in model._composed_schemas - for composed_instance in fruit._composed_instances: - if composed_instance.__class__ == apple.Apple: - apple_instance = composed_instance - self.assertEqual( - fruit._composed_instances, - [apple_instance] - ) - # model._var_name_to_model_instances maps the variable name to the - # model instances which store that variable - self.assertEqual( - fruit._var_name_to_model_instances, - { - 'color': [fruit], - 'length_cm': [fruit], - 'cultivar': [fruit, apple_instance], - 'origin': [fruit, apple_instance], - } - ) - # model._additional_properties_model_instances stores a list of - # models which have the property additional_properties_type != None - self.assertEqual( - fruit._additional_properties_model_instances, [] - ) if __name__ == '__main__': unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_grandparent_animal.py b/samples/openapi3/client/petstore/python-experimental/test/test_grandparent_animal.py index 517ccf3114c..9c84811bd80 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_grandparent_animal.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_grandparent_animal.py @@ -14,16 +14,10 @@ import sys import unittest import petstore_api -try: - from petstore_api.model import child_cat -except ImportError: - child_cat = sys.modules[ - 'petstore_api.model.child_cat'] -try: - from petstore_api.model import parent_pet -except ImportError: - parent_pet = sys.modules[ - 'petstore_api.model.parent_pet'] +from petstore_api.model.child_cat import ChildCat +from petstore_api.model.parent_pet import ParentPet +globals()['ChildCat'] = ChildCat +globals()['ParentPet'] = ParentPet from petstore_api.model.grandparent_animal import GrandparentAnimal diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_inline_response_default.py b/samples/openapi3/client/petstore/python-experimental/test/test_inline_response_default.py index 74ab5c2be31..3b3fc2ddcdf 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_inline_response_default.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_inline_response_default.py @@ -14,11 +14,8 @@ import sys import unittest import petstore_api -try: - from petstore_api.model import foo -except ImportError: - foo = sys.modules[ - 'petstore_api.model.foo'] +from petstore_api.model.foo import Foo +globals()['Foo'] = Foo from petstore_api.model.inline_response_default import InlineResponseDefault diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_integer_enum_one_value.py b/samples/openapi3/client/petstore/python-experimental/test/test_integer_enum_one_value.py index eff7298d9f3..0f5c3bef7b9 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_integer_enum_one_value.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_integer_enum_one_value.py @@ -28,14 +28,9 @@ class TestIntegerEnumOneValue(unittest.TestCase): def testIntegerEnumOneValue(self): """Test IntegerEnumOneValue""" - model = IntegerEnumOneValue() - assert model.value == 0, "With only one option, the value is assigned automatically" - - model = IntegerEnumOneValue(0) - assert model.value == 0, "We can also pass in the value as a positional arg" - - model = IntegerEnumOneValue(value=0) - assert model.value == 0, "We can also pass in the value as a named argument" + # FIXME: construct object with mandatory attributes with example values + # model = IntegerEnumOneValue() # noqa: E501 + pass if __name__ == '__main__': diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_isosceles_triangle.py b/samples/openapi3/client/petstore/python-experimental/test/test_isosceles_triangle.py index e4fe2ccbd7e..a426514a5ee 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_isosceles_triangle.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_isosceles_triangle.py @@ -14,16 +14,10 @@ import sys import unittest import petstore_api -try: - from petstore_api.model import shape_interface -except ImportError: - shape_interface = sys.modules[ - 'petstore_api.model.shape_interface'] -try: - from petstore_api.model import triangle_interface -except ImportError: - triangle_interface = sys.modules[ - 'petstore_api.model.triangle_interface'] +from petstore_api.model.shape_interface import ShapeInterface +from petstore_api.model.triangle_interface import TriangleInterface +globals()['ShapeInterface'] = ShapeInterface +globals()['TriangleInterface'] = TriangleInterface from petstore_api.model.isosceles_triangle import IsoscelesTriangle diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_mammal.py b/samples/openapi3/client/petstore/python-experimental/test/test_mammal.py index 3ed00dd7981..ee379a52a64 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_mammal.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_mammal.py @@ -14,16 +14,12 @@ import sys import unittest import petstore_api -try: - from petstore_api.model import whale -except ImportError: - whale = sys.modules[ - 'petstore_api.model.whale'] -try: - from petstore_api.model import zebra -except ImportError: - zebra = sys.modules[ - 'petstore_api.model.zebra'] +from petstore_api.model.pig import Pig +from petstore_api.model.whale import Whale +from petstore_api.model.zebra import Zebra +globals()['Pig'] = Pig +globals()['Whale'] = Whale +globals()['Zebra'] = Zebra from petstore_api.model.mammal import Mammal @@ -38,11 +34,9 @@ class TestMammal(unittest.TestCase): def testMammal(self): """Test Mammal""" - - # tests that we can make a BasquePig by traveling through descendant discriminator in Pig - model = Mammal(class_name="BasquePig") - from petstore_api.model import basque_pig - assert isinstance(model, basque_pig.BasquePig) + # FIXME: construct object with mandatory attributes with example values + # model = Mammal() # noqa: E501 + pass if __name__ == '__main__': diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_map_test.py b/samples/openapi3/client/petstore/python-experimental/test/test_map_test.py index f588781f13f..9cddd802e56 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_map_test.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_map_test.py @@ -14,11 +14,8 @@ import sys import unittest import petstore_api -try: - from petstore_api.model import string_boolean_map -except ImportError: - string_boolean_map = sys.modules[ - 'petstore_api.model.string_boolean_map'] +from petstore_api.model.string_boolean_map import StringBooleanMap +globals()['StringBooleanMap'] = StringBooleanMap from petstore_api.model.map_test import MapTest diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_mixed_properties_and_additional_properties_class.py b/samples/openapi3/client/petstore/python-experimental/test/test_mixed_properties_and_additional_properties_class.py index 7de400b004f..60b77497796 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_mixed_properties_and_additional_properties_class.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_mixed_properties_and_additional_properties_class.py @@ -14,11 +14,8 @@ import sys import unittest import petstore_api -try: - from petstore_api.model import animal -except ImportError: - animal = sys.modules[ - 'petstore_api.model.animal'] +from petstore_api.model.animal import Animal +globals()['Animal'] = Animal from petstore_api.model.mixed_properties_and_additional_properties_class import MixedPropertiesAndAdditionalPropertiesClass diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_nullable_shape.py b/samples/openapi3/client/petstore/python-experimental/test/test_nullable_shape.py index 32721b00888..c78e2d09e14 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_nullable_shape.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_nullable_shape.py @@ -14,16 +14,10 @@ import sys import unittest import petstore_api -try: - from petstore_api.model import quadrilateral -except ImportError: - quadrilateral = sys.modules[ - 'petstore_api.model.quadrilateral'] -try: - from petstore_api.model import triangle -except ImportError: - triangle = sys.modules[ - 'petstore_api.model.triangle'] +from petstore_api.model.quadrilateral import Quadrilateral +from petstore_api.model.triangle import Triangle +globals()['Quadrilateral'] = Quadrilateral +globals()['Triangle'] = Triangle from petstore_api.model.nullable_shape import NullableShape diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_number_with_validations.py b/samples/openapi3/client/petstore/python-experimental/test/test_number_with_validations.py index f4264ca82ea..80c25c556f8 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_number_with_validations.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_number_with_validations.py @@ -28,15 +28,9 @@ class TestNumberWithValidations(unittest.TestCase): def testNumberWithValidations(self): """Test NumberWithValidations""" - valid_values = [10.0, 15.0, 20.0] - for valid_value in valid_values: - model = NumberWithValidations(valid_value) - assert model.value == valid_value - - invalid_values = [9.0, 21.0] - for invalid_value in invalid_values: - with self.assertRaises(petstore_api.ApiValueError): - NumberWithValidations(invalid_value) + # FIXME: construct object with mandatory attributes with example values + # model = NumberWithValidations() # noqa: E501 + pass if __name__ == '__main__': diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_object_model_with_ref_props.py b/samples/openapi3/client/petstore/python-experimental/test/test_object_model_with_ref_props.py index 9ce55c75bb8..95f082b6613 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_object_model_with_ref_props.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_object_model_with_ref_props.py @@ -14,11 +14,8 @@ import sys import unittest import petstore_api -try: - from petstore_api.model import number_with_validations -except ImportError: - number_with_validations = sys.modules[ - 'petstore_api.model.number_with_validations'] +from petstore_api.model.number_with_validations import NumberWithValidations +globals()['NumberWithValidations'] = NumberWithValidations from petstore_api.model.object_model_with_ref_props import ObjectModelWithRefProps @@ -33,15 +30,9 @@ class TestObjectModelWithRefProps(unittest.TestCase): def testObjectModelWithRefProps(self): """Test ObjectModelWithRefProps""" - from petstore_api.model.number_with_validations import NumberWithValidations - self.assertEqual( - ObjectModelWithRefProps.openapi_types, - { - 'my_number': (NumberWithValidations,), - 'my_string': (str,), - 'my_boolean': (bool,), - } - ) + # FIXME: construct object with mandatory attributes with example values + # model = ObjectModelWithRefProps() # noqa: E501 + pass if __name__ == '__main__': diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_parent_pet.py b/samples/openapi3/client/petstore/python-experimental/test/test_parent_pet.py index a57f9b8527a..dd35d7e7f4d 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_parent_pet.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_parent_pet.py @@ -14,16 +14,10 @@ import sys import unittest import petstore_api -try: - from petstore_api.model import child_cat -except ImportError: - child_cat = sys.modules[ - 'petstore_api.model.child_cat'] -try: - from petstore_api.model import grandparent_animal -except ImportError: - grandparent_animal = sys.modules[ - 'petstore_api.model.grandparent_animal'] +from petstore_api.model.child_cat import ChildCat +from petstore_api.model.grandparent_animal import GrandparentAnimal +globals()['ChildCat'] = ChildCat +globals()['GrandparentAnimal'] = GrandparentAnimal from petstore_api.model.parent_pet import ParentPet @@ -38,12 +32,9 @@ class TestParentPet(unittest.TestCase): def testParentPet(self): """Test ParentPet""" - - # test that we can make a ParentPet from a ParentPet - # which requires that we travel back through ParentPet's allOf descendant - # GrandparentAnimal, and we use the descendant's discriminator to make ParentPet - model = ParentPet(pet_type="ParentPet") - assert isinstance(model, ParentPet) + # FIXME: construct object with mandatory attributes with example values + # model = ParentPet() # noqa: E501 + pass if __name__ == '__main__': diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_pet.py b/samples/openapi3/client/petstore/python-experimental/test/test_pet.py index 6d03ce5bb33..0d77e022738 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_pet.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_pet.py @@ -14,16 +14,10 @@ import sys import unittest import petstore_api -try: - from petstore_api.model import category -except ImportError: - category = sys.modules[ - 'petstore_api.model.category'] -try: - from petstore_api.model import tag -except ImportError: - tag = sys.modules[ - 'petstore_api.model.tag'] +from petstore_api.model.category import Category +from petstore_api.model.tag import Tag +globals()['Category'] = Category +globals()['Tag'] = Tag from petstore_api.model.pet import Pet diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_pig.py b/samples/openapi3/client/petstore/python-experimental/test/test_pig.py index bb3a6bdfa86..0b2ffff147e 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_pig.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_pig.py @@ -14,16 +14,10 @@ import sys import unittest import petstore_api -try: - from petstore_api.model import basque_pig -except ImportError: - basque_pig = sys.modules[ - 'petstore_api.model.basque_pig'] -try: - from petstore_api.model import danish_pig -except ImportError: - danish_pig = sys.modules[ - 'petstore_api.model.danish_pig'] +from petstore_api.model.basque_pig import BasquePig +from petstore_api.model.danish_pig import DanishPig +globals()['BasquePig'] = BasquePig +globals()['DanishPig'] = DanishPig from petstore_api.model.pig import Pig diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_quadrilateral.py b/samples/openapi3/client/petstore/python-experimental/test/test_quadrilateral.py index 63f74ae541f..82c0c49d21d 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_quadrilateral.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_quadrilateral.py @@ -14,16 +14,10 @@ import sys import unittest import petstore_api -try: - from petstore_api.model import complex_quadrilateral -except ImportError: - complex_quadrilateral = sys.modules[ - 'petstore_api.model.complex_quadrilateral'] -try: - from petstore_api.model import simple_quadrilateral -except ImportError: - simple_quadrilateral = sys.modules[ - 'petstore_api.model.simple_quadrilateral'] +from petstore_api.model.complex_quadrilateral import ComplexQuadrilateral +from petstore_api.model.simple_quadrilateral import SimpleQuadrilateral +globals()['ComplexQuadrilateral'] = ComplexQuadrilateral +globals()['SimpleQuadrilateral'] = SimpleQuadrilateral from petstore_api.model.quadrilateral import Quadrilateral @@ -38,10 +32,9 @@ class TestQuadrilateral(unittest.TestCase): def testQuadrilateral(self): """Test Quadrilateral""" - instance = Quadrilateral(shape_type="Quadrilateral", quadrilateral_type="ComplexQuadrilateral") - assert isinstance(instance, complex_quadrilateral.ComplexQuadrilateral) - instance = Quadrilateral(shape_type="Quadrilateral", quadrilateral_type="SimpleQuadrilateral") - assert isinstance(instance, simple_quadrilateral.SimpleQuadrilateral) + # FIXME: construct object with mandatory attributes with example values + # model = Quadrilateral() # noqa: E501 + pass if __name__ == '__main__': diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_scalene_triangle.py b/samples/openapi3/client/petstore/python-experimental/test/test_scalene_triangle.py index d6fb13eb6c9..2235c4969ac 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_scalene_triangle.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_scalene_triangle.py @@ -14,16 +14,10 @@ import sys import unittest import petstore_api -try: - from petstore_api.model import shape_interface -except ImportError: - shape_interface = sys.modules[ - 'petstore_api.model.shape_interface'] -try: - from petstore_api.model import triangle_interface -except ImportError: - triangle_interface = sys.modules[ - 'petstore_api.model.triangle_interface'] +from petstore_api.model.shape_interface import ShapeInterface +from petstore_api.model.triangle_interface import TriangleInterface +globals()['ShapeInterface'] = ShapeInterface +globals()['TriangleInterface'] = TriangleInterface from petstore_api.model.scalene_triangle import ScaleneTriangle diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_shape.py b/samples/openapi3/client/petstore/python-experimental/test/test_shape.py index d4240f69530..23612c3fc8a 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_shape.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_shape.py @@ -14,16 +14,10 @@ import sys import unittest import petstore_api -try: - from petstore_api.model import quadrilateral -except ImportError: - quadrilateral = sys.modules[ - 'petstore_api.model.quadrilateral'] -try: - from petstore_api.model import triangle -except ImportError: - triangle = sys.modules[ - 'petstore_api.model.triangle'] +from petstore_api.model.quadrilateral import Quadrilateral +from petstore_api.model.triangle import Triangle +globals()['Quadrilateral'] = Quadrilateral +globals()['Triangle'] = Triangle from petstore_api.model.shape import Shape @@ -38,71 +32,10 @@ class TestShape(unittest.TestCase): def testShape(self): """Test Shape""" - from petstore_api.model import complex_quadrilateral - from petstore_api.model import simple_quadrilateral - from petstore_api.model import equilateral_triangle - from petstore_api.model import isosceles_triangle - from petstore_api.model import scalene_triangle - tri = triangle.Triangle( - shape_type="Triangle", - triangle_type="EquilateralTriangle" - ) - assert isinstance(tri, equilateral_triangle.EquilateralTriangle) + # FIXME: construct object with mandatory attributes with example values + # model = Shape() # noqa: E501 + pass - tri = triangle.Triangle( - shape_type="Triangle", - triangle_type="IsoscelesTriangle" - ) - assert isinstance(tri, isosceles_triangle.IsoscelesTriangle) - - tri = triangle.Triangle( - shape_type="Triangle", - triangle_type="ScaleneTriangle" - ) - assert isinstance(tri, scalene_triangle.ScaleneTriangle) - - quad = Shape( - shape_type="Quadrilateral", - quadrilateral_type="ComplexQuadrilateral" - ) - assert isinstance(quad, complex_quadrilateral.ComplexQuadrilateral) - - quad = Shape( - shape_type="Quadrilateral", - quadrilateral_type="SimpleQuadrilateral" - ) - assert isinstance(quad, simple_quadrilateral.SimpleQuadrilateral) - - # No discriminator provided. - err_msg = ("Cannot deserialize input data due to missing discriminator. " - "The discriminator property '{}' is missing at path: ()" - ) - with self.assertRaisesRegex( - petstore_api.ApiValueError, - err_msg.format("shapeType") - ): - Shape() - - # invalid shape_type (first discriminator). 'Circle' does not exist in the model. - err_msg = ("Cannot deserialize input data due to invalid discriminator " - "value. The OpenAPI document has no mapping for discriminator " - "property '{}'='{}' at path: ()" - ) - with self.assertRaisesRegex( - petstore_api.ApiValueError, - err_msg.format("shapeType", "Circle") - ): - Shape(shape_type="Circle") - - # invalid quadrilateral_type (second discriminator) - with self.assertRaisesRegex( - petstore_api.ApiValueError, - err_msg.format("quadrilateralType", "Triangle") - ): - Shape( - shape_type="Quadrilateral", - quadrilateral_type="Triangle" - ) if __name__ == '__main__': unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_shape_or_null.py b/samples/openapi3/client/petstore/python-experimental/test/test_shape_or_null.py index 7dc0988173b..dbe1db89c2e 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_shape_or_null.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_shape_or_null.py @@ -14,16 +14,10 @@ import sys import unittest import petstore_api -try: - from petstore_api.model import quadrilateral -except ImportError: - quadrilateral = sys.modules[ - 'petstore_api.model.quadrilateral'] -try: - from petstore_api.model import triangle -except ImportError: - triangle = sys.modules[ - 'petstore_api.model.triangle'] +from petstore_api.model.quadrilateral import Quadrilateral +from petstore_api.model.triangle import Triangle +globals()['Quadrilateral'] = Quadrilateral +globals()['Triangle'] = Triangle from petstore_api.model.shape_or_null import ShapeOrNull diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_simple_quadrilateral.py b/samples/openapi3/client/petstore/python-experimental/test/test_simple_quadrilateral.py index 4b5e8bbedfc..b12cb4504d0 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_simple_quadrilateral.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_simple_quadrilateral.py @@ -14,16 +14,10 @@ import sys import unittest import petstore_api -try: - from petstore_api.model import quadrilateral_interface -except ImportError: - quadrilateral_interface = sys.modules[ - 'petstore_api.model.quadrilateral_interface'] -try: - from petstore_api.model import shape_interface -except ImportError: - shape_interface = sys.modules[ - 'petstore_api.model.shape_interface'] +from petstore_api.model.quadrilateral_interface import QuadrilateralInterface +from petstore_api.model.shape_interface import ShapeInterface +globals()['QuadrilateralInterface'] = QuadrilateralInterface +globals()['ShapeInterface'] = ShapeInterface from petstore_api.model.simple_quadrilateral import SimpleQuadrilateral diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_string_enum.py b/samples/openapi3/client/petstore/python-experimental/test/test_string_enum.py index a9f7431e24e..7348ffdaa87 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_string_enum.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_string_enum.py @@ -28,22 +28,9 @@ class TestStringEnum(unittest.TestCase): def testStringEnum(self): """Test StringEnum""" - inst = StringEnum(None) - self.assertIsNone(inst) - - inst = StringEnum('approved') - assert isinstance(inst, StringEnum) - - with self.assertRaises(petstore_api.ApiValueError): - StringEnum('garbage') - - # make sure that we can access its allowed_values - assert StringEnum.allowed_values[('value',)] == { - 'None': None, - 'PLACED': "placed", - 'APPROVED': "approved", - 'DELIVERED': "delivered" - } + # FIXME: construct object with mandatory attributes with example values + # model = StringEnum() # noqa: E501 + pass if __name__ == '__main__': diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_triangle.py b/samples/openapi3/client/petstore/python-experimental/test/test_triangle.py index 7268022cad5..c62116c434f 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_triangle.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_triangle.py @@ -14,21 +14,12 @@ import sys import unittest import petstore_api -try: - from petstore_api.model import equilateral_triangle -except ImportError: - equilateral_triangle = sys.modules[ - 'petstore_api.model.equilateral_triangle'] -try: - from petstore_api.model import isosceles_triangle -except ImportError: - isosceles_triangle = sys.modules[ - 'petstore_api.model.isosceles_triangle'] -try: - from petstore_api.model import scalene_triangle -except ImportError: - scalene_triangle = sys.modules[ - 'petstore_api.model.scalene_triangle'] +from petstore_api.model.equilateral_triangle import EquilateralTriangle +from petstore_api.model.isosceles_triangle import IsoscelesTriangle +from petstore_api.model.scalene_triangle import ScaleneTriangle +globals()['EquilateralTriangle'] = EquilateralTriangle +globals()['IsoscelesTriangle'] = IsoscelesTriangle +globals()['ScaleneTriangle'] = ScaleneTriangle from petstore_api.model.triangle import Triangle @@ -43,12 +34,9 @@ class TestTriangle(unittest.TestCase): def testTriangle(self): """Test Triangle""" - tri = Triangle(shape_type="Triangle", triangle_type="EquilateralTriangle") - assert isinstance(tri, equilateral_triangle.EquilateralTriangle) - tri = Triangle(shape_type="Triangle", triangle_type="IsoscelesTriangle") - assert isinstance(tri, isosceles_triangle.IsoscelesTriangle) - tri = Triangle(shape_type="Triangle", triangle_type="ScaleneTriangle") - assert isinstance(tri, scalene_triangle.ScaleneTriangle) + # FIXME: construct object with mandatory attributes with example values + # model = Triangle() # noqa: E501 + pass if __name__ == '__main__': diff --git a/samples/openapi3/client/petstore/python-experimental/tests/__init__.py b/samples/openapi3/client/petstore/python-experimental/tests_manual/__init__.py similarity index 100% rename from samples/openapi3/client/petstore/python-experimental/tests/__init__.py rename to samples/openapi3/client/petstore/python-experimental/tests_manual/__init__.py diff --git a/samples/openapi3/client/petstore/python-experimental/tests/test_api_validation.py b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_api_validation.py similarity index 100% rename from samples/openapi3/client/petstore/python-experimental/tests/test_api_validation.py rename to samples/openapi3/client/petstore/python-experimental/tests_manual/test_api_validation.py diff --git a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_composed_one_of_number_with_validations.py b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_composed_one_of_number_with_validations.py new file mode 100644 index 00000000000..dde99076977 --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_composed_one_of_number_with_validations.py @@ -0,0 +1,46 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +import sys +import unittest + +import petstore_api +try: + from petstore_api.model import animal +except ImportError: + animal = sys.modules[ + 'petstore_api.model.animal'] +from petstore_api.model.composed_one_of_number_with_validations import ComposedOneOfNumberWithValidations + + +class TestComposedOneOfNumberWithValidations(unittest.TestCase): + """ComposedOneOfNumberWithValidations unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testComposedOneOfNumberWithValidations(self): + """Test ComposedOneOfNumberWithValidations""" + # we can make an instance that stores float data + inst = ComposedOneOfNumberWithValidations(10.0) + from petstore_api.model import number_with_validations + assert isinstance(inst, number_with_validations.NumberWithValidations) + # we can make an instance that stores object (dict) data + inst = ComposedOneOfNumberWithValidations(class_name="Cat", color="black") + assert isinstance(inst, ComposedOneOfNumberWithValidations) + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/tests/test_deserialization.py b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_deserialization.py similarity index 100% rename from samples/openapi3/client/petstore/python-experimental/tests/test_deserialization.py rename to samples/openapi3/client/petstore/python-experimental/tests_manual/test_deserialization.py diff --git a/samples/openapi3/client/petstore/python-experimental/tests/test_discard_unknown_properties.py b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_discard_unknown_properties.py similarity index 100% rename from samples/openapi3/client/petstore/python-experimental/tests/test_discard_unknown_properties.py rename to samples/openapi3/client/petstore/python-experimental/tests_manual/test_discard_unknown_properties.py diff --git a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_drawing.py b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_drawing.py new file mode 100644 index 00000000000..327e01fb849 --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_drawing.py @@ -0,0 +1,170 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +import sys +import unittest + +import petstore_api +try: + from petstore_api.model import nullable_shape +except ImportError: + nullable_shape = sys.modules[ + 'petstore_api.model.nullable_shape'] +try: + from petstore_api.model import shape +except ImportError: + shape = sys.modules[ + 'petstore_api.model.shape'] +try: + from petstore_api.model import shape_or_null +except ImportError: + shape_or_null = sys.modules[ + 'petstore_api.model.shape_or_null'] +from petstore_api.model.drawing import Drawing + + +class TestDrawing(unittest.TestCase): + """Drawing unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def test_create_instances(self): + """ + Validate instance can be created using pythonic name or OAS names. + """ + + # Validate object can be created using pythonic names. + inst = shape.Shape( + shape_type="Triangle", + triangle_type="IsoscelesTriangle" + ) + from petstore_api.model.isosceles_triangle import IsoscelesTriangle + assert isinstance(inst, IsoscelesTriangle) + + # Validate object can be created using OAS names. + # For example, this can be used to construct objects on the client + # when the input data is available as JSON documents. + data = { + 'shapeType': "Triangle", + 'triangleType': "IsoscelesTriangle" + } + inst = shape.Shape(_spec_property_naming=True, **data) + assert isinstance(inst, IsoscelesTriangle) + + def test_deserialize_oneof_reference(self): + """ + Validate the scenario when the type of a OAS property is 'oneOf', and the 'oneOf' + schema is specified as a reference ($ref), not an inline 'oneOf' schema. + """ + isosceles_triangle = shape.Shape( + shape_type="Triangle", + triangle_type="IsoscelesTriangle" + ) + from petstore_api.model.isosceles_triangle import IsoscelesTriangle + from petstore_api.model.triangle import Triangle + from petstore_api.model.equilateral_triangle import EquilateralTriangle + + assert isinstance(isosceles_triangle, IsoscelesTriangle) + inst = Drawing( + # 'main_shape' has type 'Shape', which is a oneOf [triangle, quadrilateral] + # composed schema. So we should be able to assign a petstore_api.Triangle + # to a 'main_shape'. + main_shape=isosceles_triangle, + shapes=[ + shape.Shape( + shape_type="Triangle", + triangle_type="EquilateralTriangle" + ), + Triangle( + shape_type="Triangle", + triangle_type="IsoscelesTriangle" + ), + EquilateralTriangle( + shape_type="Triangle", + triangle_type="EquilateralTriangle" + ), + shape.Shape( + shape_type="Quadrilateral", + quadrilateral_type="ComplexQuadrilateral" + ), + ], + ) + from petstore_api.model.complex_quadrilateral import ComplexQuadrilateral + assert isinstance(inst, Drawing) + assert isinstance(inst.main_shape, IsoscelesTriangle) + self.assertEqual(len(inst.shapes), 4) + assert isinstance(inst.shapes[0], EquilateralTriangle) + assert isinstance(inst.shapes[1], IsoscelesTriangle) + assert isinstance(inst.shapes[2], EquilateralTriangle) + assert isinstance(inst.shapes[3], ComplexQuadrilateral) + + # Validate we cannot assign the None value to main_shape because the 'null' type + # is not one of the allowed types in the 'Shape' schema. + err_msg = (r"Invalid type for variable '{}'. " + r"Required value type is {} and passed type was {} at {}") + with self.assertRaisesRegex( + petstore_api.ApiTypeError, + err_msg.format(r"main_shape", r"one of \[ComplexQuadrilateral, EquilateralTriangle, IsoscelesTriangle, ScaleneTriangle, SimpleQuadrilateral\]", r"NoneType", r"\['main_shape'\]") + ): + inst = Drawing( + # 'main_shape' has type 'Shape', which is a oneOf [triangle, quadrilateral] + # So the None value should not be allowed and an exception should be raised. + main_shape=None, + ) + + + def test_deserialize_oneof_reference_with_null_type(self): + """ + Validate the scenario when the type of a OAS property is 'oneOf', and the 'oneOf' + schema is specified as a reference ($ref), not an inline 'oneOf' schema. + Further, the 'oneOf' schema has a 'null' type child schema (as introduced in + OpenAPI 3.1). + """ + + # Validate we can assign the None value to shape_or_null, because the 'null' type + # is one of the allowed types in the 'ShapeOrNull' schema. + inst = Drawing( + # 'shape_or_null' has type 'ShapeOrNull', which is a oneOf [null, triangle, quadrilateral] + shape_or_null=None, + ) + assert isinstance(inst, Drawing) + self.assertFalse(hasattr(inst, 'main_shape')) + self.assertTrue(hasattr(inst, 'shape_or_null')) + self.assertIsNone(inst.shape_or_null) + + + def test_deserialize_oneof_reference_with_nullable_type(self): + """ + Validate the scenario when the type of a OAS property is 'oneOf', and the 'oneOf' + schema is specified as a reference ($ref), not an inline 'oneOf' schema. + Further, the 'oneOf' schema has the 'nullable' attribute (as introduced in + OpenAPI 3.0 and deprecated in 3.1). + """ + + # Validate we can assign the None value to nullable_shape, because the NullableShape + # has the 'nullable: true' attribute. + inst = Drawing( + # 'nullable_shape' has type 'NullableShape', which is a oneOf [triangle, quadrilateral] + # and the 'nullable: true' attribute. + nullable_shape=None, + ) + assert isinstance(inst, Drawing) + self.assertFalse(hasattr(inst, 'main_shape')) + self.assertTrue(hasattr(inst, 'nullable_shape')) + self.assertIsNone(inst.nullable_shape) + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_fake_api.py b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_fake_api.py new file mode 100644 index 00000000000..60dcbd549df --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_fake_api.py @@ -0,0 +1,310 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + +from collections import namedtuple +import unittest +import json +from unittest.mock import patch + +import petstore_api +from petstore_api.api.fake_api import FakeApi # noqa: E501 +from petstore_api.rest import RESTClientObject, RESTResponse + +HTTPResponse = namedtuple( + 'urllib3_response_HTTPResponse', + ['status', 'reason', 'data', 'getheaders', 'getheader'] +) + +headers = {'Content-Type': 'application/json'} +def get_headers(): + return {} +def get_header(name, default=None): + return {}.get(name, default) + + +class TestFakeApi(unittest.TestCase): + """FakeApi unit test stubs""" + + def setUp(self): + self.api = FakeApi() # noqa: E501 + + def tearDown(self): + pass + + @staticmethod + def mock_response(body_value): + http_response = HTTPResponse( + status=200, + reason='OK', + data=json.dumps(body_value).encode('utf-8'), + getheaders=get_headers, + getheader=get_header + ) + return RESTResponse(http_response) + + @staticmethod + def assert_request_called_with(mock_method, url, value): + mock_method.assert_called_with( + 'POST', + url, + _preload_content=True, + _request_timeout=None, + body=value, + headers={ + 'Accept': 'application/json', + 'User-Agent': 'OpenAPI-Generator/1.0.0/python', + 'Content-Type': 'application/json' + }, + post_params=[], + query_params=[] + ) + + + def test_array_model(self): + """Test case for array_model + + """ + from petstore_api.model import animal_farm, animal + endpoint = self.api.array_model + assert endpoint.openapi_types['body'] == (animal_farm.AnimalFarm,) + assert endpoint.settings['response_type'] == (animal_farm.AnimalFarm,) + + # serialization + deserialization works + with patch.object(RESTClientObject, 'request') as mock_method: + cat = animal.Animal(class_name="Cat", color="black") + body = animal_farm.AnimalFarm([cat]) + json_data = [{"className": "Cat", "color": "black"}] + mock_method.return_value = self.mock_response(json_data) + + response = endpoint(body=body) + self.assert_request_called_with(mock_method, 'http://petstore.swagger.io:80/v2/fake/refs/arraymodel', json_data) + + assert isinstance(response, animal_farm.AnimalFarm) + assert response == body + + def test_boolean(self): + """Test case for boolean + + """ + endpoint = self.api.boolean + assert endpoint.openapi_types['body'] == (bool,) + assert endpoint.settings['response_type'] == (bool,) + + def test_fake_health_get(self): + """Test case for fake_health_get + + Health check endpoint # noqa: E501 + """ + pass + + def test_additional_properties_with_array_of_enums(self): + """Test case for additional_properties_with_array_of_enums + + Additional Properties with Array of Enums # noqa: E501 + """ + pass + + def test_array_of_enums(self): + """Test case for array_of_enums + + Array of Enums # noqa: E501 + """ + from petstore_api.model import array_of_enums, string_enum + endpoint = self.api.array_of_enums + assert endpoint.openapi_types['array_of_enums'] == (array_of_enums.ArrayOfEnums,) + assert endpoint.settings['response_type'] == (array_of_enums.ArrayOfEnums,) + + # serialization + deserialization works + with patch.object(RESTClientObject, 'request') as mock_method: + value = [string_enum.StringEnum("placed")] + body = array_of_enums.ArrayOfEnums(value) + value_simple = ["placed"] + mock_method.return_value = self.mock_response(value_simple) + + response = endpoint(array_of_enums=body) + self.assert_request_called_with(mock_method, 'http://petstore.swagger.io:80/v2/fake/refs/array-of-enums', value_simple) + + assert isinstance(response, array_of_enums.ArrayOfEnums) + assert response.value == value + + def test_number_with_validations(self): + """Test case for number_with_validations + + """ + from petstore_api.model import number_with_validations + endpoint = self.api.number_with_validations + assert endpoint.openapi_types['body'] == (number_with_validations.NumberWithValidations,) + assert endpoint.settings['response_type'] == (number_with_validations.NumberWithValidations,) + + # serialization + deserialization works + with patch.object(RESTClientObject, 'request') as mock_method: + value = 10.0 + body = number_with_validations.NumberWithValidations(value) + mock_method.return_value = self.mock_response(value) + + response = endpoint(body=body) + self.assert_request_called_with(mock_method, 'http://petstore.swagger.io:80/v2/fake/refs/number', value) + + assert isinstance(response, number_with_validations.NumberWithValidations) + assert response.value == value + + def test_object_model_with_ref_props(self): + """Test case for object_model_with_ref_props + + """ + from petstore_api.model import object_model_with_ref_props + endpoint = self.api.object_model_with_ref_props + assert endpoint.openapi_types['body'] == (object_model_with_ref_props.ObjectModelWithRefProps,) + assert endpoint.settings['response_type'] == (object_model_with_ref_props.ObjectModelWithRefProps,) + + def test_composed_one_of_number_with_validations(self): + """Test case for composed_one_of_number_with_validations + + """ + from petstore_api.model import animal, composed_one_of_number_with_validations, number_with_validations + endpoint = self.api.composed_one_of_number_with_validations + assert endpoint.openapi_types['composed_one_of_number_with_validations'] == ( + composed_one_of_number_with_validations.ComposedOneOfNumberWithValidations,) + assert endpoint.settings['response_type'] == ( + composed_one_of_number_with_validations.ComposedOneOfNumberWithValidations,) + + # serialization + deserialization works + num_with_validations = number_with_validations.NumberWithValidations(10.0) + cat_in_composed = composed_one_of_number_with_validations.ComposedOneOfNumberWithValidations( + class_name="Cat", color="black" + ) + import datetime + date = datetime.date(1970, 1, 1) + body_value_simple = [ + (num_with_validations, 10.0), + (cat_in_composed, {"className": "Cat", "color": "black"}), + (None, None), + (date, '1970-01-01'), + ] + for (body, value_simple) in body_value_simple: + with patch.object(RESTClientObject, 'request') as mock_method: + mock_method.return_value = self.mock_response(value_simple) + + response = endpoint(composed_one_of_number_with_validations=body) + self.assert_request_called_with( + mock_method, + 'http://petstore.swagger.io:80/v2/fake/refs/composed_one_of_number_with_validations', + value_simple + ) + + assert isinstance(response, body.__class__) + assert response == body + + def test_string(self): + """Test case for string + + """ + endpoint = self.api.string + assert endpoint.openapi_types['body'] == (str,) + assert endpoint.settings['response_type'] == (str,) + + # serialization + deserialization works + with patch.object(RESTClientObject, 'request') as mock_method: + body = "blah" + value_simple = body + mock_method.return_value = self.mock_response(value_simple) + + response = endpoint(body=body) + self.assert_request_called_with(mock_method, 'http://petstore.swagger.io:80/v2/fake/refs/string', value_simple) + + assert isinstance(response, str) + assert response == value_simple + + def test_string_enum(self): + """Test case for string_enum + + """ + from petstore_api.model import string_enum + endpoint = self.api.string_enum + assert endpoint.openapi_types['body'] == (string_enum.StringEnum,) + assert endpoint.settings['response_type'] == (string_enum.StringEnum,) + + # serialization + deserialization works + from petstore_api.rest import RESTClientObject, RESTResponse + with patch.object(RESTClientObject, 'request') as mock_method: + value = "placed" + body = string_enum.StringEnum(value) + mock_method.return_value = self.mock_response(value) + + response = endpoint(body=body) + self.assert_request_called_with(mock_method, 'http://petstore.swagger.io:80/v2/fake/refs/enum', value) + + assert isinstance(response, string_enum.StringEnum) + assert response.value == value + + def test_test_body_with_file_schema(self): + """Test case for test_body_with_file_schema + + """ + pass + + def test_test_body_with_query_params(self): + """Test case for test_body_with_query_params + + """ + pass + + def test_test_client_model(self): + """Test case for test_client_model + + To test \"client\" model # noqa: E501 + """ + pass + + def test_test_endpoint_parameters(self): + """Test case for test_endpoint_parameters + + Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 # noqa: E501 + """ + pass + + def test_test_enum_parameters(self): + """Test case for test_enum_parameters + + To test enum parameters # noqa: E501 + """ + pass + + def test_test_group_parameters(self): + """Test case for test_group_parameters + + Fake endpoint to test group parameters (optional) # noqa: E501 + """ + pass + + def test_test_inline_additional_properties(self): + """Test case for test_inline_additional_properties + + test inline additionalProperties # noqa: E501 + """ + pass + + def test_test_json_form_data(self): + """Test case for test_json_form_data + + test json serialization of form data # noqa: E501 + """ + pass + + def test_test_query_parameter_collection_format(self): + """Test case for test_query_parameter_collection_format + + """ + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_fruit.py b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_fruit.py new file mode 100644 index 00000000000..fac0319663e --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_fruit.py @@ -0,0 +1,221 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +import sys +import unittest + +import petstore_api +try: + from petstore_api.model import apple +except ImportError: + apple = sys.modules[ + 'petstore_api.model.apple'] +try: + from petstore_api.model import banana +except ImportError: + banana = sys.modules[ + 'petstore_api.model.banana'] +from petstore_api.model.fruit import Fruit + + +class TestFruit(unittest.TestCase): + """Fruit unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testFruit(self): + """Test Fruit""" + + # make an instance of Fruit, a composed schema oneOf model + # banana test + length_cm = 20.3 + color = 'yellow' + fruit = Fruit(length_cm=length_cm, color=color) + # check its properties + self.assertEqual(fruit.length_cm, length_cm) + self.assertEqual(fruit['length_cm'], length_cm) + self.assertEqual(getattr(fruit, 'length_cm'), length_cm) + self.assertEqual(fruit.color, color) + self.assertEqual(fruit['color'], color) + self.assertEqual(getattr(fruit, 'color'), color) + # check the dict representation + self.assertEqual( + fruit.to_dict(), + { + 'length_cm': length_cm, + 'color': color + } + ) + # setting a value that doesn't exist raises an exception + # with a key + with self.assertRaises(AttributeError): + fruit['invalid_variable'] = 'some value' + + # Assert that we can call the builtin hasattr() function. + # hasattr should return False for non-existent attribute. + # Internally hasattr catches the AttributeError exception. + self.assertFalse(hasattr(fruit, 'invalid_variable')) + + # Assert that we can call the builtin hasattr() function. + # hasattr should return True for existent attribute. + self.assertTrue(hasattr(fruit, 'color')) + + # with setattr + with self.assertRaises(AttributeError): + setattr(fruit, 'invalid_variable', 'some value') + + # getting a value that doesn't exist raises an exception + # with a key + with self.assertRaises(AttributeError): + invalid_variable = fruit['cultivar'] + # with getattr + # Per Python doc, if the named attribute does not exist, + # default is returned if provided. + self.assertEqual(getattr(fruit, 'cultivar', 'some value'), 'some value') + + # Per Python doc, if the named attribute does not exist, + # default is returned if provided, otherwise AttributeError is raised. + with self.assertRaises(AttributeError): + getattr(fruit, 'cultivar') + + # make sure that the ModelComposed class properties are correct + # model._composed_schemas stores the anyOf/allOf/oneOf info + self.assertEqual( + fruit._composed_schemas, + { + 'anyOf': [], + 'allOf': [], + 'oneOf': [ + apple.Apple, + banana.Banana, + ], + } + ) + # model._composed_instances is a list of the instances that were + # made from the anyOf/allOf/OneOf classes in model._composed_schemas + for composed_instance in fruit._composed_instances: + if composed_instance.__class__ == banana.Banana: + banana_instance = composed_instance + self.assertEqual( + fruit._composed_instances, + [banana_instance] + ) + # model._var_name_to_model_instances maps the variable name to the + # model instances which store that variable + self.assertEqual( + fruit._var_name_to_model_instances, + { + 'color': [fruit], + 'length_cm': [fruit, banana_instance], + 'cultivar': [fruit], + 'origin': [fruit], + } + ) + # model._additional_properties_model_instances stores a list of + # models which have the property additional_properties_type != None + self.assertEqual( + fruit._additional_properties_model_instances, [] + ) + + # if we modify one of the properties owned by multiple + # model_instances we get an exception when we try to access that + # property because the retrieved values are not all the same + banana_instance.length_cm = 4.56 + with self.assertRaises(petstore_api.ApiValueError): + some_length_cm = fruit.length_cm + + # including extra parameters raises an exception + with self.assertRaises(petstore_api.ApiValueError): + fruit = Fruit( + color=color, + length_cm=length_cm, + unknown_property='some value' + ) + + # including input parameters for two oneOf instances raise an exception + with self.assertRaises(petstore_api.ApiValueError): + fruit = Fruit( + length_cm=length_cm, + cultivar='granny smith' + ) + + # make an instance of Fruit, a composed schema oneOf model + # apple test + color = 'red' + cultivar = 'golden delicious' + fruit = Fruit(color=color, cultivar=cultivar) + # check its properties + self.assertEqual(fruit.color, color) + self.assertEqual(fruit['color'], color) + self.assertEqual(getattr(fruit, 'color'), color) + self.assertEqual(fruit.cultivar, cultivar) + self.assertEqual(fruit['cultivar'], cultivar) + self.assertEqual(getattr(fruit, 'cultivar'), cultivar) + # check the dict representation + self.assertEqual( + fruit.to_dict(), + { + 'color': color, + 'cultivar': cultivar + } + ) + + # model._composed_instances is a list of the instances that were + # made from the anyOf/allOf/OneOf classes in model._composed_schemas + for composed_instance in fruit._composed_instances: + if composed_instance.__class__ == apple.Apple: + apple_instance = composed_instance + self.assertEqual( + fruit._composed_instances, + [apple_instance] + ) + # model._var_name_to_model_instances maps the variable name to the + # model instances which store that variable + self.assertEqual( + fruit._var_name_to_model_instances, + { + 'color': [fruit], + 'length_cm': [fruit], + 'cultivar': [fruit, apple_instance], + 'origin': [fruit, apple_instance], + } + ) + # model._additional_properties_model_instances stores a list of + # models which have the property additional_properties_type != None + self.assertEqual( + fruit._additional_properties_model_instances, [] + ) + + def testFruitNullValue(self): + # Since 'apple' is nullable, validate we can create an apple with the 'null' value. + fruit = apple.Apple(None) + self.assertIsNone(fruit) + + # 'banana' is not nullable. + with self.assertRaises(petstore_api.ApiTypeError): + banana.Banana(None) + + # Since 'fruit' has oneOf 'apple', 'banana' and 'apple' is nullable, + # validate we can create a fruit with the 'null' value. + fruit = Fruit(None) + self.assertIsNone(fruit) + + # Redo the same thing, this time passing a null Apple to the Fruit constructor. + fruit = Fruit(apple.Apple(None)) + self.assertIsNone(fruit) + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_fruit_req.py b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_fruit_req.py new file mode 100644 index 00000000000..3e637c3226a --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_fruit_req.py @@ -0,0 +1,183 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +import sys +import unittest + +import petstore_api +try: + from petstore_api.model import apple_req +except ImportError: + apple_req = sys.modules[ + 'petstore_api.model.apple_req'] +try: + from petstore_api.model import banana_req +except ImportError: + banana_req = sys.modules[ + 'petstore_api.model.banana_req'] +from petstore_api.model.fruit_req import FruitReq + + +class TestFruitReq(unittest.TestCase): + """FruitReq unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testFruitReq(self): + """Test FruitReq""" + + # make an instance of Fruit, a composed schema oneOf model + # banana test + length_cm = 20.3 + fruit = FruitReq(length_cm=length_cm) + # check its properties + self.assertEqual(fruit.length_cm, length_cm) + self.assertEqual(fruit['length_cm'], length_cm) + self.assertEqual(getattr(fruit, 'length_cm'), length_cm) + # check the dict representation + self.assertEqual( + fruit.to_dict(), + { + 'length_cm': length_cm, + } + ) + # setting a value that doesn't exist raises an exception + # with a key + with self.assertRaises(AttributeError): + fruit['invalid_variable'] = 'some value' + # with setattr + with self.assertRaises(AttributeError): + setattr(fruit, 'invalid_variable', 'some value') + + # getting a value that doesn't exist raises an exception + # with a key + with self.assertRaises(AttributeError): + invalid_variable = fruit['cultivar'] + # with getattr + self.assertEqual(getattr(fruit, 'cultivar', 'some value'), 'some value') + + with self.assertRaises(AttributeError): + getattr(fruit, 'cultivar') + + # make sure that the ModelComposed class properties are correct + # model._composed_schemas stores the anyOf/allOf/oneOf info + self.assertEqual( + fruit._composed_schemas, + { + 'anyOf': [], + 'allOf': [], + 'oneOf': [ + apple_req.AppleReq, + banana_req.BananaReq, + type(None), + ], + } + ) + # model._composed_instances is a list of the instances that were + # made from the anyOf/allOf/OneOf classes in model._composed_schemas + for composed_instance in fruit._composed_instances: + if composed_instance.__class__ == banana_req.BananaReq: + banana_instance = composed_instance + self.assertEqual( + fruit._composed_instances, + [banana_instance] + ) + # model._var_name_to_model_instances maps the variable name to the + # model instances which store that variable + self.assertEqual( + fruit._var_name_to_model_instances, + { + 'length_cm': [fruit, banana_instance], + 'cultivar': [fruit], + 'mealy': [fruit], + 'sweet': [fruit, banana_instance], + } + ) + # model._additional_properties_model_instances stores a list of + # models which have the property additional_properties_type != None + self.assertEqual( + fruit._additional_properties_model_instances, [] + ) + + # if we modify one of the properties owned by multiple + # model_instances we get an exception when we try to access that + # property because the retrieved values are not all the same + banana_instance.length_cm = 4.56 + with self.assertRaises(petstore_api.ApiValueError): + some_length_cm = fruit.length_cm + + # including extra parameters raises an exception + with self.assertRaises(petstore_api.ApiValueError): + fruit = FruitReq( + length_cm=length_cm, + unknown_property='some value' + ) + + # including input parameters for two oneOf instances raise an exception + with self.assertRaises(petstore_api.ApiValueError): + fruit = FruitReq( + length_cm=length_cm, + cultivar='granny smith' + ) + + # make an instance of Fruit, a composed schema oneOf model + # apple test + cultivar = 'golden delicious' + fruit = FruitReq(cultivar=cultivar) + # check its properties + self.assertEqual(fruit.cultivar, cultivar) + self.assertEqual(fruit['cultivar'], cultivar) + self.assertEqual(getattr(fruit, 'cultivar'), cultivar) + # check the dict representation + self.assertEqual( + fruit.to_dict(), + { + 'cultivar': cultivar + } + ) + + # model._composed_instances is a list of the instances that were + # made from the anyOf/allOf/OneOf classes in model._composed_schemas + for composed_instance in fruit._composed_instances: + if composed_instance.__class__ == apple_req.AppleReq: + apple_instance = composed_instance + self.assertEqual( + fruit._composed_instances, + [apple_instance] + ) + # model._var_name_to_model_instances maps the variable name to the + # model instances which store that variable + self.assertEqual( + fruit._var_name_to_model_instances, + { + 'length_cm': [fruit], + 'cultivar': [fruit, apple_instance], + 'mealy': [fruit, apple_instance], + 'sweet': [fruit], + } + ) + # model._additional_properties_model_instances stores a list of + # models which have the property additional_properties_type != None + self.assertEqual( + fruit._additional_properties_model_instances, [] + ) + + # we can pass in None + fruit = FruitReq(None) + assert fruit is None + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_gm_fruit.py b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_gm_fruit.py new file mode 100644 index 00000000000..85d0fcf9b1c --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_gm_fruit.py @@ -0,0 +1,230 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +import sys +import unittest + +import petstore_api +try: + from petstore_api.model import apple +except ImportError: + apple = sys.modules[ + 'petstore_api.model.apple'] +try: + from petstore_api.model import banana +except ImportError: + banana = sys.modules[ + 'petstore_api.model.banana'] +from petstore_api.model.gm_fruit import GmFruit + + +class TestGmFruit(unittest.TestCase): + """GmFruit unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testGmFruit(self): + """Test GmFruit""" + + # make an instance of GmFruit, a composed schema anyOf model + # banana test + length_cm = 20.3 + color = 'yellow' + fruit = GmFruit(length_cm=length_cm, color=color) + # check its properties + self.assertEqual(fruit.length_cm, length_cm) + self.assertEqual(fruit['length_cm'], length_cm) + self.assertEqual(getattr(fruit, 'length_cm'), length_cm) + self.assertEqual(fruit.color, color) + self.assertEqual(fruit['color'], color) + self.assertEqual(getattr(fruit, 'color'), color) + # check the dict representation + self.assertEqual( + fruit.to_dict(), + { + 'length_cm': length_cm, + 'color': color + } + ) + # setting a value that doesn't exist raises an exception + # with a key + with self.assertRaises(AttributeError): + fruit['invalid_variable'] = 'some value' + # with setattr + with self.assertRaises(AttributeError): + setattr(fruit, 'invalid_variable', 'some value') + + # getting a value that doesn't exist raises an exception + # with a key + with self.assertRaises(AttributeError): + invalid_variable = fruit['cultivar'] + # with getattr + self.assertTrue(getattr(fruit, 'cultivar', 'some value'), 'some value') + + with self.assertRaises(AttributeError): + invalid_variable = getattr(fruit, 'cultivar') + + # make sure that the ModelComposed class properties are correct + # model._composed_schemas stores the anyOf/allOf/oneOf info + self.assertEqual( + fruit._composed_schemas, + { + 'anyOf': [ + apple.Apple, + banana.Banana, + ], + 'allOf': [], + 'oneOf': [], + } + ) + # model._composed_instances is a list of the instances that were + # made from the anyOf/allOf/OneOf classes in model._composed_schemas + for composed_instance in fruit._composed_instances: + if composed_instance.__class__ == banana.Banana: + banana_instance = composed_instance + self.assertEqual( + fruit._composed_instances, + [banana_instance] + ) + # model._var_name_to_model_instances maps the variable name to the + # model instances which store that variable + self.assertEqual( + fruit._var_name_to_model_instances, + { + 'color': [fruit], + 'length_cm': [fruit, banana_instance], + 'cultivar': [fruit], + 'origin': [fruit], + } + ) + # model._additional_properties_model_instances stores a list of + # models which have the property additional_properties_type != None + self.assertEqual( + fruit._additional_properties_model_instances, [] + ) + + # if we modify one of the properties owned by multiple + # model_instances we get an exception when we try to access that + # property because the retrieved values are not all the same + banana_instance.length_cm = 4.56 + with self.assertRaises(petstore_api.ApiValueError): + some_length_cm = fruit.length_cm + + # including extra parameters raises an exception + with self.assertRaises(petstore_api.ApiValueError): + fruit = GmFruit( + color=color, + length_cm=length_cm, + unknown_property='some value' + ) + + # including input parameters for both anyOf instances works + cultivar = 'banaple' + color = 'orange' + fruit = GmFruit( + color=color, + cultivar=cultivar, + length_cm=length_cm + ) + self.assertEqual(fruit.color, color) + self.assertEqual(fruit['color'], color) + self.assertEqual(getattr(fruit, 'color'), color) + self.assertEqual(fruit.cultivar, cultivar) + self.assertEqual(fruit['cultivar'], cultivar) + self.assertEqual(getattr(fruit, 'cultivar'), cultivar) + self.assertEqual(fruit.length_cm, length_cm) + self.assertEqual(fruit['length_cm'], length_cm) + self.assertEqual(getattr(fruit, 'length_cm'), length_cm) + + # model._composed_instances is a list of the instances that were + # made from the anyOf/allOf/OneOf classes in model._composed_schemas + for composed_instance in fruit._composed_instances: + if composed_instance.__class__ == apple.Apple: + apple_instance = composed_instance + elif composed_instance.__class__ == banana.Banana: + banana_instance = composed_instance + self.assertEqual( + fruit._composed_instances, + [apple_instance, banana_instance] + ) + # model._var_name_to_model_instances maps the variable name to the + # model instances which store that variable + self.assertEqual( + fruit._var_name_to_model_instances, + { + 'color': [fruit], + 'length_cm': [fruit, banana_instance], + 'cultivar': [fruit, apple_instance], + 'origin': [fruit, apple_instance], + } + ) + + # make an instance of GmFruit, a composed schema anyOf model + # apple test + color = 'red' + cultivar = 'golden delicious' + origin = 'California' + fruit = GmFruit(color=color, cultivar=cultivar, origin=origin) + # check its properties + self.assertEqual(fruit.color, color) + self.assertEqual(fruit['color'], color) + self.assertEqual(getattr(fruit, 'color'), color) + self.assertEqual(fruit.cultivar, cultivar) + self.assertEqual(fruit['cultivar'], cultivar) + self.assertEqual(getattr(fruit, 'cultivar'), cultivar) + + self.assertEqual(fruit.origin, origin) + self.assertEqual(fruit['origin'], origin) + self.assertEqual(getattr(fruit, 'origin'), origin) + + # check the dict representation + self.assertEqual( + fruit.to_dict(), + { + 'color': color, + 'cultivar': cultivar, + 'origin': origin, + } + ) + + # model._composed_instances is a list of the instances that were + # made from the anyOf/allOf/OneOf classes in model._composed_schemas + for composed_instance in fruit._composed_instances: + if composed_instance.__class__ == apple.Apple: + apple_instance = composed_instance + self.assertEqual( + fruit._composed_instances, + [apple_instance] + ) + # model._var_name_to_model_instances maps the variable name to the + # model instances which store that variable + self.assertEqual( + fruit._var_name_to_model_instances, + { + 'color': [fruit], + 'length_cm': [fruit], + 'cultivar': [fruit, apple_instance], + 'origin': [fruit, apple_instance], + } + ) + # model._additional_properties_model_instances stores a list of + # models which have the property additional_properties_type != None + self.assertEqual( + fruit._additional_properties_model_instances, [] + ) + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/tests/test_http_signature.py b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_http_signature.py similarity index 100% rename from samples/openapi3/client/petstore/python-experimental/tests/test_http_signature.py rename to samples/openapi3/client/petstore/python-experimental/tests_manual/test_http_signature.py diff --git a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_integer_enum_one_value.py b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_integer_enum_one_value.py new file mode 100644 index 00000000000..eff7298d9f3 --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_integer_enum_one_value.py @@ -0,0 +1,42 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +import sys +import unittest + +import petstore_api +from petstore_api.model.integer_enum_one_value import IntegerEnumOneValue + + +class TestIntegerEnumOneValue(unittest.TestCase): + """IntegerEnumOneValue unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testIntegerEnumOneValue(self): + """Test IntegerEnumOneValue""" + model = IntegerEnumOneValue() + assert model.value == 0, "With only one option, the value is assigned automatically" + + model = IntegerEnumOneValue(0) + assert model.value == 0, "We can also pass in the value as a positional arg" + + model = IntegerEnumOneValue(value=0) + assert model.value == 0, "We can also pass in the value as a named argument" + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_mammal.py b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_mammal.py new file mode 100644 index 00000000000..3ed00dd7981 --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_mammal.py @@ -0,0 +1,49 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +import sys +import unittest + +import petstore_api +try: + from petstore_api.model import whale +except ImportError: + whale = sys.modules[ + 'petstore_api.model.whale'] +try: + from petstore_api.model import zebra +except ImportError: + zebra = sys.modules[ + 'petstore_api.model.zebra'] +from petstore_api.model.mammal import Mammal + + +class TestMammal(unittest.TestCase): + """Mammal unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testMammal(self): + """Test Mammal""" + + # tests that we can make a BasquePig by traveling through descendant discriminator in Pig + model = Mammal(class_name="BasquePig") + from petstore_api.model import basque_pig + assert isinstance(model, basque_pig.BasquePig) + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_number_with_validations.py b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_number_with_validations.py new file mode 100644 index 00000000000..f4264ca82ea --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_number_with_validations.py @@ -0,0 +1,43 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +import sys +import unittest + +import petstore_api +from petstore_api.model.number_with_validations import NumberWithValidations + + +class TestNumberWithValidations(unittest.TestCase): + """NumberWithValidations unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testNumberWithValidations(self): + """Test NumberWithValidations""" + valid_values = [10.0, 15.0, 20.0] + for valid_value in valid_values: + model = NumberWithValidations(valid_value) + assert model.value == valid_value + + invalid_values = [9.0, 21.0] + for invalid_value in invalid_values: + with self.assertRaises(petstore_api.ApiValueError): + NumberWithValidations(invalid_value) + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_object_model_with_ref_props.py b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_object_model_with_ref_props.py new file mode 100644 index 00000000000..9ce55c75bb8 --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_object_model_with_ref_props.py @@ -0,0 +1,48 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +import sys +import unittest + +import petstore_api +try: + from petstore_api.model import number_with_validations +except ImportError: + number_with_validations = sys.modules[ + 'petstore_api.model.number_with_validations'] +from petstore_api.model.object_model_with_ref_props import ObjectModelWithRefProps + + +class TestObjectModelWithRefProps(unittest.TestCase): + """ObjectModelWithRefProps unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testObjectModelWithRefProps(self): + """Test ObjectModelWithRefProps""" + from petstore_api.model.number_with_validations import NumberWithValidations + self.assertEqual( + ObjectModelWithRefProps.openapi_types, + { + 'my_number': (NumberWithValidations,), + 'my_string': (str,), + 'my_boolean': (bool,), + } + ) + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_parent_pet.py b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_parent_pet.py new file mode 100644 index 00000000000..a57f9b8527a --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_parent_pet.py @@ -0,0 +1,50 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +import sys +import unittest + +import petstore_api +try: + from petstore_api.model import child_cat +except ImportError: + child_cat = sys.modules[ + 'petstore_api.model.child_cat'] +try: + from petstore_api.model import grandparent_animal +except ImportError: + grandparent_animal = sys.modules[ + 'petstore_api.model.grandparent_animal'] +from petstore_api.model.parent_pet import ParentPet + + +class TestParentPet(unittest.TestCase): + """ParentPet unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testParentPet(self): + """Test ParentPet""" + + # test that we can make a ParentPet from a ParentPet + # which requires that we travel back through ParentPet's allOf descendant + # GrandparentAnimal, and we use the descendant's discriminator to make ParentPet + model = ParentPet(pet_type="ParentPet") + assert isinstance(model, ParentPet) + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_quadrilateral.py b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_quadrilateral.py new file mode 100644 index 00000000000..63f74ae541f --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_quadrilateral.py @@ -0,0 +1,48 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +import sys +import unittest + +import petstore_api +try: + from petstore_api.model import complex_quadrilateral +except ImportError: + complex_quadrilateral = sys.modules[ + 'petstore_api.model.complex_quadrilateral'] +try: + from petstore_api.model import simple_quadrilateral +except ImportError: + simple_quadrilateral = sys.modules[ + 'petstore_api.model.simple_quadrilateral'] +from petstore_api.model.quadrilateral import Quadrilateral + + +class TestQuadrilateral(unittest.TestCase): + """Quadrilateral unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testQuadrilateral(self): + """Test Quadrilateral""" + instance = Quadrilateral(shape_type="Quadrilateral", quadrilateral_type="ComplexQuadrilateral") + assert isinstance(instance, complex_quadrilateral.ComplexQuadrilateral) + instance = Quadrilateral(shape_type="Quadrilateral", quadrilateral_type="SimpleQuadrilateral") + assert isinstance(instance, simple_quadrilateral.SimpleQuadrilateral) + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_shape.py b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_shape.py new file mode 100644 index 00000000000..d4240f69530 --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_shape.py @@ -0,0 +1,108 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +import sys +import unittest + +import petstore_api +try: + from petstore_api.model import quadrilateral +except ImportError: + quadrilateral = sys.modules[ + 'petstore_api.model.quadrilateral'] +try: + from petstore_api.model import triangle +except ImportError: + triangle = sys.modules[ + 'petstore_api.model.triangle'] +from petstore_api.model.shape import Shape + + +class TestShape(unittest.TestCase): + """Shape unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testShape(self): + """Test Shape""" + from petstore_api.model import complex_quadrilateral + from petstore_api.model import simple_quadrilateral + from petstore_api.model import equilateral_triangle + from petstore_api.model import isosceles_triangle + from petstore_api.model import scalene_triangle + tri = triangle.Triangle( + shape_type="Triangle", + triangle_type="EquilateralTriangle" + ) + assert isinstance(tri, equilateral_triangle.EquilateralTriangle) + + tri = triangle.Triangle( + shape_type="Triangle", + triangle_type="IsoscelesTriangle" + ) + assert isinstance(tri, isosceles_triangle.IsoscelesTriangle) + + tri = triangle.Triangle( + shape_type="Triangle", + triangle_type="ScaleneTriangle" + ) + assert isinstance(tri, scalene_triangle.ScaleneTriangle) + + quad = Shape( + shape_type="Quadrilateral", + quadrilateral_type="ComplexQuadrilateral" + ) + assert isinstance(quad, complex_quadrilateral.ComplexQuadrilateral) + + quad = Shape( + shape_type="Quadrilateral", + quadrilateral_type="SimpleQuadrilateral" + ) + assert isinstance(quad, simple_quadrilateral.SimpleQuadrilateral) + + # No discriminator provided. + err_msg = ("Cannot deserialize input data due to missing discriminator. " + "The discriminator property '{}' is missing at path: ()" + ) + with self.assertRaisesRegex( + petstore_api.ApiValueError, + err_msg.format("shapeType") + ): + Shape() + + # invalid shape_type (first discriminator). 'Circle' does not exist in the model. + err_msg = ("Cannot deserialize input data due to invalid discriminator " + "value. The OpenAPI document has no mapping for discriminator " + "property '{}'='{}' at path: ()" + ) + with self.assertRaisesRegex( + petstore_api.ApiValueError, + err_msg.format("shapeType", "Circle") + ): + Shape(shape_type="Circle") + + # invalid quadrilateral_type (second discriminator) + with self.assertRaisesRegex( + petstore_api.ApiValueError, + err_msg.format("quadrilateralType", "Triangle") + ): + Shape( + shape_type="Quadrilateral", + quadrilateral_type="Triangle" + ) + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_string_enum.py b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_string_enum.py new file mode 100644 index 00000000000..a9f7431e24e --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_string_enum.py @@ -0,0 +1,50 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +import sys +import unittest + +import petstore_api +from petstore_api.model.string_enum import StringEnum + + +class TestStringEnum(unittest.TestCase): + """StringEnum unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testStringEnum(self): + """Test StringEnum""" + inst = StringEnum(None) + self.assertIsNone(inst) + + inst = StringEnum('approved') + assert isinstance(inst, StringEnum) + + with self.assertRaises(petstore_api.ApiValueError): + StringEnum('garbage') + + # make sure that we can access its allowed_values + assert StringEnum.allowed_values[('value',)] == { + 'None': None, + 'PLACED': "placed", + 'APPROVED': "approved", + 'DELIVERED': "delivered" + } + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_triangle.py b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_triangle.py new file mode 100644 index 00000000000..7268022cad5 --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_triangle.py @@ -0,0 +1,55 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +import sys +import unittest + +import petstore_api +try: + from petstore_api.model import equilateral_triangle +except ImportError: + equilateral_triangle = sys.modules[ + 'petstore_api.model.equilateral_triangle'] +try: + from petstore_api.model import isosceles_triangle +except ImportError: + isosceles_triangle = sys.modules[ + 'petstore_api.model.isosceles_triangle'] +try: + from petstore_api.model import scalene_triangle +except ImportError: + scalene_triangle = sys.modules[ + 'petstore_api.model.scalene_triangle'] +from petstore_api.model.triangle import Triangle + + +class TestTriangle(unittest.TestCase): + """Triangle unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testTriangle(self): + """Test Triangle""" + tri = Triangle(shape_type="Triangle", triangle_type="EquilateralTriangle") + assert isinstance(tri, equilateral_triangle.EquilateralTriangle) + tri = Triangle(shape_type="Triangle", triangle_type="IsoscelesTriangle") + assert isinstance(tri, isosceles_triangle.IsoscelesTriangle) + tri = Triangle(shape_type="Triangle", triangle_type="ScaleneTriangle") + assert isinstance(tri, scalene_triangle.ScaleneTriangle) + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/tests/util.py b/samples/openapi3/client/petstore/python-experimental/tests_manual/util.py similarity index 100% rename from samples/openapi3/client/petstore/python-experimental/tests/util.py rename to samples/openapi3/client/petstore/python-experimental/tests_manual/util.py