Skip to content

Commit

Permalink
test: Add Python test [TSI-2118]
Browse files Browse the repository at this point in the history
  • Loading branch information
jablan committed Oct 12, 2023
1 parent 49c6857 commit 532fb01
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions openapi-generator/templates/python/model_test.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@

{{>partial_header}}

from __future__ import absolute_import

import unittest
import datetime

{{#models}}
{{#model}}
import {{packageName}}
from {{modelPackage}}.{{classFilename}} import {{classname}} # noqa: E501
from {{packageName}}.rest import ApiException

class Test{{classname}}(unittest.TestCase):
"""{{classname}} unit test stubs"""
Expand All @@ -21,33 +17,42 @@ class Test{{classname}}(unittest.TestCase):

def tearDown(self):
pass
{{^isEnum}}

def make_instance(self, include_optional):
def make_instance(self, include_optional) -> {{classname}}:
"""Test {{classname}}
include_option is a boolean, when False only required
params are included, when True both required and
optional params are included """
# model = {{packageName}}.models.{{classFilename}}.{{classname}}() # noqa: E501
if include_optional :
# uncomment below to create an instance of `{{{classname}}}`
"""
model = {{classname}}() # noqa: E501
if include_optional:
return {{classname}}(
{{#vars}}
{{name}} = {{#example}}{{{.}}}{{/example}}{{^example}}None{{/example}}{{#hasMore}}, {{/hasMore}}
{{/vars}}
{{#vars}}
{{name}} = {{{example}}}{{^example}}None{{/example}}{{^-last}},{{/-last}}
{{/vars}}
)
else :
else:
return {{classname}}(
{{#vars}}
{{#required}}
{{name}} = {{#example}}{{{.}}}{{/example}}{{^example}}None{{/example}},
{{/required}}
{{/vars}}
{{#vars}}
{{#required}}
{{name}} = {{{example}}}{{^example}}None{{/example}},
{{/required}}
{{/vars}}
)
"""
{{/isEnum}}

def test{{classname}}(self):
"""Test {{classname}}"""
inst_req_only = self.make_instance(include_optional=False)
inst_req_and_optional = self.make_instance(include_optional=True)

{{^isEnum}}
# inst_req_only = self.make_instance(include_optional=False)
# inst_req_and_optional = self.make_instance(include_optional=True)
{{/isEnum}}
{{#isEnum}}
# inst = {{{classname}}}()
{{/isEnum}}
{{/model}}
{{/models}}

Expand Down

0 comments on commit 532fb01

Please sign in to comment.