summaryrefslogtreecommitdiff
path: root/openstack_auth
diff options
context:
space:
mode:
authorAkihiro Motoki <amotoki@gmail.com>2020-09-13 08:32:36 +0900
committerAkihiro Motoki <amotoki@gmail.com>2020-10-27 19:58:07 +0900
commit4046ef661666794d196ee6d93cf0c6595b6830ea (patch)
treec8ea20843a480cbd4bc849a528843c2f3d66f339 /openstack_auth
parentf90c3cd50174af4927737e29e2765cd2d7ca507f (diff)
downloadhorizon-4046ef661666794d196ee6d93cf0c6595b6830ea.tar.gz
Recover scenario settings in openstack_auth test_auth
The scenario configuration in openstack_auth test_auth was ignored somehow. Perhaps it happened when openstack_auth was merged into the horizon repo as test runners used in the horizon repo so far (django test runner, nose and pytest) do not support testscenarios. This commit tries to recover the original intention of the scenario. pytest supports several ways to parametrize tests [1] but there seems no way without changing each test functions. A quick port of "testscenarios" is explained [2], but it is just a way to generate tests based on scenarios and we still need to add scenario parameters to each test function, so we cannot refer scenario parameters in setUp(). As a result, I chose a way to inherit the original class and pass different attributes per scenario. This is not ideal and I hope pytest lovers can improve the situation. The test classes in test_auth are renamed to more meaningful ones. Direct overrides of settings in test_auth.py are improved too. [1] https://docs.pytest.org/en/stable/example/parametrize.html [2] https://docs.pytest.org/en/stable/example/parametrize.html#a-quick-port-of-testscenarios Change-Id: I1538ffbc853a2c9328c364f462a27be36c85cc2f
Diffstat (limited to 'openstack_auth')
-rw-r--r--openstack_auth/tests/unit/test_auth.py111
1 files changed, 66 insertions, 45 deletions
diff --git a/openstack_auth/tests/unit/test_auth.py b/openstack_auth/tests/unit/test_auth.py
index f4e7117aa..ac162a9fc 100644
--- a/openstack_auth/tests/unit/test_auth.py
+++ b/openstack_auth/tests/unit/test_auth.py
@@ -45,37 +45,32 @@ class IsA(object):
return isinstance(other, self.cls)
-class OpenStackAuthTestsMixin(object):
- """Common functions for version specific tests."""
+class SwitchProviderTests(test.TestCase):
- scenarios = [
- ('pure', {'interface': None}),
- ('public', {'interface': 'publicURL'}),
- ('internal', {'interface': 'internalURL'}),
- ('admin', {'interface': 'adminURL'})
- ]
-
- def get_form_data(self, user):
- return {'region': "default",
- 'domain': DEFAULT_DOMAIN,
- 'password': user.password,
- 'username': user.name}
-
-
-class OpenStackAuthTestsV3Base(OpenStackAuthTestsMixin, test.TestCase):
+ interface = None
def setUp(self):
super().setUp()
- if getattr(self, 'interface', None):
- override = self.settings(OPENSTACK_ENDPOINT_TYPE=self.interface)
- override.enable()
- self.addCleanup(override.disable)
+ params = {
+ 'OPENSTACK_API_VERSIONS': {'identity': 3},
+ 'OPENSTACK_KEYSTONE_URL': "http://localhost/identity/v3",
+ }
+ if self.interface:
+ params['OPENSTACK_ENDPOINT_TYPE'] = self.interface
+
+ override = self.settings(**params)
+ override.enable()
+ self.addCleanup(override.disable)
self.data = data_v3.generate_test_data()
self.ks_client_module = client_v3
- settings.OPENSTACK_API_VERSIONS['identity'] = 3
- settings.OPENSTACK_KEYSTONE_URL = "http://localhost/identity/v3"
+
+ def get_form_data(self, user):
+ return {'region': "default",
+ 'domain': DEFAULT_DOMAIN,
+ 'password': user.password,
+ 'username': user.name}
@mock.patch.object(v3_auth, 'Keystone2Keystone')
@mock.patch.object(client_v3, 'Client')
@@ -709,7 +704,19 @@ class OpenStackAuthTestsV3Base(OpenStackAuthTestsMixin, test.TestCase):
IsA(session.Session))
-class OpenStackAuthTestsWebSSO(OpenStackAuthTestsMixin, test.TestCase):
+class SwitchProviderTestsPublicURL(SwitchProviderTests):
+ interface = 'publicURL'
+
+
+class SwitchProviderTestsInternalURL(SwitchProviderTests):
+ interface = 'internalURL'
+
+
+class SwitchProviderTestsAdminURL(SwitchProviderTests):
+ interface = 'adminURL'
+
+
+class OpenStackAuthTestsWebSSO(test.TestCase):
def setUp(self):
super().setUp()
@@ -986,25 +993,31 @@ class OpenStackAuthTestsWebSSO(OpenStackAuthTestsMixin, test.TestCase):
status_code=302, target_status_code=301)
-class OpenStackAuthTestsV3WithMock(test.TestCase):
+class OpenStackAuthTests(test.TestCase):
- def get_form_data(self, user):
- return {'region': "default",
- 'domain': DEFAULT_DOMAIN,
- 'password': user.password,
- 'username': user.name}
+ interface = None
def setUp(self):
super().setUp()
- if getattr(self, 'interface', None):
- override = self.settings(OPENSTACK_ENDPOINT_TYPE=self.interface)
- override.enable()
- self.addCleanup(override.disable)
+ params = {
+ 'OPENSTACK_API_VERSIONS': {'identity': 3},
+ 'OPENSTACK_KEYSTONE_URL': "http://localhost/identity/v3",
+ }
+ if self.interface:
+ params['OPENSTACK_ENDPOINT_TYPE'] = self.interface
+
+ override = self.settings(**params)
+ override.enable()
+ self.addCleanup(override.disable)
self.data = data_v3.generate_test_data()
- settings.OPENSTACK_API_VERSIONS['identity'] = 3
- settings.OPENSTACK_KEYSTONE_URL = "http://localhost:5000/v3"
+
+ def get_form_data(self, user):
+ return {'region': "default",
+ 'domain': DEFAULT_DOMAIN,
+ 'password': user.password,
+ 'username': user.name}
@mock.patch('keystoneauth1.identity.v3.Token.get_access')
@mock.patch('keystoneauth1.identity.v3.Password.get_access')
@@ -1109,22 +1122,18 @@ class OpenStackAuthTestsV3WithMock(test.TestCase):
self.assertContains(response, 'id="id_domain"')
self.assertContains(response, 'name="domain"')
+ @override_settings(
+ OPENSTACK_KEYSTONE_MULTIDOMAIN_SUPPORT=True,
+ OPENSTACK_KEYSTONE_DOMAIN_DROPDOWN=True,
+ OPENSTACK_KEYSTONE_DOMAIN_CHOICES=(('Default', 'Default'),)
+ )
def test_login_form_multidomain_dropdown(self):
- override = self.settings(OPENSTACK_KEYSTONE_MULTIDOMAIN_SUPPORT=True,
- OPENSTACK_KEYSTONE_DOMAIN_DROPDOWN=True,
- OPENSTACK_KEYSTONE_DOMAIN_CHOICES=(
- ('Default', 'Default'),)
- )
- override.enable()
- self.addCleanup(override.disable)
-
url = reverse('login')
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'id="id_domain"')
self.assertContains(response, 'name="domain"')
self.assertContains(response, 'option value="Default"')
- settings.OPENSTACK_KEYSTONE_DOMAIN_DROPDOWN = False
@mock.patch.object(projects.ProjectManager, 'list')
def test_tenant_sorting(self, mock_project_list):
@@ -1372,3 +1381,15 @@ class OpenStackAuthTestsV3WithMock(test.TestCase):
def test_switch_region_with_next(self, next=None):
self.test_switch_region(next='/next_url')
+
+
+class OpenStackAuthTestsPublicURL(OpenStackAuthTests):
+ interface = 'publicURL'
+
+
+class OpenStackAuthTestsInternalURL(OpenStackAuthTests):
+ interface = 'internalURL'
+
+
+class OpenStackAuthTestsAdminURL(OpenStackAuthTests):
+ interface = 'adminURL'