mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 19:46:46 +00:00
Fix APICallMixin url_args handling (#6468)
This commit is contained in:
parent
824aa8138b
commit
b372db8960
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import json as json_pkg
|
import json as json_pkg
|
||||||
import logging
|
import logging
|
||||||
|
from collections.abc import Iterable
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
@ -107,7 +108,9 @@ class APICallMixin:
|
|||||||
"""Returns an encoded path for the provided dict."""
|
"""Returns an encoded path for the provided dict."""
|
||||||
groups = []
|
groups = []
|
||||||
for key, val in arguments.items():
|
for key, val in arguments.items():
|
||||||
groups.append(f'{key}={",".join([str(a) for a in val])}')
|
if isinstance(val, Iterable) and not isinstance(val, str):
|
||||||
|
val = ','.join([str(a) for a in val])
|
||||||
|
groups.append(f'{key}={val}')
|
||||||
return f'?{"&".join(groups)}'
|
return f'?{"&".join(groups)}'
|
||||||
|
|
||||||
def api_call(
|
def api_call(
|
||||||
|
@ -263,14 +263,17 @@ class APICallMixinTest(BaseMixinDefinition, TestCase):
|
|||||||
"""Test that building up args work."""
|
"""Test that building up args work."""
|
||||||
# api_build_url_args
|
# api_build_url_args
|
||||||
# 1 arg
|
# 1 arg
|
||||||
result = self.mixin.api_build_url_args({'a': 'b'})
|
result = self.mixin.api_build_url_args({'a': 'abc123'})
|
||||||
self.assertEqual(result, '?a=b')
|
self.assertEqual(result, '?a=abc123')
|
||||||
|
# non string arg
|
||||||
|
result = self.mixin.api_build_url_args({'a': 1})
|
||||||
|
self.assertEqual(result, '?a=1')
|
||||||
# more args
|
# more args
|
||||||
result = self.mixin.api_build_url_args({'a': 'b', 'c': 'd'})
|
result = self.mixin.api_build_url_args({'a': 'b', 'c': 42})
|
||||||
self.assertEqual(result, '?a=b&c=d')
|
self.assertEqual(result, '?a=b&c=42')
|
||||||
# list args
|
# list args
|
||||||
result = self.mixin.api_build_url_args({'a': 'b', 'c': ['d', 'e', 'f']})
|
result = self.mixin.api_build_url_args({'a': 'b', 'c': ['d', 'efgh', 1337]})
|
||||||
self.assertEqual(result, '?a=b&c=d,e,f')
|
self.assertEqual(result, '?a=b&c=d,efgh,1337')
|
||||||
|
|
||||||
def test_api_call(self):
|
def test_api_call(self):
|
||||||
"""Test that api calls work."""
|
"""Test that api calls work."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user