summaryrefslogtreecommitdiff
path: root/openstack_auth/tests
diff options
context:
space:
mode:
authorStephen Finucane <stephenfin@redhat.com>2020-02-21 10:46:28 +0000
committerStephen Finucane <stephenfin@redhat.com>2020-02-21 11:08:57 +0000
commit25fa17b41737501f2091c68124b1631e904d61a0 (patch)
treea91f3cc2540f72a9ecd938eaea4ef0830c963cd2 /openstack_auth/tests
parente515713084f0ce5d7874ffe4ef080fcc2e5760cb (diff)
downloadhorizon-25fa17b41737501f2091c68124b1631e904d61a0.tar.gz
tests: Convert remaining mox tests to mock (pt. 2.1)
Mox uses a very different style of testing than mock does. In Mox, you state both the things you want to mock and the expected call order of these mocks before you call your function under test, while in mock you do the mocking, call your function under test, and then check the expected call order. This means extensive use of helper functions is problematic. Start resolving this by flattening tests, allowing us to eventually do the conversions. Change-Id: Id44cda44c7b7a8fa85ef876bf06c2c74922ff241 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
Diffstat (limited to 'openstack_auth/tests')
-rw-r--r--openstack_auth/tests/unit/test_auth.py34
1 files changed, 18 insertions, 16 deletions
diff --git a/openstack_auth/tests/unit/test_auth.py b/openstack_auth/tests/unit/test_auth.py
index 99241858d..c685cc31d 100644
--- a/openstack_auth/tests/unit/test_auth.py
+++ b/openstack_auth/tests/unit/test_auth.py
@@ -56,20 +56,6 @@ class OpenStackAuthTestsMixin(object):
('admin', {'interface': 'adminURL'})
]
- def _mock_unscoped_client(self, user):
- plugin = self._create_password_auth()
- plugin.get_access(mox.IsA(session.Session)). \
- AndReturn(self.data.unscoped_access_info)
- plugin.auth_url = settings.OPENSTACK_KEYSTONE_URL
- return self.ks_client_module.Client(session=mox.IsA(session.Session),
- auth=plugin)
-
- def _mock_unscoped_client_with_token(self, user, unscoped):
- plugin = token_endpoint.Token(settings.OPENSTACK_KEYSTONE_URL,
- unscoped.auth_token)
- return self.ks_client_module.Client(session=mox.IsA(session.Session),
- auth=plugin)
-
def _mock_scoped_client_for_tenant(self, auth_ref, tenant_id, url=None,
client=True, token=None):
if url is None:
@@ -152,7 +138,15 @@ class OpenStackAuthTestsV3(OpenStackAuthTestsMixin,
client.projects.list(user=user.id).AndReturn(projects)
def _mock_unscoped_client_list_projects_fail(self, user):
- client = self._mock_unscoped_client(user)
+ # _mock_unscoped_client
+
+ plugin = self._create_password_auth()
+ plugin.get_access(mox.IsA(session.Session)). \
+ AndReturn(self.data.unscoped_access_info)
+ plugin.auth_url = settings.OPENSTACK_KEYSTONE_URL
+ client = self.ks_client_module.Client(
+ session=mox.IsA(session.Session), auth=plugin)
+
self._mock_unscoped_list_projects_fail(client, user)
def _mock_unscoped_list_projects_fail(self, client, user):
@@ -168,7 +162,15 @@ class OpenStackAuthTestsV3(OpenStackAuthTestsMixin,
keystone_exceptions.AuthorizationFailure)
def _mock_unscoped_and_domain_list_projects(self, user, projects):
- client = self._mock_unscoped_client(user)
+ # _mock_unscoped_client
+
+ plugin = self._create_password_auth()
+ plugin.get_access(mox.IsA(session.Session)). \
+ AndReturn(self.data.unscoped_access_info)
+ plugin.auth_url = settings.OPENSTACK_KEYSTONE_URL
+ client = self.ks_client_module.Client(
+ session=mox.IsA(session.Session), auth=plugin)
+
self._mock_scoped_for_domain(projects)
self._mock_unscoped_list_projects(client, user, projects)