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

Commit 605f380

Browse files
authored
Adds 3.1.0 unit test spec (#238)
* Adds 310 unit test spec * Adds 310 sample generation yaml * Writes v310 spec and sample with some json keywords turned on * Turns on json schema max properties keywords * Turns on min json schema keywords * Adds multipleOf and not json schema test examples * Adds pattern and properties * Adds ref * Adds required * Adds type * Adds uniqueItems * Turns on ci tests for 310 unit test spec * Omits maxItems test because of bug * Removes two failing tests * Excludes failing tests with min/max/Items/Length/Properties with float values * Turns off format validation in tests * Fixes type checking for integers * Fixes integer multipleOf tests * Fixes python tests * Sample regen * Sample regen w/ RequestBody.serialize fix
1 parent 4047724 commit 605f380

File tree

3,507 files changed

+137961
-315
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

3,507 files changed

+137961
-315
lines changed

.circleci/parallel.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ elif [ "$JOB_ID" = "testPythonClientSamples" ]; then
2121
echo "Running job $JOB_ID ..."
2222
(cd samples/client/petstore/python && make test)
2323
(cd samples/client/3_0_3_unit_test/python && make test)
24+
(cd samples/client/3_1_0_unit_test/python && make test)
2425
(cd samples/client/openapi_features/nonCompliantUseDiscriminatorIfCompositionFails/python && make test)
2526
(cd samples/client/openapi_features/security/python && make test)
2627
(cd samples/client/3_1_0_json_schema/python && make test)

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "src/test/resources/JSON-Schema-Test-Suite"]
2+
path = src/test/resources/JSON-Schema-Test-Suite
3+
url = https://github.com/json-schema-org/JSON-Schema-Test-Suite.git
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
generatorName: python
2+
outputDir: samples/client/3_1_0_unit_test/python
3+
inputSpec: src/test/resources/3_1/unit_test_spec/3_1_0_unit_test_spec.yaml
4+
additionalProperties:
5+
packageName: unit_test_api

