Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Commit 5ab099d

Browse files
committed
Fixes more python tests
1 parent 1d437df commit 5ab099d

13 files changed

+39
-195
lines changed

samples/openapi3/client/petstore/python/tests_manual/test_array_holding_any_type.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ def testArrayHoldingAnyType(self):
3333

3434
enum_values = [True, False]
3535
for enum_value in enum_values:
36-
inst = ArrayHoldingAnyType([enum_value])
36+
inst = ArrayHoldingAnyType.validate([enum_value])
3737
assert isinstance(inst, ArrayHoldingAnyType)
3838
assert isinstance(inst, tuple)
3939
assert isinstance(inst[0], BoolClass)
4040
assert bool(inst[0]) is enum_value
4141

42-
inst = ArrayHoldingAnyType([None])
42+
inst = ArrayHoldingAnyType.validate([None])
4343
assert isinstance(inst, ArrayHoldingAnyType)
4444
assert isinstance(inst, tuple)
4545
assert isinstance(inst[0], NoneClass)
@@ -55,7 +55,7 @@ def testArrayHoldingAnyType(self):
5555
('hi', 'hi'),
5656
]
5757
for input, stored_value in input_to_stored_value:
58-
inst = ArrayHoldingAnyType([input])
58+
inst = ArrayHoldingAnyType.validate([input])
5959
assert isinstance(inst, ArrayHoldingAnyType)
6060
assert isinstance(inst, tuple)
6161
assert inst[0] == stored_value

samples/openapi3/client/petstore/python/tests_manual/test_array_with_validations_in_items.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,21 @@ def testArrayWithValidationsInItems(self):
3232

3333
valid_values = [-1, 5, 7]
3434
for valid_value in valid_values:
35-
inst = ArrayWithValidationsInItems([valid_value])
35+
inst = ArrayWithValidationsInItems.validate([valid_value])
3636
assert isinstance(inst, ArrayWithValidationsInItems)
3737
assert inst == (valid_value,)
3838

3939
with self.assertRaisesRegex(
4040
exceptions.ApiValueError,
4141
r"Invalid value `8`, must be a value less than or equal to `7` at \('args\[0\]', 0\)"
4242
):
43-
ArrayWithValidationsInItems([8])
43+
ArrayWithValidationsInItems.validate([8])
4444

4545
with self.assertRaisesRegex(
4646
exceptions.ApiValueError,
4747
r"Invalid value `\(Decimal\('1'\), Decimal\('2'\), Decimal\('3'\)\)`, number of items must be less than or equal to `2` at \('args\[0\]',\)"
4848
):
49-
ArrayWithValidationsInItems([1, 2, 3])
49+
ArrayWithValidationsInItems.validate([1, 2, 3])
5050

5151

5252
if __name__ == '__main__':

samples/openapi3/client/petstore/python/tests_manual/test_boolean_enum.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ def tearDown(self):
2727

2828
def test_BooleanEnum(self):
2929
"""Test BooleanEnum"""
30-
model = BooleanEnum(True)
30+
model = BooleanEnum.validate(True)
3131
assert model is BooleanEnum.TRUE
3232
assert model.is_true_()
3333
assert model.is_false_() is False
3434
assert repr(model) == '<DynamicSchema: True>'
3535
with self.assertRaises(petstore_api.ApiValueError):
36-
BooleanEnum(False)
36+
BooleanEnum.validate(False)
3737

3838

3939
if __name__ == '__main__':

samples/openapi3/client/petstore/python/tests_manual/test_combine_object_schemas.py

-152
This file was deleted.

samples/openapi3/client/petstore/python/tests_manual/test_combine_schemas.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ class EnumPlusPrim(IntegerEnumOneValue, IntegerMax10):
4141

4242
# invalid value throws an exception
4343
with self.assertRaises(petstore_api.ApiValueError):
44-
EnumPlusPrim(9)
44+
EnumPlusPrim.validate(9)
4545

4646
# valid value succeeds
47-
val = EnumPlusPrim(0)
47+
val = EnumPlusPrim.validate(0)
4848
assert val == 0
4949
assert isinstance(val, EnumPlusPrim)
5050
assert isinstance(val, Singleton)

samples/openapi3/client/petstore/python/tests_manual/test_composed_bool.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test_ComposedBool(self):
3030
all_values = [None, True, False, 2, 3.14, '', {}, []]
3131
for value in all_values:
3232
if isinstance(value, bool):
33-
model = ComposedBool(value)
33+
model = ComposedBool.validate(value)
3434
if value is True:
3535
self.assertTrue(bool(model))
3636
self.assertTrue(model.is_true_())
@@ -41,7 +41,7 @@ def test_ComposedBool(self):
4141
self.assertFalse(bool(model))
4242
continue
4343
with self.assertRaises(petstore_api.ApiTypeError):
44-
ComposedBool(value)
44+
ComposedBool.validate(value)
4545
continue
4646

4747

samples/openapi3/client/petstore/python/tests_manual/test_composed_none.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ def test_ComposedNone(self):
3333
for value in all_values:
3434
if value not in valid_values:
3535
with self.assertRaises(petstore_api.ApiTypeError):
36-
model = ComposedNone(value)
36+
ComposedNone.validate(value)
3737
continue
38-
model = ComposedNone(value)
38+
ComposedNone.validate(value)
3939

4040

4141
if __name__ == '__main__':

