forked from loafle/openapi-generator-original
[python] Renames python generators (#7965)
* python->python-legacy, python-experimental->python * test with openjdk8 * test with openjdk11 * comment out rm * move kotlin tests to circleci * move kotlin tests * move tests to circleci * fix circleci * rearrange test * move tests * use wrapper Co-authored-by: Justin Black <justin.a.black@gmail.com>
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
# coding: utf-8
|
||||
|
||||
"""
|
||||
OpenAPI Extension with dynamic servers
|
||||
|
||||
This specification shows how to use dynamic servers. # noqa: E501
|
||||
|
||||
The version of the OpenAPI document: 1.0.0
|
||||
Generated by: https://openapi-generator.tech
|
||||
"""
|
||||
|
||||
import functools
|
||||
import unittest
|
||||
|
||||
import dynamic_servers
|
||||
from dynamic_servers.api.usage_api import UsageApi # noqa: E501
|
||||
|
||||
|
||||
class TestUsageApi(unittest.TestCase):
|
||||
"""UsageApi unit test stubs"""
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def test_custom_server(self):
|
||||
"""Test case for custom_server
|
||||
|
||||
Use custom server # noqa: E501
|
||||
"""
|
||||
# expected value, config
|
||||
servers = (
|
||||
("https://custom-petstore.swagger.io:8080/v2/custom", {}),
|
||||
(
|
||||
"https://custom-petstore.swagger.io:80/v2/custom",
|
||||
{
|
||||
"server_index": 0,
|
||||
"server_variables": {"port": "80"}, # global override
|
||||
},
|
||||
),
|
||||
(
|
||||
"https://custom-petstore.swagger.io:8080/v2/custom",
|
||||
{
|
||||
"server_index": 0,
|
||||
"server_variables": {"port": "80"},
|
||||
"server_operation_variables": {"custom_server": {"port": "8080"}}, # operation override
|
||||
},
|
||||
),
|
||||
(
|
||||
"https://third.example.com/global-prefix/custom",
|
||||
{
|
||||
"server_index": 2,
|
||||
"server_variables": {"prefix": "global-prefix"}, # global override
|
||||
},
|
||||
),
|
||||
(
|
||||
"https://third.example.com/local-prefix/custom",
|
||||
{
|
||||
"server_index": 1,
|
||||
"server_variables": {"prefix": "global-prefix"},
|
||||
"server_operation_index": {"custom_server": 2},
|
||||
"server_operation_variables": {"custom_server": {"prefix": "local-prefix"}}, # operation override
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
def request(expected_url, method, url, **kwargs):
|
||||
assert expected_url == url
|
||||
raise RuntimeError("pass")
|
||||
|
||||
for expected_url, kwargs in servers:
|
||||
client = dynamic_servers.ApiClient(dynamic_servers.Configuration(**kwargs))
|
||||
client.request = functools.partial(request, expected_url)
|
||||
api = UsageApi(client)
|
||||
|
||||
try:
|
||||
api.custom_server()
|
||||
except RuntimeError as e:
|
||||
assert "pass" == str(e)
|
||||
|
||||
def test_default_server(self):
|
||||
"""Test case for default_server
|
||||
|
||||
Use default server # noqa: E501
|
||||
"""
|
||||
# expected value, config
|
||||
servers = (
|
||||
("http://petstore.swagger.io:80/v2/default", {}),
|
||||
(
|
||||
"http://dev-petstore.swagger.io:8080/v2/default",
|
||||
{
|
||||
"server_index": 0,
|
||||
"server_variables": {"server": "dev-petstore", "port": "8080"},
|
||||
},
|
||||
),
|
||||
("https://localhost:8080/v1/default", {"server_index": 1}),
|
||||
(
|
||||
"https://localhost:8080/v3/default",
|
||||
{"server_index": 1, "server_variables": {"version": "v3"}},
|
||||
),
|
||||
)
|
||||
|
||||
def request(expected_url, method, url, **kwargs):
|
||||
assert expected_url == url
|
||||
raise RuntimeError("pass")
|
||||
|
||||
for expected_url, kwargs in servers:
|
||||
client = dynamic_servers.ApiClient(dynamic_servers.Configuration(**kwargs))
|
||||
client.request = functools.partial(request, expected_url)
|
||||
api = UsageApi(client)
|
||||
|
||||
try:
|
||||
api.default_server()
|
||||
except RuntimeError as e:
|
||||
assert "pass" == str(e)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user