samples/client/3_0_3_unit_test/python/src/unit_test_api/api_client.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,8 +1213,8 @@ def _get_headers(
12131213
headers.add('Accept', accept_content_type)
12141214
return headers
12151215

1216-
@staticmethod
12171216
def _get_fields_and_body(
1217+
self,
12181218
request_body: typing.Type[RequestBody],
12191219
body: typing.Union[schemas.INPUT_TYPES_ALL, schemas.Unset],
12201220
content_type: str,
@@ -1229,7 +1229,7 @@ def _get_fields_and_body(
12291229

12301230
serialized_fields = None
12311231
serialized_body = None
1232-
serialized_data = request_body.serialize(body, content_type)
1232+
serialized_data = request_body.serialize(body, content_type, configuration=self.api_client.schema_configuration)
12331233
headers.add('Content-Type', content_type)
12341234
if 'fields' in serialized_data:
12351235
serialized_fields = serialized_data['fields']
@@ -1357,7 +1357,7 @@ def __serialize_application_x_www_form_data(
13571357

13581358
@classmethod
13591359
def serialize(
1360-
cls, in_data: schemas.INPUT_TYPES_ALL, content_type: str
1360+
cls, in_data: schemas.INPUT_TYPES_ALL, content_type: str, configuration: typing.Optional[schema_configuration_.SchemaConfiguration] = None
13611361
) -> SerializedRequestBody:
13621362
"""
13631363
If a str is returned then the result will be assigned to data when making the request
@@ -1371,7 +1371,8 @@ def serialize(
13711371
media_type = cls.content[content_type]
13721372
assert media_type.schema is not None
13731373
schema = schemas.get_class(media_type.schema)
1374-
cast_in_data = schema.validate_base(in_data)
1374+
used_configuration = configuration if configuration is not None else schema_configuration_.SchemaConfiguration()
1375+
cast_in_data = schema.validate_base(in_data, configuration=used_configuration)
13751376
# TODO check for and use encoding if it exists
13761377
# and content_type is multipart or application/x-www-form-urlencoded
13771378
if cls._content_type_is_json(content_type):

samples/client/3_0_3_unit_test/python/src/unit_test_api/schemas/validation.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ def _validate(
110110
used_val = (val, prefix_items_length)
111111
elif keyword in {'unevaluated_items', 'unevaluated_properties'}:
112112
used_val = (val, path_to_schemas)
113+
elif keyword in {'types'}:
114+
format: typing.Optional[str] = vars(cls_schema).get('format', None)
115+
used_val = (val, format)
113116
else:
114117
used_val = val
115118
validator = json_schema_keyword_to_validator[keyword]
@@ -257,19 +260,31 @@ class PatternInfo:
257260

258261
def validate_types(
259262
arg: typing.Any,
260-
allowed_types: typing.Set[typing.Type],
263+
allowed_types_format: typing.Tuple[typing.Set[typing.Type], typing.Optional[str]],
261264
cls: typing.Type,
262265
validation_metadata: ValidationMetadata,
263266
) -> None:
267+
allowed_types = allowed_types_format[0]
264268
if type(arg) not in allowed_types:
265269
raise __get_type_error(
266270
arg,
267271
validation_metadata.path_to_item,
268272
allowed_types,
269273
key_type=False,
270274
)
275+
if isinstance(arg, bool) or not isinstance(arg, (int, float)):
276+
return None
277+
format = allowed_types_format[1]
278+
if format and format == 'int' and arg != int(arg):
279+
# there is a json schema test where 1.0 validates as an integer
280+
raise exceptions.ApiValueError(
281+
"Invalid non-integer value '{}' for type {} at {}".format(
282+
arg, format, validation_metadata.path_to_item
283+
)
284+
)
271285
return None
272286

287+
273288
def validate_enum(
274289
arg: typing.Any,
275290
enum_value_to_name: typing.Dict[typing.Any, str],

samples/client/3_0_3_unit_test/python/test/test_paths/test_request_body_post_additionalproperties_allows_a_schema_which_should_validate_request_body/test_post.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ class TestPost(ApiTestMixin, unittest.TestCase):
2323
Post unit test stubs
2424
"""
2525
api_config = api_configuration.ApiConfiguration()
26-
schema_config = schema_configuration.SchemaConfiguration()
26+
schema_config = schema_configuration.SchemaConfiguration(
27+
disabled_json_schema_keywords={'format'}
28+
)
2729
used_api_client = api_client.ApiClient(configuration=api_config, schema_configuration=schema_config)
2830
api = post.ApiForPost(api_client=used_api_client) # noqa: E501
2931

samples/client/3_0_3_unit_test/python/test/test_paths/test_request_body_post_additionalproperties_are_allowed_by_default_request_body/test_post.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ class TestPost(ApiTestMixin, unittest.TestCase):
2323
Post unit test stubs
2424
"""
2525
api_config = api_configuration.ApiConfiguration()
26-
schema_config = schema_configuration.SchemaConfiguration()
26+
schema_config = schema_configuration.SchemaConfiguration(
27+
disabled_json_schema_keywords={'format'}
28+
)
2729
used_api_client = api_client.ApiClient(configuration=api_config, schema_configuration=schema_config)
2830
api = post.ApiForPost(api_client=used_api_client) # noqa: E501
2931

samples/client/3_0_3_unit_test/python/test/test_paths/test_request_body_post_additionalproperties_can_exist_by_itself_request_body/test_post.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ class TestPost(ApiTestMixin, unittest.TestCase):
2323
Post unit test stubs
2424
"""
2525
api_config = api_configuration.ApiConfiguration()
26-
schema_config = schema_configuration.SchemaConfiguration()
26+
schema_config = schema_configuration.SchemaConfiguration(
27+
disabled_json_schema_keywords={'format'}
28+
)
2729
used_api_client = api_client.ApiClient(configuration=api_config, schema_configuration=schema_config)
2830
api = post.ApiForPost(api_client=used_api_client) # noqa: E501
2931

samples/client/3_0_3_unit_test/python/test/test_paths/test_request_body_post_additionalproperties_should_not_look_in_applicators_request_body/test_post.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ class TestPost(ApiTestMixin, unittest.TestCase):
2323
Post unit test stubs
2424
"""
2525
api_config = api_configuration.ApiConfiguration()
26-
schema_config = schema_configuration.SchemaConfiguration()
26+
schema_config = schema_configuration.SchemaConfiguration(
27+
disabled_json_schema_keywords={'format'}
28+
)
2729
used_api_client = api_client.ApiClient(configuration=api_config, schema_configuration=schema_config)
2830
api = post.ApiForPost(api_client=used_api_client) # noqa: E501
2931

samples/client/3_0_3_unit_test/python/test/test_paths/test_request_body_post_allof_combined_with_anyof_oneof_request_body/test_post.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ class TestPost(ApiTestMixin, unittest.TestCase):
2323
Post unit test stubs
2424
"""
2525
api_config = api_configuration.ApiConfiguration()
26-
schema_config = schema_configuration.SchemaConfiguration()
26+
schema_config = schema_configuration.SchemaConfiguration(
27+
disabled_json_schema_keywords={'format'}
28+
)
2729
used_api_client = api_client.ApiClient(configuration=api_config, schema_configuration=schema_config)
2830
api = post.ApiForPost(api_client=used_api_client) # noqa: E501
2931

0 commit comments

Comments
 (0)