samples/openapi3/client/petstore/python/tests_manual/test_composed_number.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"""
1111

1212

13-
import sys
1413
import unittest
1514

1615
import petstore_api
@@ -33,9 +32,9 @@ def test_ComposedNumber(self):
3332
for value in all_values:
3433
if value not in valid_values:
3534
with self.assertRaises(petstore_api.ApiTypeError):
36-
model = ComposedNumber(value)
35+
ComposedNumber.validate(value)
3736
continue
38-
model = ComposedNumber(value)
37+
ComposedNumber.validate(value)
3938

4039

4140
if __name__ == '__main__':

samples/openapi3/client/petstore/python/tests_manual/test_composed_object.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,13 @@ def tearDown(self):
2828

2929
def test_ComposedObject(self):
3030
"""Test ComposedObject"""
31-
valid_values = [{}]
32-
all_values = [None, True, False, 2, 3.14, '', {}, []]
31+
all_values = (None, True, False, 2, 3.14, '', {}, [])
3332
for value in all_values:
34-
if value not in valid_values:
33+
if not isinstance(value, dict):
3534
with self.assertRaises(petstore_api.ApiTypeError):
36-
model = ComposedObject(value)
35+
ComposedObject.validate(value)
3736
continue
38-
model = ComposedObject(value)
37+
ComposedObject(value)
3938

4039

4140
if __name__ == '__main__':

samples/openapi3/client/petstore/python/tests_manual/test_composed_one_of_different_types.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -34,32 +34,32 @@ def tearDown(self):
3434
def test_ComposedOneOfDifferentTypes(self):
3535
"""Test ComposedOneOfDifferentTypes"""
3636
# we can make an instance that stores float data
37-
inst = ComposedOneOfDifferentTypes(10.0)
37+
inst = ComposedOneOfDifferentTypes.validate(10.0)
3838
assert isinstance(inst, NumberWithValidations)
3939

4040
# we can make an instance that stores object (dict) data
41-
inst = ComposedOneOfDifferentTypes({'className': "Cat", 'color': "black"})
41+
inst = ComposedOneOfDifferentTypes.validate({'className': "Cat", 'color': "black"})
4242
assert isinstance(inst, ComposedOneOfDifferentTypes)
4343
assert isinstance(inst, Animal)
4444
assert isinstance(inst, Cat)
4545
assert isinstance(inst, frozendict.frozendict)
4646

4747
# object that holds 4 properties and is not an Animal
48-
inst = ComposedOneOfDifferentTypes({'a': "a", 'b': "b", 'c': "c", 'd': "d"})
48+
inst = ComposedOneOfDifferentTypes.validate({'a': "a", 'b': "b", 'c': "c", 'd': "d"})
4949
assert isinstance(inst, ComposedOneOfDifferentTypes)
5050
assert not isinstance(inst, Animal)
5151
assert isinstance(inst, frozendict.frozendict)
5252

5353
# None
54-
inst = ComposedOneOfDifferentTypes(None)
54+
inst = ComposedOneOfDifferentTypes.validate(None)
5555
inst.is_none_()
5656
assert isinstance(inst, ComposedOneOfDifferentTypes)
5757
assert isinstance(inst, Singleton)
5858
assert isinstance(inst, NoneClass)
5959
assert inst.is_none_() is True
6060

6161
# date
62-
inst = ComposedOneOfDifferentTypes('2019-01-10')
62+
inst = ComposedOneOfDifferentTypes.validate('2019-01-10')
6363
assert isinstance(inst, ComposedOneOfDifferentTypes)
6464
assert isinstance(inst, DateSchema)
6565
assert isinstance(inst, str)
@@ -68,7 +68,7 @@ def test_ComposedOneOfDifferentTypes(self):
6868
assert inst.as_date_.day == 10
6969

7070
# date
71-
inst = ComposedOneOfDifferentTypes(date(2019, 1, 10))
71+
inst = ComposedOneOfDifferentTypes.validate(date(2019, 1, 10))
7272
assert isinstance(inst, ComposedOneOfDifferentTypes)
7373
assert isinstance(inst, DateSchema)
7474
assert isinstance(inst, str)
@@ -77,7 +77,7 @@ def test_ComposedOneOfDifferentTypes(self):
7777
assert inst.as_date_.day == 10
7878

7979
# date-time
80-
inst = ComposedOneOfDifferentTypes('2020-01-02T03:04:05Z')
80+
inst = ComposedOneOfDifferentTypes.validate('2020-01-02T03:04:05Z')
8181
assert isinstance(inst, ComposedOneOfDifferentTypes)
8282
assert isinstance(inst, DateTimeSchema)
8383
assert isinstance(inst, str)
@@ -91,7 +91,7 @@ def test_ComposedOneOfDifferentTypes(self):
9191
assert inst.as_datetime_.tzinfo == utc_tz
9292

9393
# date-time
94-
inst = ComposedOneOfDifferentTypes(datetime(2020, 1, 2, 3, 4, 5, tzinfo=timezone.utc))
94+
inst = ComposedOneOfDifferentTypes.validate(datetime(2020, 1, 2, 3, 4, 5, tzinfo=timezone.utc))
9595
assert isinstance(inst, ComposedOneOfDifferentTypes)
9696
assert isinstance(inst, DateTimeSchema)
9797
assert isinstance(inst, str)

samples/openapi3/client/petstore/python/tests_manual/test_composed_string.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
Generated by: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator
1010
"""
1111

12-
13-
import sys
1412
import unittest
1513

1614
import petstore_api
@@ -33,9 +31,9 @@ def test_ComposedString(self):
3331
for value in all_values:
3432
if value not in valid_values:
3533
with self.assertRaises(petstore_api.ApiTypeError):
36-
model = ComposedString(value)
34+
ComposedString.validate(value)
3735
continue
38-
model = ComposedString(value)
36+
ComposedString.validate(value)
3937

4038

4139
if __name__ == '__main__':

0 commit comments

Comments
 (0)