Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 3 additions & 6 deletions pynetbox/lib/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ def url_param_builder(param_dict):
Creates URL paramters (e.g. '.../?xyz=r21&abc=123') from a dict
passed in param_dict
'''
param_list = []
for key, val in param_dict.items():
param_list.append('{}={}'.format(key, val))
return '?{}'.format('&'.join(param_list))
return '?{}'.format(urlencode(param_dict))


class RequestError(Exception):
Expand Down Expand Up @@ -150,9 +147,9 @@ def construct_url(input):
for k, v in input.items():
if isinstance(v, list):
for i in v:
yield "{}={}".format(k, i)
yield urlencode({k: i})
else:
yield "{}={}".format(k, v)
yield urlencode({k: v})

if self.key:
return '{}/{key}/'.format(
Expand Down
4 changes: 2 additions & 2 deletions tests/test_dcim.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,12 @@ def test_get(self, mock):
return_value=Response(fixture='dcim/devices.json')
)
def test_multi_filter(self, mock):
ret = getattr(nb, self.name).filter(role=['test', 'test1'], site='TEST1')
ret = getattr(nb, self.name).filter(role=['test', 'test1'], site='TEST#1')
self.assertTrue(ret)
self.assertTrue(isinstance(ret, list))
self.assertTrue(isinstance(ret[0], self.ret))
mock.assert_called_with(
'http://localhost:8000/api/{}/{}/?role=test&role=test1&site=TEST1'.format(
'http://localhost:8000/api/{}/{}/?role=test&role=test1&site=TEST%231'.format(
self.app,
self.name.replace('_', '-')
),
Expand Down
3 changes: 2 additions & 1 deletion tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ def test_url_param_builder(self):
test_params = OrderedDict([
('abc', '123'),
('xyz', '321'),
('enc', '#12'),
])
self.assertEqual(url_param_builder(test_params), '?abc=123&xyz=321')
self.assertEqual(url_param_builder(test_params), '?abc=123&xyz=321&enc=%2312')