diff options
Diffstat (limited to 'keystone-moon/keystone/tests/unit/rest.py')
-rw-r--r-- | keystone-moon/keystone/tests/unit/rest.py | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/keystone-moon/keystone/tests/unit/rest.py b/keystone-moon/keystone/tests/unit/rest.py index 35b47e2b..512c301d 100644 --- a/keystone-moon/keystone/tests/unit/rest.py +++ b/keystone-moon/keystone/tests/unit/rest.py @@ -61,7 +61,7 @@ class RestfulTestCase(unit.TestCase): # Will need to reset the plug-ins self.addCleanup(setattr, auth_controllers, 'AUTH_METHODS', {}) - self.useFixture(database.Database()) + self.useFixture(database.Database(self.sql_driver_version_overrides)) self.load_backends() self.load_fixtures(default_fixtures) @@ -114,11 +114,10 @@ class RestfulTestCase(unit.TestCase): example:: - self.assertResponseStatus(response, 204) + self.assertResponseStatus(response, http_client.NO_CONTENT) """ self.assertEqual( - response.status_code, - expected_status, + expected_status, response.status_code, 'Status code %s is not %s, as expected\n\n%s' % (response.status_code, expected_status, response.body)) @@ -133,9 +132,9 @@ class RestfulTestCase(unit.TestCase): Subclasses can override this function based on the expected response. """ - self.assertEqual(response.status_code, expected_status) + self.assertEqual(expected_status, response.status_code) error = response.result['error'] - self.assertEqual(error['code'], response.status_code) + self.assertEqual(response.status_code, error['code']) self.assertIsNotNone(error.get('title')) def _to_content_type(self, body, headers, content_type=None): @@ -146,7 +145,11 @@ class RestfulTestCase(unit.TestCase): headers['Accept'] = 'application/json' if body: headers['Content-Type'] = 'application/json' - return jsonutils.dumps(body) + # NOTE(davechen):dump the body to bytes since WSGI requires + # the body of the response to be `Bytestrings`. + # see pep-3333: + # https://www.python.org/dev/peps/pep-3333/#a-note-on-string-types + return jsonutils.dump_as_bytes(body) def _from_content_type(self, response, content_type=None): """Attempt to decode JSON and XML automatically, if detected.""" @@ -213,6 +216,17 @@ class RestfulTestCase(unit.TestCase): r = self.public_request(method='POST', path='/v2.0/tokens', body=body) return self._get_token_id(r) + def get_admin_token(self): + return self._get_token({ + 'auth': { + 'passwordCredentials': { + 'username': self.user_reqadmin['name'], + 'password': self.user_reqadmin['password'] + }, + 'tenantId': default_fixtures.SERVICE_TENANT_ID + } + }) + def get_unscoped_token(self): """Convenience method so that we can test authenticated requests.""" return self._get_token({ |