diff options
author | utkarshrai98 <utkarshrai98@gmail.com> | 2017-09-17 10:06:50 +0530 |
---|---|---|
committer | Utkarsh Rai <utkarshrai98@gmail.com> | 2017-09-18 06:45:40 +0000 |
commit | 532e0c4a6f77c65634b09ba311fe32464372c84e (patch) | |
tree | eaafac59bc6e1b0b0764313f05e3bcdc575ab9c2 | |
parent | 1fc5d49f8aa9eb44e615afdd597827be48cf517a (diff) |
Bug Fix: Using library for urlencode
Changes to method call _set_query
Change-Id: I95837df57cc98c21ff5d95d9753269490c025dd3
Signed-off-by: utkarshrai98 <utkarshrai98@gmail.com>
-rw-r--r-- | utils/test/testapi/opnfv_testapi/tests/unit/resources/test_result.py | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_result.py b/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_result.py index f5026c957..1df31f36c 100644 --- a/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_result.py +++ b/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_result.py @@ -11,6 +11,7 @@ from datetime import datetime from datetime import timedelta import httplib import json +import urllib import unittest from opnfv_testapi.common import message @@ -268,29 +269,29 @@ class TestResultGet(TestResultBase): @executor.query(httplib.BAD_REQUEST, message.must_int('period')) def test_queryPeriodNotInt(self): - return self._set_query('period=a') + return self._set_query(period='a') @executor.query(httplib.OK, '_query_period_one', 1) def test_queryPeriodSuccess(self): - return self._set_query('period=5') + return self._set_query(period=5) @executor.query(httplib.BAD_REQUEST, message.must_int('last')) def test_queryLastNotInt(self): - return self._set_query('last=a') + return self._set_query(last='a') @executor.query(httplib.OK, '_query_last_one', 1) def test_queryLast(self): - return self._set_query('last=1') + return self._set_query(last=1) @executor.query(httplib.OK, '_query_success', 4) def test_queryPublic(self): self._create_public_data() - return self._set_query('') + return self._set_query() @executor.query(httplib.OK, '_query_success', 1) def test_queryPrivate(self): self._create_private_data() - return self._set_query('public=false') + return self._set_query(public='false') @executor.query(httplib.OK, '_query_period_one', 1) def test_combination(self): @@ -303,12 +304,11 @@ class TestResultGet(TestResultBase): 'scenario', 'trust_indicator', 'criteria', - 'period=5') + period=5) @executor.query(httplib.OK, '_query_success', 0) def test_notFound(self): - return self._set_query('pod=notExistPod', - 'project', + return self._set_query('project', 'case', 'version', 'installer', @@ -316,7 +316,8 @@ class TestResultGet(TestResultBase): 'scenario', 'trust_indicator', 'criteria', - 'period=1') + pod='notExistPod', + period=1) @executor.query(httplib.OK, '_query_success', 1) def test_filterErrorStartdate(self): @@ -324,7 +325,7 @@ class TestResultGet(TestResultBase): self._create_error_start_date('None') self._create_error_start_date('null') self._create_error_start_date('') - return self._set_query('period=5') + return self._set_query(period=5) def _query_success(self, body, number): self.assertEqual(number, len(body.results)) @@ -363,18 +364,16 @@ class TestResultGet(TestResultBase): self.create(req) return req - def _set_query(self, *args): + def _set_query(self, *args, **kwargs): def get_value(arg): return self.__getattribute__(arg) \ if arg != 'trust_indicator' else self.trust_indicator.current - uri = '' + query = [] for arg in args: - if arg: - if '=' in arg: - uri += arg + '&' - else: - uri += '{}={}&'.format(arg, get_value(arg)) - return uri[0: -1] + query.append((arg, get_value(arg))) + for k, v in kwargs.iteritems(): + query.append((k, v)) + return urllib.urlencode(query) class TestResultUpdate(TestResultBase): |