mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-08 21:06:11 +00:00
[python-client] Add model default values (#1776)
* Adds two models to the v2.0 spec, uses examples as defaults in python client * Adds array default and type_holder_default and type_holder_example tests * Re-generated python security client with ./bin/security/python-petstore.sh * Changes comment text, rebased master * Updates client + server samples * Adds missing samples updates * Changes python client to look for true or false with booleans in toDefaultValue * Changes boolean casting to use Boolean.valueOf * Adds deserialization fix for python tests * Changes Mock to namedtuple in python deserialization tests * Actually remove unittest.mock
This commit is contained in:
committed by
William Cheng
parent
189849319c
commit
539ec23298
@@ -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
|
||||
|
||||
OpenAPI spec version: 1.0.0
|
||||
Generated by: https://openapi-generator.tech
|
||||
"""
|
||||
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import unittest
|
||||
|
||||
import petstore_api
|
||||
from petstore_api.models.type_holder_default import TypeHolderDefault # noqa: E501
|
||||
from petstore_api.rest import ApiException
|
||||
|
||||
|
||||
class TestTypeHolderDefault(unittest.TestCase):
|
||||
"""TypeHolderDefault unit test stubs"""
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def testTypeHolderDefault(self):
|
||||
"""Test TypeHolderDefault"""
|
||||
# required_vars are set to None now until swagger-parser/swagger-core fixes
|
||||
# https://github.com/swagger-api/swagger-parser/issues/971
|
||||
required_vars = ['number_item', 'integer_item', 'array_item']
|
||||
sample_values = [5.67, 4, [-5, 2, -6]]
|
||||
assigned_variables = {}
|
||||
for index, required_var in enumerate(required_vars):
|
||||
with self.assertRaises(ValueError):
|
||||
model = TypeHolderDefault(**assigned_variables)
|
||||
assigned_variables[required_var] = sample_values[index]
|
||||
# assigned_variables is fully set, all required variables passed in
|
||||
model = TypeHolderDefault(**assigned_variables)
|
||||
self.assertEqual(model.string_item, 'what')
|
||||
self.assertEqual(model.bool_item, True)
|
||||
|
||||
|
||||
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
|
||||
|
||||
OpenAPI spec version: 1.0.0
|
||||
Generated by: https://openapi-generator.tech
|
||||
"""
|
||||
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import unittest
|
||||
|
||||
import petstore_api
|
||||
from petstore_api.models.type_holder_example import TypeHolderExample # noqa: E501
|
||||
from petstore_api.rest import ApiException
|
||||
|
||||
|
||||
class TestTypeHolderExample(unittest.TestCase):
|
||||
"""TypeHolderExample unit test stubs"""
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def testTypeHolderExample(self):
|
||||
"""Test TypeHolderExample"""
|
||||
model = TypeHolderExample()
|
||||
self.assertEqual(model.string_item, 'what')
|
||||
self.assertEqual(model.number_item, 1.234)
|
||||
self.assertEqual(model.integer_item, -2)
|
||||
self.assertEqual(model.bool_item, True)
|
||||
self.assertEqual(model.array_item, [0, 1, 2, 3])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user