Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
minor fixes, add tests
  • Loading branch information
wing328 committed Jan 23, 2019
commit fc59ad9e9d58ff6de44a844f965d71b3ade202fb
Original file line number Diff line number Diff line change
Expand Up @@ -294,20 +294,20 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)):

# check array index out of bound
if index < 0 or index > len(servers):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the second expression should be >=

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Just pushed out a fix.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI. I'm also reviewing other clients and filing a fix accordingly if the same issue is found.

raise ValueError("Invalid index %i when selecting the host settings. Must be less than %i" % index % len(servers)) # noqa: E501
raise ValueError("Invalid index {} when selecting the host settings. Must be less than {}".format(index, len(servers))) # noqa: E501

server = servers[index]
url = server['url']

# go through variable and assign a value
for variable_name in server['variables']:
if variable_name in variables:
if variables[variable_name] in variables[variable_name]['enum_values']:
if variables[variable_name] in server['variables'][variable_name]['enum_values']:
url = url.replace("{" + variable_name + "}", variables[variable_name])
else:
raise ValueError("The variable `%s` in the host URL has invalid value %s. Must be %s." % variable_name % variables[variable_name] % variables[variable_name]['enum_values']) # noqa: E501
raise ValueError("The variable `{}` in the host URL has invalid value {}. Must be {}.".format(variable_name, variables[variable_name], server['variables'][variable_name]['enum_values'])) # noqa: E501
else:
# use default value
url = url.replace("{" + variable_name + "}", variables[variable_name]['default_value']) # noqa: E501
url = url.replace("{" + variable_name + "}", server['variables'][variable_name]['default_value']) # noqa: E501

return url
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,7 @@
<module>samples/client/petstore/javascript-promise</module>
<module>samples/client/petstore/javascript-promise-es6</module>
<module>samples/client/petstore/javascript-flowtyped</module>
<module>samples/openapi3/client/petstore/python</module>
<module>samples/client/petstore/python</module>
<module>samples/client/petstore/python-tornado</module>
<module>samples/client/petstore/python-asyncio</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,20 +315,20 @@ def get_host_from_settings(self, index, variables={}):

# check array index out of bound
if index < 0 or index > len(servers):
raise ValueError("Invalid index %i when selecting the host settings. Must be less than %i" % index % len(servers)) # noqa: E501
raise ValueError("Invalid index {} when selecting the host settings. Must be less than {}".format(index, len(servers))) # noqa: E501

server = servers[index]
url = server['url']

# go through variable and assign a value
for variable_name in server['variables']:
if variable_name in variables:
if variables[variable_name] in variables[variable_name]['enum_values']:
if variables[variable_name] in server['variables'][variable_name]['enum_values']:
url = url.replace("{" + variable_name + "}", variables[variable_name])
else:
raise ValueError("The variable `%s` in the host URL has invalid value %s. Must be %s." % variable_name % variables[variable_name] % variables[variable_name]['enum_values']) # noqa: E501
raise ValueError("The variable `{}` in the host URL has invalid value {}. Must be {}.".format(variable_name, variables[variable_name], server['variables'][variable_name]['enum_values'])) # noqa: E501
else:
# use default value
url = url.replace("{" + variable_name + "}", variables[variable_name]['default_value']) # noqa: E501
url = url.replace("{" + variable_name + "}", server['variables'][variable_name]['default_value']) # noqa: E501

return url
43 changes: 43 additions & 0 deletions samples/openapi3/client/petstore/python/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.openapitools</groupId>
<artifactId>PythonOASv3PetstoreTests</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>Python OpenAPI3 Petstore Client</name>
<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>nose-test</id>
<phase>integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>tox</executable>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
54 changes: 54 additions & 0 deletions samples/openapi3/client/petstore/python/test/test_configuration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# 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 import Configuration # noqa: E501
from petstore_api.rest import ApiException


class TestConfiguration(unittest.TestCase):
"""Confgiruation unit test stubs"""

def setUp(self):
self.config= Configuration()

def tearDown(self):
pass

def test_configuration(self):
"""Test configuration

Test host settings # noqa: E501
"""
host_settings = self.config.get_host_settings()

self.assertEqual('http://{server}.swagger.io:{port}/v2', host_settings[0]['url'])
self.assertEqual('petstore', host_settings[0]['variables']['server']['default_value'])

self.assertEqual('https://localhost:8080/{version}', host_settings[1]['url'])
self.assertEqual('v2', host_settings[1]['variables']['version']['default_value'])

def test_get_host_from_settings(self):
""" Test get_host_from_settings

Test get URL from host settings
"""
self.assertEqual("http://petstore.swagger.io:80/v2", self.config.get_host_from_settings(0))
self.assertEqual("http://petstore.swagger.io:8080/v2", self.config.get_host_from_settings(0, {'port': '8080'}))
self.assertEqual("http://dev-petstore.swagger.io:8080/v2", self.config.get_host_from_settings(0, {'server': 'dev-petstore', 'port': '8080'}))

if __name__ == '__main__':
unittest.main()