Test query-string for list actions with filter arguments

httpretty.register_uri only matches the path, not the query
string, so the test_list will pass even if the query string
passed by the manager doesn't match that passed as part of
expected_path.

So add a test for the query component of all list requests,
and a way to override the expected query, which is needed in
the trusts list filter tests where the query string doesn't
exactly match the kwargs passed to the client API.

Change-Id: I290b73bbbdac88487c225063fd3775ab7dd8bb89
This commit is contained in:
Steven Hardy
2014-02-15 08:55:44 +00:00
parent 4917f1347a
commit 1c744bb266
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)
def test_list_filter_trustor(self):
ep = 'v3/OS-TRUST/trusts?trustor_user_id=12345'
super(TrustTests, self).test_list(expected_path=ep,
expected_query = {'trustor_user_id': '12345'}
super(TrustTests, self).test_list(expected_query=expected_query,
trustor_user='12345')
def test_list_filter_trustee(self):
ep = 'v3/OS-TRUST/trusts?trustee_user_id=12345'
super(TrustTests, self).test_list(expected_path=ep,
expected_query = {'trustee_user_id': '12345'}
super(TrustTests, self).test_list(expected_query=expected_query,
trustee_user='12345')
def test_update(self):

View File

@@ -13,6 +13,7 @@
import uuid
import httpretty
import six
from six.moves.urllib import parse as urlparse
from keystoneclient.openstack.common import jsonutils
@@ -234,7 +235,8 @@ class CrudTests(object):
return expected_path
@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()]
expected_path = self._get_expected_path(expected_path)
@@ -246,6 +248,22 @@ class CrudTests(object):
self.assertEqual(len(ref_list), len(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
def test_list_params(self):
ref_list = [self.new_ref()]