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

Commit 293e9a2

Browse files
committed
Adds TestFakeQueryParamWithJsonContentType.test_get
1 parent bd2894c commit 293e9a2

File tree

4 files changed

+83
-25
lines changed

4 files changed

+83
-25
lines changed

samples/openapi3/client/petstore/python/tests_manual/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import collections
12
import json
23
import typing
34
import unittest
@@ -7,6 +8,8 @@
78

89
from petstore_api import api_client
910

11+
ParamTestCase = collections.namedtuple('ParamTestCase', 'payload expected_serialization explode', defaults=[False])
12+
1013

1114
class ApiTestMixin(unittest.TestCase):
1215
json_content_type = 'application/json'

samples/openapi3/client/petstore/python/tests_manual/test_parameters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
from petstore_api import api_client, exceptions, schemas
1515

16-
ParamTestCase = collections.namedtuple('ParamTestCase', 'payload expected_serialization explode', defaults=[False])
16+
from . import ParamTestCase
1717

1818

1919
class TestParameter(unittest.TestCase):

samples/openapi3/client/petstore/python/tests_manual/test_paths/test_fake_query_param_with_json_content_type/test_get.py

Lines changed: 78 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
Generated by: https://openapi-generator.tech
77
"""
88

9+
import collections
910
import unittest
1011
from unittest.mock import patch
1112

@@ -15,26 +16,90 @@
1516
from petstore_api.paths.fake_query_param_with_json_content_type import get # noqa: E501
1617
from petstore_api import configuration, schemas, api_client
1718

18-
from .. import ApiTestMixin
19+
from ... import ApiTestMixin, ParamTestCase
1920

2021

2122
class TestFakeQueryParamWithJsonContentType(ApiTestMixin, unittest.TestCase):
2223
"""
2324
FakeQueryParamWithJsonContentType unit test stubs
2425
query param with json content-type # noqa: E501
2526
"""
26-
_configuration = configuration.Configuration()
27-
28-
def setUp(self):
29-
used_api_client = api_client.ApiClient(configuration=self._configuration)
30-
self.api = get.ApiForget(api_client=used_api_client) # noqa: E501
31-
32-
def tearDown(self):
33-
pass
34-
35-
response_status = 200
36-
37-
27+
@patch.object(urllib3.PoolManager, 'request')
28+
def test_get(self, mock_request):
29+
used_api_client = api_client.ApiClient()
30+
api = get.ApiForget(api_client=used_api_client)
31+
32+
response_json = {}
33+
body = self.json_bytes(response_json)
34+
mock_request.return_value = self.response(body)
35+
36+
test_cases = (
37+
ParamTestCase(
38+
None,
39+
'null'
40+
),
41+
ParamTestCase(
42+
1,
43+
'1'
44+
),
45+
ParamTestCase(
46+
3.14,
47+
'3.14'
48+
),
49+
ParamTestCase(
50+
'blue',
51+
'%22blue%22'
52+
),
53+
ParamTestCase(
54+
'hello world',
55+
'%22hello%20world%22'
56+
),
57+
ParamTestCase(
58+
'',
59+
'%22%22'
60+
),
61+
ParamTestCase(
62+
True,
63+
'true'
64+
),
65+
ParamTestCase(
66+
False,
67+
'false'
68+
),
69+
ParamTestCase(
70+
[],
71+
'%5B%5D'
72+
),
73+
ParamTestCase(
74+
['blue', 'black', 'brown'],
75+
'%5B%22blue%22%2C%22black%22%2C%22brown%22%5D'
76+
),
77+
ParamTestCase(
78+
{},
79+
'%7B%7D'
80+
),
81+
ParamTestCase(
82+
dict(R=100, G=200, B=150),
83+
'%7B%22R%22%3A100%2C%22G%22%3A200%2C%22B%22%3A150%7D'
84+
),
85+
)
86+
87+
for test_case in test_cases:
88+
api_response = api.get(query_params={'someParam': test_case.payload})
89+
self.assert_pool_manager_request_called_with(
90+
mock_request,
91+
f'http://petstore.swagger.io:80/v2/fake/queryParamWithJsonContentType?someParam={test_case.expected_serialization}',
92+
body=None,
93+
method='GET',
94+
content_type=None,
95+
accept_content_type='application/json',
96+
)
97+
98+
assert isinstance(api_response.response, urllib3.HTTPResponse)
99+
assert isinstance(api_response.body, schemas.AnyTypeSchema)
100+
assert isinstance(api_response.body, schemas.frozendict.frozendict)
101+
assert isinstance(api_response.headers, schemas.Unset)
102+
assert api_response.response.status == 200
38103

39104

40105
if __name__ == '__main__':

samples/openapi3/client/petstore/python/tests_manual/test_paths/test_pet_pet_id/test_get.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class TestPetPetId(ApiTestMixin, unittest.TestCase):
2727
def test_get(self):
2828
config_with_auth = configuration.Configuration(api_key={'api_key': 'someKey'})
2929
used_api_client = api_client.ApiClient(configuration=config_with_auth)
30-
api = get.ApiForget(api_client=used_api_client) # noqa: E501
30+
api = get.ApiForget(api_client=used_api_client)
3131

3232
with patch.object(urllib3.PoolManager, 'request') as mock_request:
3333
response_json = {
@@ -61,15 +61,5 @@ def test_get(self):
6161
assert api_response.response.status == 200
6262

6363

64-
65-
66-
67-
response_status = 200
68-
69-
70-
71-
72-
73-
7464
if __name__ == '__main__':
7565
unittest.main()

0 commit comments

Comments
 (0)