forked from loafle/openapi-generator-original
[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
This commit is contained in:
parent
f609120236
commit
6653cedcc7
@ -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}}
|
||||
|
@ -1407,6 +1407,7 @@ components:
|
||||
name: Tag
|
||||
Pet:
|
||||
type: object
|
||||
description: Pet object that needs to be added to the store
|
||||
required:
|
||||
- name
|
||||
- photoUrls
|
||||
|
@ -1,5 +1,6 @@
|
||||
# Pet
|
||||
|
||||
Pet object that needs to be added to the store
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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__':
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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__':
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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__':
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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__':
|
||||
|
@ -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__':
|
||||
|
@ -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__':
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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__':
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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__':
|
||||
|
@ -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__':
|
||||
|
@ -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()
|
@ -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()
|
@ -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()
|
@ -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()
|
@ -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()
|
@ -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()
|
@ -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()
|
@ -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()
|
@ -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()
|
@ -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()
|
@ -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()
|
@ -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()
|
@ -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()
|
@ -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()
|
@ -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()
|
Loading…
x
Reference in New Issue
Block a user