summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2015-09-14 22:28:26 +0000
committerGerrit Code Review <review@openstack.org>2015-09-14 22:28:26 +0000
commitc3fdf97437ab91007478a59c3a7168d1ee4ea324 (patch)
tree1ec1c0b69b4726f41885154ca248f82bef47a848
parentea54c461747af8c1b65fb74eb730706dedd29820 (diff)
parentffedc364e1611ef184ad2a579c37dd23028a565c (diff)
downloadkeystone-c3fdf97437ab91007478a59c3a7168d1ee4ea324.tar.gz
Merge "Move TestClient to test_versions"
-rw-r--r--keystone/tests/unit/core.py31
-rw-r--r--keystone/tests/unit/test_versions.py65
2 files changed, 48 insertions, 48 deletions
diff --git a/keystone/tests/unit/core.py b/keystone/tests/unit/core.py
index 10b7c0b76..eb8b9f65b 100644
--- a/keystone/tests/unit/core.py
+++ b/keystone/tests/unit/core.py
@@ -37,7 +37,6 @@ from paste.deploy import loadwsgi
import six
from sqlalchemy import exc
from testtools import testcase
-import webob
# NOTE(ayoung)
# environment.use_eventlet must run before any of the code that will
@@ -224,36 +223,6 @@ class UnexpectedExit(Exception):
pass
-class TestClient(object):
- def __init__(self, app=None, token=None):
- self.app = app
- self.token = token
-
- def request(self, method, path, headers=None, body=None):
- if headers is None:
- headers = {}
-
- if self.token:
- headers.setdefault('X-Auth-Token', self.token)
-
- req = webob.Request.blank(path)
- req.method = method
- for k, v in headers.items():
- req.headers[k] = v
- if body:
- req.body = body
- return req.get_response(self.app)
-
- def get(self, path, headers=None):
- return self.request('GET', path=path, headers=headers)
-
- def post(self, path, headers=None, body=None):
- return self.request('POST', path=path, headers=headers, body=body)
-
- def put(self, path, headers=None, body=None):
- return self.request('PUT', path=path, headers=headers, body=body)
-
-
def new_ref():
"""Populates a ref with attributes common to some API entities."""
return {
diff --git a/keystone/tests/unit/test_versions.py b/keystone/tests/unit/test_versions.py
index 76625b354..40814588e 100644
--- a/keystone/tests/unit/test_versions.py
+++ b/keystone/tests/unit/test_versions.py
@@ -22,6 +22,7 @@ from oslo_config import cfg
from oslo_serialization import jsonutils
from six.moves import http_client
from testtools import matchers as tt_matchers
+import webob
from keystone.common import json_home
from keystone import controllers
@@ -622,6 +623,36 @@ V3_JSON_HOME_RESOURCES_INHERIT_ENABLED.update(
)
+class TestClient(object):
+ def __init__(self, app=None, token=None):
+ self.app = app
+ self.token = token
+
+ def request(self, method, path, headers=None, body=None):
+ if headers is None:
+ headers = {}
+
+ if self.token:
+ headers.setdefault('X-Auth-Token', self.token)
+
+ req = webob.Request.blank(path)
+ req.method = method
+ for k, v in headers.items():
+ req.headers[k] = v
+ if body:
+ req.body = body
+ return req.get_response(self.app)
+
+ def get(self, path, headers=None):
+ return self.request('GET', path=path, headers=headers)
+
+ def post(self, path, headers=None, body=None):
+ return self.request('POST', path=path, headers=headers, body=body)
+
+ def put(self, path, headers=None, body=None):
+ return self.request('PUT', path=path, headers=headers, body=body)
+
+
class _VersionsEqual(tt_matchers.MatchesListwise):
def __init__(self, expected):
super(_VersionsEqual, self).__init__([
@@ -665,7 +696,7 @@ class VersionTestCase(unit.TestCase):
link['href'] = port
def test_public_versions(self):
- client = unit.TestClient(self.public_app)
+ client = TestClient(self.public_app)
resp = client.get('/')
self.assertEqual(300, resp.status_int)
data = jsonutils.loads(resp.body)
@@ -682,7 +713,7 @@ class VersionTestCase(unit.TestCase):
self.assertThat(data, _VersionsEqual(expected))
def test_admin_versions(self):
- client = unit.TestClient(self.admin_app)
+ client = TestClient(self.admin_app)
resp = client.get('/')
self.assertEqual(300, resp.status_int)
data = jsonutils.loads(resp.body)
@@ -702,7 +733,7 @@ class VersionTestCase(unit.TestCase):
self.config_fixture.config(public_endpoint=None, admin_endpoint=None)
for app in (self.public_app, self.admin_app):
- client = unit.TestClient(app)
+ client = TestClient(app)
resp = client.get('/')
self.assertEqual(300, resp.status_int)
data = jsonutils.loads(resp.body)
@@ -718,7 +749,7 @@ class VersionTestCase(unit.TestCase):
self.assertThat(data, _VersionsEqual(expected))
def test_public_version_v2(self):
- client = unit.TestClient(self.public_app)
+ client = TestClient(self.public_app)
resp = client.get('/v2.0/')
self.assertEqual(200, resp.status_int)
data = jsonutils.loads(resp.body)
@@ -729,7 +760,7 @@ class VersionTestCase(unit.TestCase):
self.assertEqual(expected, data)
def test_admin_version_v2(self):
- client = unit.TestClient(self.admin_app)
+ client = TestClient(self.admin_app)
resp = client.get('/v2.0/')
self.assertEqual(200, resp.status_int)
data = jsonutils.loads(resp.body)
@@ -742,7 +773,7 @@ class VersionTestCase(unit.TestCase):
def test_use_site_url_if_endpoint_unset_v2(self):
self.config_fixture.config(public_endpoint=None, admin_endpoint=None)
for app in (self.public_app, self.admin_app):
- client = unit.TestClient(app)
+ client = TestClient(app)
resp = client.get('/v2.0/')
self.assertEqual(200, resp.status_int)
data = jsonutils.loads(resp.body)
@@ -751,7 +782,7 @@ class VersionTestCase(unit.TestCase):
self.assertEqual(data, expected)
def test_public_version_v3(self):
- client = unit.TestClient(self.public_app)
+ client = TestClient(self.public_app)
resp = client.get('/v3/')
self.assertEqual(200, resp.status_int)
data = jsonutils.loads(resp.body)
@@ -763,7 +794,7 @@ class VersionTestCase(unit.TestCase):
@utils.wip('waiting on bug #1381961')
def test_admin_version_v3(self):
- client = unit.TestClient(self.admin_app)
+ client = TestClient(self.admin_app)
resp = client.get('/v3/')
self.assertEqual(200, resp.status_int)
data = jsonutils.loads(resp.body)
@@ -776,7 +807,7 @@ class VersionTestCase(unit.TestCase):
def test_use_site_url_if_endpoint_unset_v3(self):
self.config_fixture.config(public_endpoint=None, admin_endpoint=None)
for app in (self.public_app, self.admin_app):
- client = unit.TestClient(app)
+ client = TestClient(app)
resp = client.get('/v3/')
self.assertEqual(200, resp.status_int)
data = jsonutils.loads(resp.body)
@@ -786,7 +817,7 @@ class VersionTestCase(unit.TestCase):
@mock.patch.object(controllers, '_VERSIONS', ['v3'])
def test_v2_disabled(self):
- client = unit.TestClient(self.public_app)
+ client = TestClient(self.public_app)
# request to /v2.0 should fail
resp = client.get('/v2.0/')
self.assertEqual(http_client.NOT_FOUND, resp.status_int)
@@ -819,7 +850,7 @@ class VersionTestCase(unit.TestCase):
@mock.patch.object(controllers, '_VERSIONS', ['v2.0'])
def test_v3_disabled(self):
- client = unit.TestClient(self.public_app)
+ client = TestClient(self.public_app)
# request to /v3 should fail
resp = client.get('/v3/')
self.assertEqual(http_client.NOT_FOUND, resp.status_int)
@@ -851,7 +882,7 @@ class VersionTestCase(unit.TestCase):
self.assertEqual(v2_only_response, data)
def _test_json_home(self, path, exp_json_home_data):
- client = unit.TestClient(self.public_app)
+ client = TestClient(self.public_app)
resp = client.get(path, headers={'Accept': 'application/json-home'})
self.assertThat(resp.status, tt_matchers.Equals('200 OK'))
@@ -884,7 +915,7 @@ class VersionTestCase(unit.TestCase):
# Accept headers with multiple types and qvalues are handled.
def make_request(accept_types=None):
- client = unit.TestClient(self.public_app)
+ client = TestClient(self.public_app)
headers = None
if accept_types:
headers = {'Accept': accept_types}
@@ -970,7 +1001,7 @@ class VersionSingleAppTestCase(unit.TestCase):
else:
return CONF.eventlet_server.public_port
app = self.loadapp('keystone', app_name)
- client = unit.TestClient(app)
+ client = TestClient(app)
resp = client.get('/')
self.assertEqual(300, resp.status_int)
data = jsonutils.loads(resp.body)
@@ -1016,7 +1047,7 @@ class VersionInheritEnabledTestCase(unit.TestCase):
# If the request is /v3 and the Accept header is application/json-home
# then the server responds with a JSON Home document.
- client = unit.TestClient(self.public_app)
+ client = TestClient(self.public_app)
resp = client.get('/v3/', headers={'Accept': 'application/json-home'})
self.assertThat(resp.status, tt_matchers.Equals('200 OK'))
@@ -1056,7 +1087,7 @@ class VersionBehindSslTestCase(unit.TestCase):
return expected
def test_versions_without_headers(self):
- client = unit.TestClient(self.public_app)
+ client = TestClient(self.public_app)
host_name = 'host-%d' % random.randint(10, 30)
host_port = random.randint(10000, 30000)
host = 'http://%s:%s/' % (host_name, host_port)
@@ -1067,7 +1098,7 @@ class VersionBehindSslTestCase(unit.TestCase):
self.assertThat(data, _VersionsEqual(expected))
def test_versions_with_header(self):
- client = unit.TestClient(self.public_app)
+ client = TestClient(self.public_app)
host_name = 'host-%d' % random.randint(10, 30)
host_port = random.randint(10000, 30000)
resp = client.get('http://%s:%s/' % (host_name, host_port),