Skip to content

Commit

Permalink
Merge pull request #53 from mchrobak/urlencoding
Browse files Browse the repository at this point in the history
fix some urlencoding problems
  • Loading branch information
Zach Moody authored Apr 26, 2018
2 parents 07b71c2 + 3946543 commit f670997
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
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')

0 comments on commit f670997

Please sign in to comment.