Skip to content

Commit

Permalink
CTOOLS-373: extra check that the data types match
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt-Storey-Finbourne committed Oct 4, 2024
1 parent d592101 commit 153a2dd
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions generate/templates/api_test.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,13 @@ class {{#operations}}Test{{classname}}(unittest.IsolatedAsyncioTestCase):
{{^isPrimitiveType}}
{{#content}}
spec_filepath = os.environ['OPENAPI_SPEC_PATH']
print('spec_filepath', spec_filepath)
with open(spec_filepath) as file:
openapiSpecJson = file.read()

method = "{{httpMethod}}".replace("Http", "").lower()
jsonContent = json.loads(openapiSpecJson)
jsonContent = jsonContent["paths"]["{{path}}"][method]["requestBody"]["content"]["application/json"]
{{paramName}}: {{{dataType}}} = None
# {{complexType}}
if "example" in jsonContent:
{{paramName}}: {{dataType}} = jsonContent["example"]
elif "examples" in jsonContent:
Expand All @@ -113,7 +111,9 @@ class {{#operations}}Test{{classname}}(unittest.IsolatedAsyncioTestCase):
else:
break
{{paramName}} = tmp_{{paramName}}

else:
if '{{dataType}}' == '{{complexType}}':
{{paramName}}: {{dataType}} = {{complexType}}.from_dict({{paramName}})
{{/content}}
{{^content}}
{{#isArray}}
Expand All @@ -124,7 +124,6 @@ class {{#operations}}Test{{classname}}(unittest.IsolatedAsyncioTestCase):
{{/isPrimitiveType}}
{{/vendorExtensions.x-regex}}
{{/allParams}}
print()
{{#returnType}}response = {{/returnType}}await self.api.{{operationId}}({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}})
{{#returnType}}
assert(response is not None)
Expand Down

0 comments on commit 153a2dd

Please sign in to comment.