[python-nextgen] support dict query params (#14727)

* [python-nextgen] convert dictionary query params to string

* [python-nextgen] regenerated samples

* [python-nextgen] added some test cases for parameters_to_url_query

* [python-nextgen] use json.dumps instead of str(v)

* [python-nextgen] update api_client tests
This commit is contained in:
Emma
2023-02-25 09:25:52 -05:00
committed by GitHub
parent 92b96635bd
commit 1f2d6b8848
5 changed files with 55 additions and 0 deletions

View File

@@ -549,6 +549,8 @@ class ApiClient(object):
v = str(v)
if isinstance(v, bool):
v = str(v).lower()
if isinstance(v, dict):
v = json.dumps(v)
if k in collection_formats:
collection_format = collection_formats[k]

View File

@@ -526,6 +526,8 @@ class ApiClient(object):
v = str(v)
if isinstance(v, bool):
v = str(v).lower()
if isinstance(v, dict):
v = json.dumps(v)
if k in collection_formats:
collection_format = collection_formats[k]

View File

@@ -526,6 +526,8 @@ class ApiClient(object):
v = str(v)
if isinstance(v, bool):
v = str(v).lower()
if isinstance(v, dict):
v = json.dumps(v)
if k in collection_formats:
collection_format = collection_formats[k]

View File

@@ -525,6 +525,8 @@ class ApiClient(object):
v = str(v)
if isinstance(v, bool):
v = str(v).lower()
if isinstance(v, dict):
v = json.dumps(v)
if k in collection_formats:
collection_format = collection_formats[k]

View File

@@ -212,3 +212,50 @@ class ApiClientTests(unittest.TestCase):
self.assertIsNotNone(client._pool)
atexit._run_exitfuncs()
self.assertIsNone(client._pool)
def test_parameters_to_url_query(self):
data = 'value={"category": "example", "category2": "example2"}'
dictionary = {
"category": "example",
"category2": "example2"
}
result = self.api_client.parameters_to_url_query([('value', dictionary)], {})
self.assertEqual(result, data)
data='value={"number": 1, "string": "str", "bool": true, "dict": {"number": 1, "string": "str", "bool": true}}'
dictionary = {
"number": 1,
"string": "str",
"bool": True,
"dict": {
"number": 1,
"string": "str",
"bool": True
}
}
result = self.api_client.parameters_to_url_query([('value', dictionary)], {})
self.assertEqual(result, data)
data='value={"strValues": ["one", "two", "three"], "dictValues": [{"name": "value1", "age": 14}, {"name": "value2", "age": 12}]}'
dictionary = {
"strValues": [
"one",
"two",
"three"
],
"dictValues": [
{
"name": "value1",
"age": 14
},
{
"name": "value2",
"age": 12
},
]
}
result = self.api_client.parameters_to_url_query([('value', dictionary)], {})
self.assertEqual(result, data)