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}}
|
||||||
{{{.}}}
|
{{{.}}}
|
||||||
{{/imports}}
|
{{/imports}}
|
||||||
from {{modelPackage}}.{{classFilename}} import {{unescapedDescription}}
|
from {{modelPackage}}.{{classFilename}} import {{classname}}
|
||||||
|
|
||||||
|
|
||||||
class Test{{unescapedDescription}}(unittest.TestCase):
|
class Test{{classname}}(unittest.TestCase):
|
||||||
"""{{unescapedDescription}} unit test stubs"""
|
"""{{classname}} unit test stubs"""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
pass
|
pass
|
||||||
@ -23,10 +23,10 @@ class Test{{unescapedDescription}}(unittest.TestCase):
|
|||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test{{unescapedDescription}}(self):
|
def test{{classname}}(self):
|
||||||
"""Test {{unescapedDescription}}"""
|
"""Test {{classname}}"""
|
||||||
# FIXME: construct object with mandatory attributes with example values
|
# FIXME: construct object with mandatory attributes with example values
|
||||||
# model = {{unescapedDescription}}() # noqa: E501
|
# model = {{classname}}() # noqa: E501
|
||||||
pass
|
pass
|
||||||
|
|
||||||
{{/model}}
|
{{/model}}
|
||||||
|
@ -1407,6 +1407,7 @@ components:
|
|||||||
name: Tag
|
name: Tag
|
||||||
Pet:
|
Pet:
|
||||||
type: object
|
type: object
|
||||||
|
description: Pet object that needs to be added to the store
|
||||||
required:
|
required:
|
||||||
- name
|
- name
|
||||||
- photoUrls
|
- photoUrls
|
||||||
@ -2216,4 +2217,4 @@ components:
|
|||||||
type: string
|
type: string
|
||||||
default: '2010-01-01T10:10:10.000111+01:00'
|
default: '2010-01-01T10:10:10.000111+01:00'
|
||||||
example: '2010-01-01T10:10:10.000111+01:00'
|
example: '2010-01-01T10:10:10.000111+01:00'
|
||||||
format: date-time
|
format: date-time
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
# Pet
|
# Pet
|
||||||
|
|
||||||
|
Pet object that needs to be added to the store
|
||||||
## Properties
|
## Properties
|
||||||
Name | Type | Description | Notes
|
Name | Type | Description | Notes
|
||||||
------------ | ------------- | ------------- | -------------
|
------------ | ------------- | ------------- | -------------
|
||||||
|
@ -14,11 +14,8 @@ import sys
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import petstore_api
|
import petstore_api
|
||||||
try:
|
from petstore_api.model.enum_class import EnumClass
|
||||||
from petstore_api.model import enum_class
|
globals()['EnumClass'] = EnumClass
|
||||||
except ImportError:
|
|
||||||
enum_class = sys.modules[
|
|
||||||
'petstore_api.model.enum_class']
|
|
||||||
from petstore_api.model.additional_properties_with_array_of_enums import AdditionalPropertiesWithArrayOfEnums
|
from petstore_api.model.additional_properties_with_array_of_enums import AdditionalPropertiesWithArrayOfEnums
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,16 +14,10 @@ import sys
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import petstore_api
|
import petstore_api
|
||||||
try:
|
from petstore_api.model.cat import Cat
|
||||||
from petstore_api.model import cat
|
from petstore_api.model.dog import Dog
|
||||||
except ImportError:
|
globals()['Cat'] = Cat
|
||||||
cat = sys.modules[
|
globals()['Dog'] = Dog
|
||||||
'petstore_api.model.cat']
|
|
||||||
try:
|
|
||||||
from petstore_api.model import dog
|
|
||||||
except ImportError:
|
|
||||||
dog = sys.modules[
|
|
||||||
'petstore_api.model.dog']
|
|
||||||
from petstore_api.model.animal import Animal
|
from petstore_api.model.animal import Animal
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,11 +14,8 @@ import sys
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import petstore_api
|
import petstore_api
|
||||||
try:
|
from petstore_api.model.animal import Animal
|
||||||
from petstore_api.model import animal
|
globals()['Animal'] = Animal
|
||||||
except ImportError:
|
|
||||||
animal = sys.modules[
|
|
||||||
'petstore_api.model.animal']
|
|
||||||
from petstore_api.model.animal_farm import AnimalFarm
|
from petstore_api.model.animal_farm import AnimalFarm
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,11 +14,8 @@ import sys
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import petstore_api
|
import petstore_api
|
||||||
try:
|
from petstore_api.model.string_enum import StringEnum
|
||||||
from petstore_api.model import string_enum
|
globals()['StringEnum'] = StringEnum
|
||||||
except ImportError:
|
|
||||||
string_enum = sys.modules[
|
|
||||||
'petstore_api.model.string_enum']
|
|
||||||
from petstore_api.model.array_of_enums import ArrayOfEnums
|
from petstore_api.model.array_of_enums import ArrayOfEnums
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,11 +14,8 @@ import sys
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import petstore_api
|
import petstore_api
|
||||||
try:
|
from petstore_api.model.read_only_first import ReadOnlyFirst
|
||||||
from petstore_api.model import read_only_first
|
globals()['ReadOnlyFirst'] = ReadOnlyFirst
|
||||||
except ImportError:
|
|
||||||
read_only_first = sys.modules[
|
|
||||||
'petstore_api.model.read_only_first']
|
|
||||||
from petstore_api.model.array_test import ArrayTest
|
from petstore_api.model.array_test import ArrayTest
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,21 +14,12 @@ import sys
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import petstore_api
|
import petstore_api
|
||||||
try:
|
from petstore_api.model.address import Address
|
||||||
from petstore_api.model import address
|
from petstore_api.model.animal import Animal
|
||||||
except ImportError:
|
from petstore_api.model.cat_all_of import CatAllOf
|
||||||
address = sys.modules[
|
globals()['Address'] = Address
|
||||||
'petstore_api.model.address']
|
globals()['Animal'] = Animal
|
||||||
try:
|
globals()['CatAllOf'] = CatAllOf
|
||||||
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.cat import Cat
|
from petstore_api.model.cat import Cat
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,16 +14,10 @@ import sys
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import petstore_api
|
import petstore_api
|
||||||
try:
|
from petstore_api.model.child_cat_all_of import ChildCatAllOf
|
||||||
from petstore_api.model import child_cat_all_of
|
from petstore_api.model.parent_pet import ParentPet
|
||||||
except ImportError:
|
globals()['ChildCatAllOf'] = ChildCatAllOf
|
||||||
child_cat_all_of = sys.modules[
|
globals()['ParentPet'] = ParentPet
|
||||||
'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 import ChildCat
|
from petstore_api.model.child_cat import ChildCat
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,16 +14,10 @@ import sys
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import petstore_api
|
import petstore_api
|
||||||
try:
|
from petstore_api.model.quadrilateral_interface import QuadrilateralInterface
|
||||||
from petstore_api.model import quadrilateral_interface
|
from petstore_api.model.shape_interface import ShapeInterface
|
||||||
except ImportError:
|
globals()['QuadrilateralInterface'] = QuadrilateralInterface
|
||||||
quadrilateral_interface = sys.modules[
|
globals()['ShapeInterface'] = ShapeInterface
|
||||||
'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.complex_quadrilateral import ComplexQuadrilateral
|
from petstore_api.model.complex_quadrilateral import ComplexQuadrilateral
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,11 +14,10 @@ import sys
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import petstore_api
|
import petstore_api
|
||||||
try:
|
from petstore_api.model.animal import Animal
|
||||||
from petstore_api.model import animal
|
from petstore_api.model.number_with_validations import NumberWithValidations
|
||||||
except ImportError:
|
globals()['Animal'] = Animal
|
||||||
animal = sys.modules[
|
globals()['NumberWithValidations'] = NumberWithValidations
|
||||||
'petstore_api.model.animal']
|
|
||||||
from petstore_api.model.composed_one_of_number_with_validations import ComposedOneOfNumberWithValidations
|
from petstore_api.model.composed_one_of_number_with_validations import ComposedOneOfNumberWithValidations
|
||||||
|
|
||||||
|
|
||||||
@ -33,13 +32,9 @@ class TestComposedOneOfNumberWithValidations(unittest.TestCase):
|
|||||||
|
|
||||||
def testComposedOneOfNumberWithValidations(self):
|
def testComposedOneOfNumberWithValidations(self):
|
||||||
"""Test ComposedOneOfNumberWithValidations"""
|
"""Test ComposedOneOfNumberWithValidations"""
|
||||||
# we can make an instance that stores float data
|
# FIXME: construct object with mandatory attributes with example values
|
||||||
inst = ComposedOneOfNumberWithValidations(10.0)
|
# model = ComposedOneOfNumberWithValidations() # noqa: E501
|
||||||
from petstore_api.model import number_with_validations
|
pass
|
||||||
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__':
|
if __name__ == '__main__':
|
||||||
|
@ -14,16 +14,10 @@ import sys
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import petstore_api
|
import petstore_api
|
||||||
try:
|
from petstore_api.model.animal import Animal
|
||||||
from petstore_api.model import animal
|
from petstore_api.model.dog_all_of import DogAllOf
|
||||||
except ImportError:
|
globals()['Animal'] = Animal
|
||||||
animal = sys.modules[
|
globals()['DogAllOf'] = DogAllOf
|
||||||
'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.dog import Dog
|
from petstore_api.model.dog import Dog
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,21 +14,14 @@ import sys
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import petstore_api
|
import petstore_api
|
||||||
try:
|
from petstore_api.model.fruit import Fruit
|
||||||
from petstore_api.model import nullable_shape
|
from petstore_api.model.nullable_shape import NullableShape
|
||||||
except ImportError:
|
from petstore_api.model.shape import Shape
|
||||||
nullable_shape = sys.modules[
|
from petstore_api.model.shape_or_null import ShapeOrNull
|
||||||
'petstore_api.model.nullable_shape']
|
globals()['Fruit'] = Fruit
|
||||||
try:
|
globals()['NullableShape'] = NullableShape
|
||||||
from petstore_api.model import shape
|
globals()['Shape'] = Shape
|
||||||
except ImportError:
|
globals()['ShapeOrNull'] = ShapeOrNull
|
||||||
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
|
from petstore_api.model.drawing import Drawing
|
||||||
|
|
||||||
|
|
||||||
@ -41,130 +34,12 @@ class TestDrawing(unittest.TestCase):
|
|||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test_create_instances(self):
|
def testDrawing(self):
|
||||||
"""
|
"""Test Drawing"""
|
||||||
Validate instance can be created using pythonic name or OAS names.
|
# 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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
@ -14,31 +14,16 @@ import sys
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import petstore_api
|
import petstore_api
|
||||||
try:
|
from petstore_api.model.integer_enum import IntegerEnum
|
||||||
from petstore_api.model import integer_enum
|
from petstore_api.model.integer_enum_one_value import IntegerEnumOneValue
|
||||||
except ImportError:
|
from petstore_api.model.integer_enum_with_default_value import IntegerEnumWithDefaultValue
|
||||||
integer_enum = sys.modules[
|
from petstore_api.model.string_enum import StringEnum
|
||||||
'petstore_api.model.integer_enum']
|
from petstore_api.model.string_enum_with_default_value import StringEnumWithDefaultValue
|
||||||
try:
|
globals()['IntegerEnum'] = IntegerEnum
|
||||||
from petstore_api.model import integer_enum_one_value
|
globals()['IntegerEnumOneValue'] = IntegerEnumOneValue
|
||||||
except ImportError:
|
globals()['IntegerEnumWithDefaultValue'] = IntegerEnumWithDefaultValue
|
||||||
integer_enum_one_value = sys.modules[
|
globals()['StringEnum'] = StringEnum
|
||||||
'petstore_api.model.integer_enum_one_value']
|
globals()['StringEnumWithDefaultValue'] = StringEnumWithDefaultValue
|
||||||
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.enum_test import EnumTest
|
from petstore_api.model.enum_test import EnumTest
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,16 +14,10 @@ import sys
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import petstore_api
|
import petstore_api
|
||||||
try:
|
from petstore_api.model.shape_interface import ShapeInterface
|
||||||
from petstore_api.model import shape_interface
|
from petstore_api.model.triangle_interface import TriangleInterface
|
||||||
except ImportError:
|
globals()['ShapeInterface'] = ShapeInterface
|
||||||
shape_interface = sys.modules[
|
globals()['TriangleInterface'] = TriangleInterface
|
||||||
'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.equilateral_triangle import EquilateralTriangle
|
from petstore_api.model.equilateral_triangle import EquilateralTriangle
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,25 +9,11 @@
|
|||||||
Generated by: https://openapi-generator.tech
|
Generated by: https://openapi-generator.tech
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from collections import namedtuple
|
|
||||||
import unittest
|
import unittest
|
||||||
import json
|
|
||||||
from unittest.mock import patch
|
|
||||||
|
|
||||||
import petstore_api
|
import petstore_api
|
||||||
from petstore_api.api.fake_api import FakeApi # noqa: E501
|
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):
|
class TestFakeApi(unittest.TestCase):
|
||||||
@ -39,72 +25,6 @@ class TestFakeApi(unittest.TestCase):
|
|||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
pass
|
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):
|
def test_additional_properties_with_array_of_enums(self):
|
||||||
"""Test case for additional_properties_with_array_of_enums
|
"""Test case for additional_properties_with_array_of_enums
|
||||||
|
|
||||||
@ -112,138 +32,61 @@ class TestFakeApi(unittest.TestCase):
|
|||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def test_array_model(self):
|
||||||
|
"""Test case for array_model
|
||||||
|
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
def test_array_of_enums(self):
|
def test_array_of_enums(self):
|
||||||
"""Test case for array_of_enums
|
"""Test case for array_of_enums
|
||||||
|
|
||||||
Array of Enums # noqa: E501
|
Array of Enums # noqa: E501
|
||||||
"""
|
"""
|
||||||
from petstore_api.model import array_of_enums, string_enum
|
pass
|
||||||
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
|
def test_boolean(self):
|
||||||
with patch.object(RESTClientObject, 'request') as mock_method:
|
"""Test case for boolean
|
||||||
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
|
pass
|
||||||
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):
|
def test_composed_one_of_number_with_validations(self):
|
||||||
"""Test case for composed_one_of_number_with_validations
|
"""Test case for composed_one_of_number_with_validations
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from petstore_api.model import animal, composed_one_of_number_with_validations, number_with_validations
|
pass
|
||||||
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
|
def test_fake_health_get(self):
|
||||||
num_with_validations = number_with_validations.NumberWithValidations(10.0)
|
"""Test case for fake_health_get
|
||||||
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)
|
Health check endpoint # noqa: E501
|
||||||
self.assert_request_called_with(
|
"""
|
||||||
mock_method,
|
pass
|
||||||
'http://petstore.swagger.io:80/v2/fake/refs/composed_one_of_number_with_validations',
|
|
||||||
value_simple
|
|
||||||
)
|
|
||||||
|
|
||||||
assert isinstance(response, body.__class__)
|
def test_number_with_validations(self):
|
||||||
assert response == body
|
"""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):
|
def test_string(self):
|
||||||
"""Test case for string
|
"""Test case for string
|
||||||
|
|
||||||
"""
|
"""
|
||||||
endpoint = self.api.string
|
pass
|
||||||
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):
|
def test_string_enum(self):
|
||||||
"""Test case for string_enum
|
"""Test case for string_enum
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from petstore_api.model import string_enum
|
pass
|
||||||
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):
|
def test_test_body_with_file_schema(self):
|
||||||
"""Test case for test_body_with_file_schema
|
"""Test case for test_body_with_file_schema
|
||||||
|
@ -14,11 +14,8 @@ import sys
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import petstore_api
|
import petstore_api
|
||||||
try:
|
from petstore_api.model.file import File
|
||||||
from petstore_api.model import file
|
globals()['File'] = File
|
||||||
except ImportError:
|
|
||||||
file = sys.modules[
|
|
||||||
'petstore_api.model.file']
|
|
||||||
from petstore_api.model.file_schema_test_class import FileSchemaTestClass
|
from petstore_api.model.file_schema_test_class import FileSchemaTestClass
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,16 +14,10 @@ import sys
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import petstore_api
|
import petstore_api
|
||||||
try:
|
from petstore_api.model.apple import Apple
|
||||||
from petstore_api.model import apple
|
from petstore_api.model.banana import Banana
|
||||||
except ImportError:
|
globals()['Apple'] = Apple
|
||||||
apple = sys.modules[
|
globals()['Banana'] = Banana
|
||||||
'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
|
from petstore_api.model.fruit import Fruit
|
||||||
|
|
||||||
|
|
||||||
@ -38,184 +32,10 @@ class TestFruit(unittest.TestCase):
|
|||||||
|
|
||||||
def testFruit(self):
|
def testFruit(self):
|
||||||
"""Test Fruit"""
|
"""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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
@ -14,16 +14,10 @@ import sys
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import petstore_api
|
import petstore_api
|
||||||
try:
|
from petstore_api.model.apple_req import AppleReq
|
||||||
from petstore_api.model import apple_req
|
from petstore_api.model.banana_req import BananaReq
|
||||||
except ImportError:
|
globals()['AppleReq'] = AppleReq
|
||||||
apple_req = sys.modules[
|
globals()['BananaReq'] = BananaReq
|
||||||
'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
|
from petstore_api.model.fruit_req import FruitReq
|
||||||
|
|
||||||
|
|
||||||
@ -38,146 +32,10 @@ class TestFruitReq(unittest.TestCase):
|
|||||||
|
|
||||||
def testFruitReq(self):
|
def testFruitReq(self):
|
||||||
"""Test FruitReq"""
|
"""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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
@ -14,16 +14,10 @@ import sys
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import petstore_api
|
import petstore_api
|
||||||
try:
|
from petstore_api.model.apple import Apple
|
||||||
from petstore_api.model import apple
|
from petstore_api.model.banana import Banana
|
||||||
except ImportError:
|
globals()['Apple'] = Apple
|
||||||
apple = sys.modules[
|
globals()['Banana'] = Banana
|
||||||
'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
|
from petstore_api.model.gm_fruit import GmFruit
|
||||||
|
|
||||||
|
|
||||||
@ -38,193 +32,10 @@ class TestGmFruit(unittest.TestCase):
|
|||||||
|
|
||||||
def testGmFruit(self):
|
def testGmFruit(self):
|
||||||
"""Test GmFruit"""
|
"""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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
@ -14,16 +14,10 @@ import sys
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import petstore_api
|
import petstore_api
|
||||||
try:
|
from petstore_api.model.child_cat import ChildCat
|
||||||
from petstore_api.model import child_cat
|
from petstore_api.model.parent_pet import ParentPet
|
||||||
except ImportError:
|
globals()['ChildCat'] = ChildCat
|
||||||
child_cat = sys.modules[
|
globals()['ParentPet'] = ParentPet
|
||||||
'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.grandparent_animal import GrandparentAnimal
|
from petstore_api.model.grandparent_animal import GrandparentAnimal
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,11 +14,8 @@ import sys
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import petstore_api
|
import petstore_api
|
||||||
try:
|
from petstore_api.model.foo import Foo
|
||||||
from petstore_api.model import foo
|
globals()['Foo'] = Foo
|
||||||
except ImportError:
|
|
||||||
foo = sys.modules[
|
|
||||||
'petstore_api.model.foo']
|
|
||||||
from petstore_api.model.inline_response_default import InlineResponseDefault
|
from petstore_api.model.inline_response_default import InlineResponseDefault
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,14 +28,9 @@ class TestIntegerEnumOneValue(unittest.TestCase):
|
|||||||
|
|
||||||
def testIntegerEnumOneValue(self):
|
def testIntegerEnumOneValue(self):
|
||||||
"""Test IntegerEnumOneValue"""
|
"""Test IntegerEnumOneValue"""
|
||||||
model = IntegerEnumOneValue()
|
# FIXME: construct object with mandatory attributes with example values
|
||||||
assert model.value == 0, "With only one option, the value is assigned automatically"
|
# model = IntegerEnumOneValue() # noqa: E501
|
||||||
|
pass
|
||||||
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__':
|
if __name__ == '__main__':
|
||||||
|
@ -14,16 +14,10 @@ import sys
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import petstore_api
|
import petstore_api
|
||||||
try:
|
from petstore_api.model.shape_interface import ShapeInterface
|
||||||
from petstore_api.model import shape_interface
|
from petstore_api.model.triangle_interface import TriangleInterface
|
||||||
except ImportError:
|
globals()['ShapeInterface'] = ShapeInterface
|
||||||
shape_interface = sys.modules[
|
globals()['TriangleInterface'] = TriangleInterface
|
||||||
'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.isosceles_triangle import IsoscelesTriangle
|
from petstore_api.model.isosceles_triangle import IsoscelesTriangle
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,16 +14,12 @@ import sys
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import petstore_api
|
import petstore_api
|
||||||
try:
|
from petstore_api.model.pig import Pig
|
||||||
from petstore_api.model import whale
|
from petstore_api.model.whale import Whale
|
||||||
except ImportError:
|
from petstore_api.model.zebra import Zebra
|
||||||
whale = sys.modules[
|
globals()['Pig'] = Pig
|
||||||
'petstore_api.model.whale']
|
globals()['Whale'] = Whale
|
||||||
try:
|
globals()['Zebra'] = Zebra
|
||||||
from petstore_api.model import zebra
|
|
||||||
except ImportError:
|
|
||||||
zebra = sys.modules[
|
|
||||||
'petstore_api.model.zebra']
|
|
||||||
from petstore_api.model.mammal import Mammal
|
from petstore_api.model.mammal import Mammal
|
||||||
|
|
||||||
|
|
||||||
@ -38,11 +34,9 @@ class TestMammal(unittest.TestCase):
|
|||||||
|
|
||||||
def testMammal(self):
|
def testMammal(self):
|
||||||
"""Test Mammal"""
|
"""Test Mammal"""
|
||||||
|
# FIXME: construct object with mandatory attributes with example values
|
||||||
# tests that we can make a BasquePig by traveling through descendant discriminator in Pig
|
# model = Mammal() # noqa: E501
|
||||||
model = Mammal(class_name="BasquePig")
|
pass
|
||||||
from petstore_api.model import basque_pig
|
|
||||||
assert isinstance(model, basque_pig.BasquePig)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -14,11 +14,8 @@ import sys
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import petstore_api
|
import petstore_api
|
||||||
try:
|
from petstore_api.model.string_boolean_map import StringBooleanMap
|
||||||
from petstore_api.model import string_boolean_map
|
globals()['StringBooleanMap'] = StringBooleanMap
|
||||||
except ImportError:
|
|
||||||
string_boolean_map = sys.modules[
|
|
||||||
'petstore_api.model.string_boolean_map']
|
|
||||||
from petstore_api.model.map_test import MapTest
|
from petstore_api.model.map_test import MapTest
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,11 +14,8 @@ import sys
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import petstore_api
|
import petstore_api
|
||||||
try:
|
from petstore_api.model.animal import Animal
|
||||||
from petstore_api.model import animal
|
globals()['Animal'] = Animal
|
||||||
except ImportError:
|
|
||||||
animal = sys.modules[
|
|
||||||
'petstore_api.model.animal']
|
|
||||||
from petstore_api.model.mixed_properties_and_additional_properties_class import MixedPropertiesAndAdditionalPropertiesClass
|
from petstore_api.model.mixed_properties_and_additional_properties_class import MixedPropertiesAndAdditionalPropertiesClass
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,16 +14,10 @@ import sys
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import petstore_api
|
import petstore_api
|
||||||
try:
|
from petstore_api.model.quadrilateral import Quadrilateral
|
||||||
from petstore_api.model import quadrilateral
|
from petstore_api.model.triangle import Triangle
|
||||||
except ImportError:
|
globals()['Quadrilateral'] = Quadrilateral
|
||||||
quadrilateral = sys.modules[
|
globals()['Triangle'] = Triangle
|
||||||
'petstore_api.model.quadrilateral']
|
|
||||||
try:
|
|
||||||
from petstore_api.model import triangle
|
|
||||||
except ImportError:
|
|
||||||
triangle = sys.modules[
|
|
||||||
'petstore_api.model.triangle']
|
|
||||||
from petstore_api.model.nullable_shape import NullableShape
|
from petstore_api.model.nullable_shape import NullableShape
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,15 +28,9 @@ class TestNumberWithValidations(unittest.TestCase):
|
|||||||
|
|
||||||
def testNumberWithValidations(self):
|
def testNumberWithValidations(self):
|
||||||
"""Test NumberWithValidations"""
|
"""Test NumberWithValidations"""
|
||||||
valid_values = [10.0, 15.0, 20.0]
|
# FIXME: construct object with mandatory attributes with example values
|
||||||
for valid_value in valid_values:
|
# model = NumberWithValidations() # noqa: E501
|
||||||
model = NumberWithValidations(valid_value)
|
pass
|
||||||
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__':
|
if __name__ == '__main__':
|
||||||
|
@ -14,11 +14,8 @@ import sys
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import petstore_api
|
import petstore_api
|
||||||
try:
|
from petstore_api.model.number_with_validations import NumberWithValidations
|
||||||
from petstore_api.model import number_with_validations
|
globals()['NumberWithValidations'] = NumberWithValidations
|
||||||
except ImportError:
|
|
||||||
number_with_validations = sys.modules[
|
|
||||||
'petstore_api.model.number_with_validations']
|
|
||||||
from petstore_api.model.object_model_with_ref_props import ObjectModelWithRefProps
|
from petstore_api.model.object_model_with_ref_props import ObjectModelWithRefProps
|
||||||
|
|
||||||
|
|
||||||
@ -33,15 +30,9 @@ class TestObjectModelWithRefProps(unittest.TestCase):
|
|||||||
|
|
||||||
def testObjectModelWithRefProps(self):
|
def testObjectModelWithRefProps(self):
|
||||||
"""Test ObjectModelWithRefProps"""
|
"""Test ObjectModelWithRefProps"""
|
||||||
from petstore_api.model.number_with_validations import NumberWithValidations
|
# FIXME: construct object with mandatory attributes with example values
|
||||||
self.assertEqual(
|
# model = ObjectModelWithRefProps() # noqa: E501
|
||||||
ObjectModelWithRefProps.openapi_types,
|
pass
|
||||||
{
|
|
||||||
'my_number': (NumberWithValidations,),
|
|
||||||
'my_string': (str,),
|
|
||||||
'my_boolean': (bool,),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -14,16 +14,10 @@ import sys
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import petstore_api
|
import petstore_api
|
||||||
try:
|
from petstore_api.model.child_cat import ChildCat
|
||||||
from petstore_api.model import child_cat
|
from petstore_api.model.grandparent_animal import GrandparentAnimal
|
||||||
except ImportError:
|
globals()['ChildCat'] = ChildCat
|
||||||
child_cat = sys.modules[
|
globals()['GrandparentAnimal'] = GrandparentAnimal
|
||||||
'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
|
from petstore_api.model.parent_pet import ParentPet
|
||||||
|
|
||||||
|
|
||||||
@ -38,12 +32,9 @@ class TestParentPet(unittest.TestCase):
|
|||||||
|
|
||||||
def testParentPet(self):
|
def testParentPet(self):
|
||||||
"""Test ParentPet"""
|
"""Test ParentPet"""
|
||||||
|
# FIXME: construct object with mandatory attributes with example values
|
||||||
# test that we can make a ParentPet from a ParentPet
|
# model = ParentPet() # noqa: E501
|
||||||
# which requires that we travel back through ParentPet's allOf descendant
|
pass
|
||||||
# GrandparentAnimal, and we use the descendant's discriminator to make ParentPet
|
|
||||||
model = ParentPet(pet_type="ParentPet")
|
|
||||||
assert isinstance(model, ParentPet)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -14,16 +14,10 @@ import sys
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import petstore_api
|
import petstore_api
|
||||||
try:
|
from petstore_api.model.category import Category
|
||||||
from petstore_api.model import category
|
from petstore_api.model.tag import Tag
|
||||||
except ImportError:
|
globals()['Category'] = Category
|
||||||
category = sys.modules[
|
globals()['Tag'] = Tag
|
||||||
'petstore_api.model.category']
|
|
||||||
try:
|
|
||||||
from petstore_api.model import tag
|
|
||||||
except ImportError:
|
|
||||||
tag = sys.modules[
|
|
||||||
'petstore_api.model.tag']
|
|
||||||
from petstore_api.model.pet import Pet
|
from petstore_api.model.pet import Pet
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,16 +14,10 @@ import sys
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import petstore_api
|
import petstore_api
|
||||||
try:
|
from petstore_api.model.basque_pig import BasquePig
|
||||||
from petstore_api.model import basque_pig
|
from petstore_api.model.danish_pig import DanishPig
|
||||||
except ImportError:
|
globals()['BasquePig'] = BasquePig
|
||||||
basque_pig = sys.modules[
|
globals()['DanishPig'] = DanishPig
|
||||||
'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.pig import Pig
|
from petstore_api.model.pig import Pig
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,16 +14,10 @@ import sys
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import petstore_api
|
import petstore_api
|
||||||
try:
|
from petstore_api.model.complex_quadrilateral import ComplexQuadrilateral
|
||||||
from petstore_api.model import complex_quadrilateral
|
from petstore_api.model.simple_quadrilateral import SimpleQuadrilateral
|
||||||
except ImportError:
|
globals()['ComplexQuadrilateral'] = ComplexQuadrilateral
|
||||||
complex_quadrilateral = sys.modules[
|
globals()['SimpleQuadrilateral'] = SimpleQuadrilateral
|
||||||
'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
|
from petstore_api.model.quadrilateral import Quadrilateral
|
||||||
|
|
||||||
|
|
||||||
@ -38,10 +32,9 @@ class TestQuadrilateral(unittest.TestCase):
|
|||||||
|
|
||||||
def testQuadrilateral(self):
|
def testQuadrilateral(self):
|
||||||
"""Test Quadrilateral"""
|
"""Test Quadrilateral"""
|
||||||
instance = Quadrilateral(shape_type="Quadrilateral", quadrilateral_type="ComplexQuadrilateral")
|
# FIXME: construct object with mandatory attributes with example values
|
||||||
assert isinstance(instance, complex_quadrilateral.ComplexQuadrilateral)
|
# model = Quadrilateral() # noqa: E501
|
||||||
instance = Quadrilateral(shape_type="Quadrilateral", quadrilateral_type="SimpleQuadrilateral")
|
pass
|
||||||
assert isinstance(instance, simple_quadrilateral.SimpleQuadrilateral)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -14,16 +14,10 @@ import sys
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import petstore_api
|
import petstore_api
|
||||||
try:
|
from petstore_api.model.shape_interface import ShapeInterface
|
||||||
from petstore_api.model import shape_interface
|
from petstore_api.model.triangle_interface import TriangleInterface
|
||||||
except ImportError:
|
globals()['ShapeInterface'] = ShapeInterface
|
||||||
shape_interface = sys.modules[
|
globals()['TriangleInterface'] = TriangleInterface
|
||||||
'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.scalene_triangle import ScaleneTriangle
|
from petstore_api.model.scalene_triangle import ScaleneTriangle
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,16 +14,10 @@ import sys
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import petstore_api
|
import petstore_api
|
||||||
try:
|
from petstore_api.model.quadrilateral import Quadrilateral
|
||||||
from petstore_api.model import quadrilateral
|
from petstore_api.model.triangle import Triangle
|
||||||
except ImportError:
|
globals()['Quadrilateral'] = Quadrilateral
|
||||||
quadrilateral = sys.modules[
|
globals()['Triangle'] = Triangle
|
||||||
'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
|
from petstore_api.model.shape import Shape
|
||||||
|
|
||||||
|
|
||||||
@ -38,71 +32,10 @@ class TestShape(unittest.TestCase):
|
|||||||
|
|
||||||
def testShape(self):
|
def testShape(self):
|
||||||
"""Test Shape"""
|
"""Test Shape"""
|
||||||
from petstore_api.model import complex_quadrilateral
|
# FIXME: construct object with mandatory attributes with example values
|
||||||
from petstore_api.model import simple_quadrilateral
|
# model = Shape() # noqa: E501
|
||||||
from petstore_api.model import equilateral_triangle
|
pass
|
||||||
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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
@ -14,16 +14,10 @@ import sys
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import petstore_api
|
import petstore_api
|
||||||
try:
|
from petstore_api.model.quadrilateral import Quadrilateral
|
||||||
from petstore_api.model import quadrilateral
|
from petstore_api.model.triangle import Triangle
|
||||||
except ImportError:
|
globals()['Quadrilateral'] = Quadrilateral
|
||||||
quadrilateral = sys.modules[
|
globals()['Triangle'] = Triangle
|
||||||
'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_or_null import ShapeOrNull
|
from petstore_api.model.shape_or_null import ShapeOrNull
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,16 +14,10 @@ import sys
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import petstore_api
|
import petstore_api
|
||||||
try:
|
from petstore_api.model.quadrilateral_interface import QuadrilateralInterface
|
||||||
from petstore_api.model import quadrilateral_interface
|
from petstore_api.model.shape_interface import ShapeInterface
|
||||||
except ImportError:
|
globals()['QuadrilateralInterface'] = QuadrilateralInterface
|
||||||
quadrilateral_interface = sys.modules[
|
globals()['ShapeInterface'] = ShapeInterface
|
||||||
'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.simple_quadrilateral import SimpleQuadrilateral
|
from petstore_api.model.simple_quadrilateral import SimpleQuadrilateral
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,22 +28,9 @@ class TestStringEnum(unittest.TestCase):
|
|||||||
|
|
||||||
def testStringEnum(self):
|
def testStringEnum(self):
|
||||||
"""Test StringEnum"""
|
"""Test StringEnum"""
|
||||||
inst = StringEnum(None)
|
# FIXME: construct object with mandatory attributes with example values
|
||||||
self.assertIsNone(inst)
|
# model = StringEnum() # noqa: E501
|
||||||
|
pass
|
||||||
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__':
|
if __name__ == '__main__':
|
||||||
|
@ -14,21 +14,12 @@ import sys
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import petstore_api
|
import petstore_api
|
||||||
try:
|
from petstore_api.model.equilateral_triangle import EquilateralTriangle
|
||||||
from petstore_api.model import equilateral_triangle
|
from petstore_api.model.isosceles_triangle import IsoscelesTriangle
|
||||||
except ImportError:
|
from petstore_api.model.scalene_triangle import ScaleneTriangle
|
||||||
equilateral_triangle = sys.modules[
|
globals()['EquilateralTriangle'] = EquilateralTriangle
|
||||||
'petstore_api.model.equilateral_triangle']
|
globals()['IsoscelesTriangle'] = IsoscelesTriangle
|
||||||
try:
|
globals()['ScaleneTriangle'] = ScaleneTriangle
|
||||||
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
|
from petstore_api.model.triangle import Triangle
|
||||||
|
|
||||||
|
|
||||||
@ -43,12 +34,9 @@ class TestTriangle(unittest.TestCase):
|
|||||||
|
|
||||||
def testTriangle(self):
|
def testTriangle(self):
|
||||||
"""Test Triangle"""
|
"""Test Triangle"""
|
||||||
tri = Triangle(shape_type="Triangle", triangle_type="EquilateralTriangle")
|
# FIXME: construct object with mandatory attributes with example values
|
||||||
assert isinstance(tri, equilateral_triangle.EquilateralTriangle)
|
# model = Triangle() # noqa: E501
|
||||||
tri = Triangle(shape_type="Triangle", triangle_type="IsoscelesTriangle")
|
pass
|
||||||
assert isinstance(tri, isosceles_triangle.IsoscelesTriangle)
|
|
||||||
tri = Triangle(shape_type="Triangle", triangle_type="ScaleneTriangle")
|
|
||||||
assert isinstance(tri, scalene_triangle.ScaleneTriangle)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
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