forked from loafle/openapi-generator-original
[python-experimental] generate model if type != object if enums/validations exist (#2757)
* Python-experimental adds model_utils module, refactors python api class * Fixes python-experimental so the sample sare generated in the petstore_api folder * FIxes python samples tests * Updates python and python-experimental tests * Fixes python-experimental tests * Adds newlines back to python templates + samples * Reverts files with newline tweaks back to master branch versions * Fixes indentation errors in python-experimental api_client * Removes unused files * Python files now generated in correct folders * Adds logging when the user tries to set generateAliasAsModel in python-experimental * Fixes typo
This commit is contained in:
committed by
William Cheng
parent
002da8d9f9
commit
252c3e58be
@@ -40,11 +40,23 @@ class TestFakeApi(unittest.TestCase):
|
||||
"""
|
||||
pass
|
||||
|
||||
def test_fake_outer_enum_serialize(self):
|
||||
"""Test case for fake_outer_enum_serialize
|
||||
|
||||
"""
|
||||
# verify that the input and output are type OuterEnum
|
||||
endpoint = self.api.fake_outer_enum_serialize
|
||||
assert endpoint.openapi_types['body'] == 'OuterEnum'
|
||||
assert endpoint.settings['response_type'] == 'OuterEnum'
|
||||
|
||||
def test_fake_outer_number_serialize(self):
|
||||
"""Test case for fake_outer_number_serialize
|
||||
|
||||
"""
|
||||
pass
|
||||
# verify that the input and output are the correct type
|
||||
endpoint = self.api.fake_outer_number_serialize
|
||||
assert endpoint.openapi_types['body'] == 'OuterNumber'
|
||||
assert endpoint.settings['response_type'] == 'OuterNumber'
|
||||
|
||||
def test_fake_outer_string_serialize(self):
|
||||
"""Test case for fake_outer_string_serialize
|
||||
@@ -70,14 +82,38 @@ class TestFakeApi(unittest.TestCase):
|
||||
|
||||
Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 # noqa: E501
|
||||
"""
|
||||
pass
|
||||
# check that we can access the endpoint's validations
|
||||
endpoint = self.api.test_endpoint_parameters
|
||||
assert endpoint.validations[('number',)] == {
|
||||
'inclusive_maximum': 543.2,
|
||||
'inclusive_minimum': 32.1,
|
||||
}
|
||||
# make sure that an exception is thrown on an invalid value
|
||||
keyword_args = dict(
|
||||
number=544, # invalid
|
||||
double=100,
|
||||
pattern_without_delimiter="abc",
|
||||
byte='sample string'
|
||||
)
|
||||
with self.assertRaises(petstore_api.ApiValueError):
|
||||
self.api.test_endpoint_parameters(**keyword_args)
|
||||
|
||||
def test_test_enum_parameters(self):
|
||||
"""Test case for test_enum_parameters
|
||||
|
||||
To test enum parameters # noqa: E501
|
||||
"""
|
||||
pass
|
||||
# check that we can access the endpoint's allowed_values
|
||||
endpoint = self.api.test_enum_parameters
|
||||
assert endpoint.allowed_values[('enum_query_string',)] == {
|
||||
"_ABC": "_abc",
|
||||
"-EFG": "-efg",
|
||||
"(XYZ)": "(xyz)"
|
||||
}
|
||||
# make sure that an exception is thrown on an invalid value
|
||||
keyword_args = dict(enum_query_string="bad value")
|
||||
with self.assertRaises(petstore_api.ApiValueError):
|
||||
self.api.test_enum_parameters(**keyword_args)
|
||||
|
||||
def test_test_inline_additional_properties(self):
|
||||
"""Test case for test_inline_additional_properties
|
||||
|
||||
@@ -2,9 +2,7 @@
|
||||
|
||||
"""
|
||||
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
|
||||
|
||||
OpenAPI spec version: 1.0.0
|
||||
Generated by: https://openapi-generator.tech
|
||||
"""
|
||||
@@ -16,24 +14,139 @@ import unittest
|
||||
|
||||
import petstore_api
|
||||
from petstore_api.models.format_test import FormatTest # noqa: E501
|
||||
from petstore_api.rest import ApiException
|
||||
from petstore_api import ApiValueError
|
||||
|
||||
|
||||
class TestFormatTest(unittest.TestCase):
|
||||
"""FormatTest unit test stubs"""
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
self.required_named_args = dict(
|
||||
number=40.1,
|
||||
byte='what',
|
||||
date='2019-03-23',
|
||||
password='rainbowtable'
|
||||
)
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
def test_integer(self):
|
||||
var_name = 'integer'
|
||||
validations = FormatTest.validations[(var_name,)]
|
||||
keyword_args = {}
|
||||
keyword_args.update(self.required_named_args)
|
||||
key_adder_pairs = [('inclusive_maximum', 1), ('inclusive_minimum', -1)]
|
||||
for key, adder in key_adder_pairs:
|
||||
# value outside the bounds throws an error
|
||||
with self.assertRaises(ApiValueError):
|
||||
keyword_args[var_name] = validations[key] + adder
|
||||
FormatTest(**keyword_args)
|
||||
|
||||
def testFormatTest(self):
|
||||
"""Test FormatTest"""
|
||||
# FIXME: construct object with mandatory attributes with example values
|
||||
# model = petstore_api.models.format_test.FormatTest() # noqa: E501
|
||||
pass
|
||||
# value inside the bounds works
|
||||
keyword_args[var_name] = validations[key]
|
||||
assert (getattr(FormatTest(**keyword_args), var_name) ==
|
||||
validations[key])
|
||||
|
||||
def test_int32(self):
|
||||
var_name = 'int32'
|
||||
validations = FormatTest.validations[(var_name,)]
|
||||
keyword_args = {}
|
||||
keyword_args.update(self.required_named_args)
|
||||
key_adder_pairs = [('inclusive_maximum', 1), ('inclusive_minimum', -1)]
|
||||
for key, adder in key_adder_pairs:
|
||||
# value outside the bounds throws an error
|
||||
with self.assertRaises(ApiValueError):
|
||||
keyword_args[var_name] = validations[key] + adder
|
||||
FormatTest(**keyword_args)
|
||||
|
||||
# value inside the bounds works
|
||||
keyword_args[var_name] = validations[key]
|
||||
assert (getattr(FormatTest(**keyword_args), var_name) ==
|
||||
validations[key])
|
||||
|
||||
def test_number(self):
|
||||
var_name = 'number'
|
||||
validations = FormatTest.validations[(var_name,)]
|
||||
keyword_args = {}
|
||||
keyword_args.update(self.required_named_args)
|
||||
key_adder_pairs = [('inclusive_maximum', 1), ('inclusive_minimum', -1)]
|
||||
for key, adder in key_adder_pairs:
|
||||
# value outside the bounds throws an error
|
||||
with self.assertRaises(ApiValueError):
|
||||
keyword_args[var_name] = validations[key] + adder
|
||||
FormatTest(**keyword_args)
|
||||
|
||||
# value inside the bounds works
|
||||
keyword_args[var_name] = validations[key]
|
||||
assert (getattr(FormatTest(**keyword_args), var_name) ==
|
||||
validations[key])
|
||||
|
||||
def test_float(self):
|
||||
var_name = 'float'
|
||||
validations = FormatTest.validations[(var_name,)]
|
||||
keyword_args = {}
|
||||
keyword_args.update(self.required_named_args)
|
||||
key_adder_pairs = [('inclusive_maximum', 1), ('inclusive_minimum', -1)]
|
||||
for key, adder in key_adder_pairs:
|
||||
# value outside the bounds throws an error
|
||||
with self.assertRaises(ApiValueError):
|
||||
keyword_args[var_name] = validations[key] + adder
|
||||
FormatTest(**keyword_args)
|
||||
|
||||
# value inside the bounds works
|
||||
keyword_args[var_name] = validations[key]
|
||||
assert (getattr(FormatTest(**keyword_args), var_name) ==
|
||||
validations[key])
|
||||
|
||||
def test_double(self):
|
||||
var_name = 'double'
|
||||
validations = FormatTest.validations[(var_name,)]
|
||||
keyword_args = {}
|
||||
keyword_args.update(self.required_named_args)
|
||||
key_adder_pairs = [('inclusive_maximum', 1), ('inclusive_minimum', -1)]
|
||||
for key, adder in key_adder_pairs:
|
||||
# value outside the bounds throws an error
|
||||
with self.assertRaises(ApiValueError):
|
||||
keyword_args[var_name] = validations[key] + adder
|
||||
FormatTest(**keyword_args)
|
||||
|
||||
# value inside the bounds works
|
||||
keyword_args[var_name] = validations[key]
|
||||
assert (getattr(FormatTest(**keyword_args), var_name) ==
|
||||
validations[key])
|
||||
|
||||
def test_password(self):
|
||||
var_name = 'password'
|
||||
validations = FormatTest.validations[(var_name,)]
|
||||
keyword_args = {}
|
||||
keyword_args.update(self.required_named_args)
|
||||
key_adder_pairs = [('max_length', 1), ('min_length', -1)]
|
||||
for key, adder in key_adder_pairs:
|
||||
# value outside the bounds throws an error
|
||||
with self.assertRaises(ApiValueError):
|
||||
keyword_args[var_name] = 'a'*(validations[key] + adder)
|
||||
FormatTest(**keyword_args)
|
||||
|
||||
# value inside the bounds works
|
||||
keyword_args[var_name] = 'a'*validations[key]
|
||||
assert (getattr(FormatTest(**keyword_args), var_name) ==
|
||||
'a'*validations[key])
|
||||
|
||||
def test_string(self):
|
||||
var_name = 'string'
|
||||
validations = FormatTest.validations[(var_name,)]
|
||||
keyword_args = {}
|
||||
keyword_args.update(self.required_named_args)
|
||||
values_invalid = ['abc3', '1', '.', ' ', 'مرحبا', '']
|
||||
for value_invalid in values_invalid:
|
||||
# invalid values throw exceptions
|
||||
with self.assertRaises(ApiValueError):
|
||||
keyword_args[var_name] = value_invalid
|
||||
FormatTest(**keyword_args)
|
||||
|
||||
# valid value works
|
||||
value_valid = 'abcdz'
|
||||
keyword_args[var_name] = value_valid
|
||||
assert getattr(FormatTest(**keyword_args), var_name) == value_valid
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
unittest.main()
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
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
|
||||
|
||||
OpenAPI spec version: 1.0.0
|
||||
The version of the OpenAPI document: 1.0.0
|
||||
Generated by: https://openapi-generator.tech
|
||||
"""
|
||||
|
||||
@@ -30,10 +30,18 @@ class TestOuterEnum(unittest.TestCase):
|
||||
|
||||
def testOuterEnum(self):
|
||||
"""Test OuterEnum"""
|
||||
# FIXME: construct object with mandatory attributes with example values
|
||||
# model = petstore_api.models.outer_enum.OuterEnum() # noqa: E501
|
||||
pass
|
||||
|
||||
# make sure that we can access its allowed_values
|
||||
assert OuterEnum.allowed_values[('value',)] == {
|
||||
'PLACED': "placed",
|
||||
'APPROVED': "approved",
|
||||
'DELIVERED': "delivered"
|
||||
}
|
||||
# make sure that an exception is thrown on an invalid value
|
||||
with self.assertRaises(petstore_api.ApiValueError):
|
||||
OuterEnum('bad_value')
|
||||
# make sure valid value works
|
||||
valid_value = OuterEnum.allowed_values[('value',)]['PLACED']
|
||||
assert valid_value == OuterEnum(valid_value).value
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
# 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 __future__ import absolute_import
|
||||
|
||||
import unittest
|
||||
|
||||
import petstore_api
|
||||
from petstore_api.models.outer_number import OuterNumber # noqa: E501
|
||||
from petstore_api.rest import ApiException
|
||||
|
||||
|
||||
class TestOuterNumber(unittest.TestCase):
|
||||
"""OuterNumber unit test stubs"""
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def testOuterNumber(self):
|
||||
"""Test OuterNumber"""
|
||||
# FIXME: construct object with mandatory attributes with example values
|
||||
# model = petstore_api.models.outer_number.OuterNumber() # noqa: E501
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -0,0 +1,39 @@
|
||||
# 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 __future__ import absolute_import
|
||||
|
||||
import unittest
|
||||
|
||||
import petstore_api
|
||||
from petstore_api.models.string_boolean_map import StringBooleanMap # noqa: E501
|
||||
from petstore_api.rest import ApiException
|
||||
|
||||
|
||||
class TestStringBooleanMap(unittest.TestCase):
|
||||
"""StringBooleanMap unit test stubs"""
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def testStringBooleanMap(self):
|
||||
"""Test StringBooleanMap"""
|
||||
# FIXME: construct object with mandatory attributes with example values
|
||||
# model = petstore_api.models.string_boolean_map.StringBooleanMap() # noqa: E501
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -32,10 +32,8 @@ class TestTypeHolderDefault(unittest.TestCase):
|
||||
"""Test TypeHolderDefault"""
|
||||
# required_vars are set to None now until swagger-parser/swagger-core fixes
|
||||
# https://github.com/swagger-api/swagger-parser/issues/971
|
||||
with self.assertRaises(TypeError):
|
||||
model = TypeHolderDefault()
|
||||
array_item = [1, 2, 3]
|
||||
model = TypeHolderDefault(array_item)
|
||||
model = TypeHolderDefault(array_item=array_item)
|
||||
self.assertEqual(model.string_item, 'what')
|
||||
self.assertEqual(model.bool_item, True)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user