Quote query string when POST is used

Change-Id: I9f2a3aeef715f168de1ac215f87f19b43c7c7e95
This commit is contained in:
Mehdi Abaakouk 2016-02-10 15:11:50 +01:00
parent d7b8965e80
commit 21c54eda21
3 changed files with 14 additions and 2 deletions

View File

@ -210,7 +210,7 @@ class MetricClientTest(base.ClientTestBase):
# MEASURES AGGREGATION
result = self.gnocchi(
'measures', params=("--debug aggregation "
'measures', params=("aggregation "
"--query \"id='metric-res'\" "
"--resource-type \"generic\" "
"-m metric-name "

View File

@ -85,3 +85,14 @@ class SearchQueryBuilderTest(base.BaseTestCase):
]},
{"=": {"foo": "quote"}},
]})
def test_dict_to_querystring(self):
expected = ["start=2016-02-10T13%3A54%3A53%2B00%3A00"
"&stop=2016-02-10T13%3A56%3A42%2B02%3A00",
"stop=2016-02-10T13%3A56%3A42%2B02%3A00"
"&start=2016-02-10T13%3A54%3A53%2B00%3A00"]
self.assertIn(utils.dict_to_querystring(
{"start": "2016-02-10T13:54:53+00:00",
"stop": "2016-02-10T13:56:42+02:00"}),
expected)

View File

@ -16,6 +16,7 @@ import uuid
import pyparsing as pp
import six
from six.moves.urllib import parse as urllib_parse
uninary_operators = ("not", )
binary_operator = (u">=", u"<=", u"!=", u">", u"<", u"=", u"==", u"eq", u"ne",
@ -146,7 +147,7 @@ def dict_from_parsed_args(parsed_args, attrs):
def dict_to_querystring(objs):
return "&".join(["%s=%s" % (k, v)
return "&".join(["%s=%s" % (k, urllib_parse.quote(six.text_type(v)))
for k, v in objs.items()
if v is not None])