Skip to content

Commit

Permalink
fix fields handling
Browse files Browse the repository at this point in the history
  • Loading branch information
DanCech committed Nov 30, 2017
1 parent 5a58e4f commit 019bcf1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
12 changes: 11 additions & 1 deletion webapp/graphite/tags/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,20 @@ def request(self, method, url, fields, requestContext=None):
if 'Authorization' not in headers and self.username and self.password:
headers['Authorization'] = 'Basic ' + ('%s:%s' % (self.username, self.password)).encode('base64')

req_fields = []
for (field, value) in fields.items():
if value is None:
continue

if isinstance(value, list) or isinstance(value, tuple):
req_fields.extend([(field, v) for v in value if v is not None])
else:
req_fields.append((field, value))

result = http.request(
method,
self.base_url + url,
fields={field: value for (field, value) in fields.items() if value is not None},
fields=req_fields,
headers=headers,
timeout=self.settings.REMOTE_FIND_TIMEOUT,
)
Expand Down
11 changes: 9 additions & 2 deletions webapp/tests/test_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,17 @@ def mockRequest(method, url, fields=None, headers=None, timeout=None):
else:
self.assertEqual(headers, {})

req_fields = {}
for (field, value) in fields:
if field in req_fields:
req_fields[field].append(value)
else:
req_fields[field] = [value]

if method == 'POST':
result = self.client.post(url, fields)
result = self.client.post(url, req_fields)
elif method == 'GET':
result = self.client.get(url, fields)
result = self.client.get(url, req_fields)
else:
raise Exception('Invalid HTTP method %s' % method)

Expand Down

0 comments on commit 019bcf1

Please sign in to comment.