summaryrefslogtreecommitdiff
path: root/openstack_auth/tests
diff options
context:
space:
mode:
authorStephen Finucane <stephenfin@redhat.com>2020-02-21 11:07:49 +0000
committerStephen Finucane <stephenfin@redhat.com>2020-02-21 11:12:51 +0000
commit3422bed83f8d48a3bbe20d9f56ed1891be5f8552 (patch)
treed179d6743adafb660c46a0492bb6fe6368ad6d96 /openstack_auth/tests
parent25fa17b41737501f2091c68124b1631e904d61a0 (diff)
downloadhorizon-3422bed83f8d48a3bbe20d9f56ed1891be5f8552.tar.gz
tests: Convert remaining mox tests to mock (pt. 2.2)
As before, we're not actually doing any conversion but rather flattening things out to allow us easily switch from the Mox style to mock style of testing. Change-Id: I37b7944b25ed6fe3a1fc49086c829b75970f248f Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
Diffstat (limited to 'openstack_auth/tests')
-rw-r--r--openstack_auth/tests/unit/test_auth.py145
1 files changed, 114 insertions, 31 deletions
diff --git a/openstack_auth/tests/unit/test_auth.py b/openstack_auth/tests/unit/test_auth.py
index c685cc31d..3df329909 100644
--- a/openstack_auth/tests/unit/test_auth.py
+++ b/openstack_auth/tests/unit/test_auth.py
@@ -47,7 +47,7 @@ class IsA(object):
class OpenStackAuthTestsMixin(object):
- '''Common functions for version specific tests.'''
+ """Common functions for version specific tests."""
scenarios = [
('pure', {'interface': None}),
@@ -56,25 +56,6 @@ class OpenStackAuthTestsMixin(object):
('admin', {'interface': 'adminURL'})
]
- def _mock_scoped_client_for_tenant(self, auth_ref, tenant_id, url=None,
- client=True, token=None):
- if url is None:
- url = settings.OPENSTACK_KEYSTONE_URL
-
- if not token:
- token = self.data.unscoped_access_info.auth_token
-
- plugin = self._create_token_auth(
- tenant_id,
- token=token,
- url=url)
- self.scoped_token_auth = plugin
- plugin.get_access(mox.IsA(session.Session)).AndReturn(auth_ref)
- if client:
- return self.ks_client_module.Client(
- session=mox.IsA(session.Session),
- auth=plugin)
-
def get_form_data(self, user):
return {'region': "default",
'domain': DEFAULT_DOMAIN,
@@ -265,7 +246,20 @@ class OpenStackAuthTestsV3(OpenStackAuthTestsMixin,
# mock authenticate
self._mock_unscoped_and_domain_list_projects(user, projects)
- self._mock_scoped_client_for_tenant(unscoped, self.data.project_one.id)
+
+ # _mock_scoped_client_for_tenant
+
+ url = settings.OPENSTACK_KEYSTONE_URL
+ token = self.data.unscoped_access_info.auth_token
+ plugin = self._create_token_auth(
+ self.data.project_one.id,
+ token=token,
+ url=url)
+ self.scoped_token_auth = plugin
+ plugin.get_access(mox.IsA(session.Session)).AndReturn(unscoped)
+ self.ks_client_module.Client(
+ session=mox.IsA(session.Session),
+ auth=plugin)
# mock switch
plugin = v3_auth.Token(auth_url=auth_url,
@@ -331,7 +325,20 @@ class OpenStackAuthTestsV3(OpenStackAuthTestsMixin,
# mock authenticate
self._mock_unscoped_and_domain_list_projects(user, projects)
- self._mock_scoped_client_for_tenant(unscoped, self.data.project_one.id)
+
+ # _mock_scoped_client_for_tenant
+
+ url = settings.OPENSTACK_KEYSTONE_URL
+ token = self.data.unscoped_access_info.auth_token
+ plugin = self._create_token_auth(
+ self.data.project_one.id,
+ token=token,
+ url=url)
+ self.scoped_token_auth = plugin
+ plugin.get_access(mox.IsA(session.Session)).AndReturn(unscoped)
+ self.ks_client_module.Client(
+ session=mox.IsA(session.Session),
+ auth=plugin)
# mock switch
plugin = v3_auth.Token(auth_url=auth_url,
@@ -373,10 +380,20 @@ class OpenStackAuthTestsV3(OpenStackAuthTestsMixin,
client = self._mock_unscoped_token_client(None, plugin.auth_url,
plugin=sp_unscoped_auth)
self._mock_unscoped_federated_list_projects(client, sp_projects)
- self._mock_scoped_client_for_tenant(sp_unscoped,
- self.sp_data.project_one.id,
- url=plugin.auth_url,
- token=sp_unscoped.auth_token)
+
+ # _mock_scoped_client_for_tenant
+
+ url = plugin.auth_url
+ token = sp_unscoped.auth_token
+ plugin = self._create_token_auth(
+ self.sp_data.project_one.id,
+ token=token,
+ url=url)
+ self.scoped_token_auth = plugin
+ plugin.get_access(mox.IsA(session.Session)).AndReturn(sp_unscoped)
+ self.ks_client_module.Client(
+ session=mox.IsA(session.Session),
+ auth=plugin)
self.mox.ReplayAll()
@@ -414,7 +431,21 @@ class OpenStackAuthTestsV3(OpenStackAuthTestsMixin,
# mock authenticate
self._mock_unscoped_and_domain_list_projects(user, projects)
- self._mock_scoped_client_for_tenant(unscoped, self.data.project_one.id)
+
+ # _mock_scoped_client_for_tenant
+
+ url = settings.OPENSTACK_KEYSTONE_URL
+ token = self.data.unscoped_access_info.auth_token
+ plugin = self._create_token_auth(
+ self.data.project_one.id,
+ token=token,
+ url=url)
+ self.scoped_token_auth = plugin
+ plugin.get_access(mox.IsA(session.Session)).AndReturn(unscoped)
+ self.ks_client_module.Client(
+ session=mox.IsA(session.Session),
+ auth=plugin)
+
self._mock_unscoped_token_client(unscoped,
auth_url=auth_url,
client=False)
@@ -425,7 +456,20 @@ class OpenStackAuthTestsV3(OpenStackAuthTestsMixin,
client = self._mock_unscoped_token_client(None, auth_url=auth_url,
plugin=unscoped_auth)
self._mock_unscoped_list_projects(client, user, projects)
- self._mock_scoped_client_for_tenant(unscoped, self.data.project_one.id)
+
+ # _mock_scoped_client_for_tenant
+
+ url = settings.OPENSTACK_KEYSTONE_URL
+ token = self.data.unscoped_access_info.auth_token
+ plugin = self._create_token_auth(
+ self.data.project_one.id,
+ token=token,
+ url=url)
+ self.scoped_token_auth = plugin
+ plugin.get_access(mox.IsA(session.Session)).AndReturn(unscoped)
+ self.ks_client_module.Client(
+ session=mox.IsA(session.Session),
+ auth=plugin)
self.mox.ReplayAll()
@@ -461,7 +505,20 @@ class OpenStackAuthTestsV3(OpenStackAuthTestsMixin,
# mock authenticate
self._mock_unscoped_and_domain_list_projects(user, projects)
- self._mock_scoped_client_for_tenant(unscoped, self.data.project_one.id)
+
+ # _mock_scoped_client_for_tenant
+
+ url = settings.OPENSTACK_KEYSTONE_URL
+ token = self.data.unscoped_access_info.auth_token
+ plugin = self._create_token_auth(
+ self.data.project_one.id,
+ token=token,
+ url=url)
+ self.scoped_token_auth = plugin
+ plugin.get_access(mox.IsA(session.Session)).AndReturn(unscoped)
+ self.ks_client_module.Client(
+ session=mox.IsA(session.Session),
+ auth=plugin)
# Let using the base token for logging in fail
plugin = v3_auth.Token(auth_url=auth_url,
@@ -617,7 +674,20 @@ class OpenStackAuthTestsWebSSO(OpenStackAuthTestsMixin,
form_data = {'token': token}
self._mock_federated_client_list_domains(unscoped_auth, domains)
self._mock_federated_client_list_projects(unscoped_auth, projects)
- self._mock_scoped_client_for_tenant(unscoped, self.data.project_one.id)
+
+ # _mock_scoped_client_for_tenant
+
+ url = settings.OPENSTACK_KEYSTONE_URL
+ token = self.data.unscoped_access_info.auth_token
+ plugin = self._create_token_auth(
+ self.data.project_one.id,
+ token=token,
+ url=url)
+ self.scoped_token_auth = plugin
+ plugin.get_access(mox.IsA(session.Session)).AndReturn(unscoped)
+ self.ks_client_module.Client(
+ session=mox.IsA(session.Session),
+ auth=plugin)
self.mox.ReplayAll()
@@ -640,7 +710,20 @@ class OpenStackAuthTestsWebSSO(OpenStackAuthTestsMixin,
form_data = {'token': token}
self._mock_federated_client_list_domains(unscoped_auth, domains)
self._mock_federated_client_list_projects(unscoped_auth, projects)
- self._mock_scoped_client_for_tenant(unscoped, self.data.project_one.id)
+
+ # _mock_scoped_client_for_tenant
+
+ url = settings.OPENSTACK_KEYSTONE_URL
+ token = self.data.unscoped_access_info.auth_token
+ plugin = self._create_token_auth(
+ self.data.project_one.id,
+ token=token,
+ url=url)
+ self.scoped_token_auth = plugin
+ plugin.get_access(mox.IsA(session.Session)).AndReturn(unscoped)
+ self.ks_client_module.Client(
+ session=mox.IsA(session.Session),
+ auth=plugin)
self.mox.ReplayAll()