Merge "Test query-string for list actions with filter arguments"

This commit is contained in:
Jenkins
2014-02-20 04:29:41 +00:00
committed by Gerrit Code Review
2 changed files with 23 additions and 5 deletions

View File

@@ -86,13 +86,13 @@ class TrustTests(utils.TestCase, utils.CrudTests):
super(TrustTests, self).test_create(ref=ref, req_ref=req_ref) super(TrustTests, self).test_create(ref=ref, req_ref=req_ref)
def test_list_filter_trustor(self): def test_list_filter_trustor(self):
ep = 'v3/OS-TRUST/trusts?trustor_user_id=12345' expected_query = {'trustor_user_id': '12345'}
super(TrustTests, self).test_list(expected_path=ep, super(TrustTests, self).test_list(expected_query=expected_query,
trustor_user='12345') trustor_user='12345')
def test_list_filter_trustee(self): def test_list_filter_trustee(self):
ep = 'v3/OS-TRUST/trusts?trustee_user_id=12345' expected_query = {'trustee_user_id': '12345'}
super(TrustTests, self).test_list(expected_path=ep, super(TrustTests, self).test_list(expected_query=expected_query,
trustee_user='12345') trustee_user='12345')
def test_update(self): def test_update(self):

View File

@@ -13,6 +13,7 @@
import uuid import uuid
import httpretty import httpretty
import six
from six.moves.urllib import parse as urlparse from six.moves.urllib import parse as urlparse
from keystoneclient.openstack.common import jsonutils from keystoneclient.openstack.common import jsonutils
@@ -234,7 +235,8 @@ class CrudTests(object):
return expected_path return expected_path
@httpretty.activate @httpretty.activate
def test_list(self, ref_list=None, expected_path=None, **filter_kwargs): def test_list(self, ref_list=None, expected_path=None,
expected_query=None, **filter_kwargs):
ref_list = ref_list or [self.new_ref(), self.new_ref()] ref_list = ref_list or [self.new_ref(), self.new_ref()]
expected_path = self._get_expected_path(expected_path) expected_path = self._get_expected_path(expected_path)
@@ -246,6 +248,22 @@ class CrudTests(object):
self.assertEqual(len(ref_list), len(returned_list)) self.assertEqual(len(ref_list), len(returned_list))
[self.assertIsInstance(r, self.model) for r in returned_list] [self.assertIsInstance(r, self.model) for r in returned_list]
# register_uri doesn't match the querystring component, so we have to
# explicitly test the querystring component passed by the manager
qs_args = httpretty.last_request().querystring
qs_args_expected = expected_query or filter_kwargs
for key, value in six.iteritems(qs_args_expected):
self.assertIn(key, qs_args)
# The httppretty.querystring value is a list
# Note we convert the value to a string, as the query string
# is always a string and the filter_kwargs may contain non-string
# values, for example a boolean, causing the comaprison to fail.
self.assertIn(str(value), qs_args[key])
# Also check that no query string args exist which are not expected
for key in qs_args:
self.assertIn(key, qs_args_expected)
@httpretty.activate @httpretty.activate
def test_list_params(self): def test_list_params(self):
ref_list = [self.new_ref()] ref_list = [self.new_ref()]