From f3af02f20fe4a4d48c7f5820bce95ae65b7f8e8c Mon Sep 17 00:00:00 2001 From: Akihiro Motoki Date: Wed, 22 Nov 2017 14:21:03 +0000 Subject: [PATCH] openstack_dashboard: Move test files to match module structure This commit relocates test codes in openstack_dashboard according to blueprint relocation-test-codes. Change-Id: I397a5a47fe9c1bf3a498c22056d924bf409c514b --- .../dashboards/project/api_access/tests.py | 174 +++++++++++++++- .../test/{api_tests => selenium}/__init__.py | 0 .../{tests => selenium}/selenium_tests.py | 0 openstack_dashboard/test/tests/policy.py | 39 ---- openstack_dashboard/test/tests/templates.py | 189 ------------------ .../test/{tests => unit}/__init__.py | 0 openstack_dashboard/test/unit/api/__init__.py | 0 .../test/unit/api/rest/__init__.py | 0 .../api/rest/test_cinder.py} | 0 .../api/rest/test_config.py} | 0 .../api/rest/test_glance.py} | 0 .../api/rest/test_keystone.py} | 0 .../api/rest/test_network.py} | 0 .../api/rest/test_neutron.py} | 0 .../api/rest/test_nova.py} | 0 .../api/rest/test_policy.py} | 0 .../api/rest/test_swift.py} | 0 .../api/rest/test_utils.py} | 0 .../base_tests.py => unit/api/test_base.py} | 0 .../api/test_cinder.py} | 0 .../api/test_glance.py} | 0 .../api/test_keystone.py} | 0 .../api/test_network.py} | 0 .../api/test_neutron.py} | 0 .../nova_tests.py => unit/api/test_nova.py} | 0 .../swift_tests.py => unit/api/test_swift.py} | 0 .../test_error_pages.py} | 0 .../policy_backend.py => unit/test_policy.py} | 15 ++ .../test/{themes.py => unit/test_themes.py} | 0 .../test/{views.py => unit/test_views.py} | 0 .../test/unit/usage/__init__.py | 0 .../quotas.py => unit/usage/test_quotas.py} | 0 .../test/unit/utils/__init__.py | 0 .../utils/test_config_types.py} | 27 --- .../test/unit/utils/test_filters.py | 41 ++++ 35 files changed, 228 insertions(+), 257 deletions(-) rename openstack_dashboard/test/{api_tests => selenium}/__init__.py (100%) rename openstack_dashboard/test/{tests => selenium}/selenium_tests.py (100%) delete mode 100644 openstack_dashboard/test/tests/policy.py delete mode 100644 openstack_dashboard/test/tests/templates.py rename openstack_dashboard/test/{tests => unit}/__init__.py (100%) create mode 100644 openstack_dashboard/test/unit/api/__init__.py create mode 100644 openstack_dashboard/test/unit/api/rest/__init__.py rename openstack_dashboard/test/{api_tests/cinder_rest_tests.py => unit/api/rest/test_cinder.py} (100%) rename openstack_dashboard/test/{api_tests/config_rest_tests.py => unit/api/rest/test_config.py} (100%) rename openstack_dashboard/test/{api_tests/glance_rest_tests.py => unit/api/rest/test_glance.py} (100%) rename openstack_dashboard/test/{api_tests/keystone_rest_tests.py => unit/api/rest/test_keystone.py} (100%) rename openstack_dashboard/test/{api_tests/network_rest_tests.py => unit/api/rest/test_network.py} (100%) rename openstack_dashboard/test/{api_tests/neutron_rest_tests.py => unit/api/rest/test_neutron.py} (100%) rename openstack_dashboard/test/{api_tests/nova_rest_tests.py => unit/api/rest/test_nova.py} (100%) rename openstack_dashboard/test/{api_tests/policy_rest_tests.py => unit/api/rest/test_policy.py} (100%) rename openstack_dashboard/test/{api_tests/swift_rest_tests.py => unit/api/rest/test_swift.py} (100%) rename openstack_dashboard/test/{api_tests/rest_util_tests.py => unit/api/rest/test_utils.py} (100%) rename openstack_dashboard/test/{api_tests/base_tests.py => unit/api/test_base.py} (100%) rename openstack_dashboard/test/{api_tests/cinder_tests.py => unit/api/test_cinder.py} (100%) rename openstack_dashboard/test/{api_tests/glance_tests.py => unit/api/test_glance.py} (100%) rename openstack_dashboard/test/{api_tests/keystone_tests.py => unit/api/test_keystone.py} (100%) rename openstack_dashboard/test/{api_tests/network_tests.py => unit/api/test_network.py} (100%) rename openstack_dashboard/test/{api_tests/neutron_tests.py => unit/api/test_neutron.py} (100%) rename openstack_dashboard/test/{api_tests/nova_tests.py => unit/api/test_nova.py} (100%) rename openstack_dashboard/test/{api_tests/swift_tests.py => unit/api/test_swift.py} (100%) rename openstack_dashboard/test/{tests/error_pages.py => unit/test_error_pages.py} (100%) rename openstack_dashboard/test/{tests/policy_backend.py => unit/test_policy.py} (88%) rename openstack_dashboard/test/{themes.py => unit/test_themes.py} (100%) rename openstack_dashboard/test/{views.py => unit/test_views.py} (100%) create mode 100644 openstack_dashboard/test/unit/usage/__init__.py rename openstack_dashboard/test/{tests/quotas.py => unit/usage/test_quotas.py} (100%) create mode 100644 openstack_dashboard/test/unit/utils/__init__.py rename openstack_dashboard/test/{tests/utils.py => unit/utils/test_config_types.py} (70%) create mode 100644 openstack_dashboard/test/unit/utils/test_filters.py diff --git a/openstack_dashboard/dashboards/project/api_access/tests.py b/openstack_dashboard/dashboards/project/api_access/tests.py index 6a717e7592..a9c389ce7f 100644 --- a/openstack_dashboard/dashboards/project/api_access/tests.py +++ b/openstack_dashboard/dashboards/project/api_access/tests.py @@ -12,14 +12,16 @@ # License for the specific language governing permissions and limitations # under the License. +from mox3.mox import IsA import six +import yaml from django.core.urlresolvers import reverse from django.http import HttpRequest +from django import template +from django.template import loader from django.test.utils import override_settings -from mox3.mox import IsA - from openstack_dashboard import api from openstack_dashboard.test import helpers as test @@ -202,3 +204,171 @@ class UnicodeTenantNameRCTests(test.TestCase): encode('latin-1') self.assertEqual(expected, result_content_disposition) + + +class FakeUser(object): + username = "cool user" + + +class TemplateRenderTest(test.TestCase): + """Tests for templates render.""" + + def test_openrc_html_escape(self): + context = { + "user": FakeUser(), + "tenant_id": "some-cool-id", + "auth_url": "http://tests.com", + "tenant_name": "ENG Perf R&D"} + out = loader.render_to_string( + 'project/api_access/openrc.sh.template', + context, + template.Context(context)) + + self.assertNotIn("&", out) + self.assertIn("ENG Perf R&D", out) + + def test_openrc_html_evil_shell_escape(self): + context = { + "user": FakeUser(), + "tenant_id": "some-cool-id", + "auth_url": "http://tests.com", + "tenant_name": 'o"; sudo rm -rf /'} + out = loader.render_to_string( + 'project/api_access/openrc.sh.template', + context, + template.Context(context)) + + self.assertNotIn('o"', out) + self.assertIn('\"', out) + + def test_openrc_html_evil_shell_backslash_escape(self): + context = { + "user": FakeUser(), + "tenant_id": "some-cool-id", + "auth_url": "http://tests.com", + "tenant_name": 'o\"; sudo rm -rf /'} + out = loader.render_to_string( + 'project/api_access/openrc.sh.template', + context, + template.Context(context)) + + self.assertNotIn('o\"', out) + self.assertNotIn('o"', out) + self.assertIn('\\"', out) + + def test_openrc_set_region(self): + context = { + "user": FakeUser(), + "tenant_id": "some-cool-id", + "auth_url": "http://tests.com", + "tenant_name": "Tenant", + "region": "Colorado"} + out = loader.render_to_string( + 'project/api_access/openrc.sh.template', + context, + template.Context(context)) + + self.assertIn("OS_REGION_NAME=\"Colorado\"", out) + + def test_openrc_region_not_set(self): + context = { + "user": FakeUser(), + "tenant_id": "some-cool-id", + "auth_url": "http://tests.com", + "tenant_name": "Tenant"} + out = loader.render_to_string( + 'project/api_access/openrc.sh.template', + context, + template.Context(context)) + + self.assertIn("OS_REGION_NAME=\"\"", out) + + def test_clouds_yaml_set_region(self): + context = { + "cloud_name": "openstack", + "user": FakeUser(), + "tenant_id": "some-cool-id", + "auth_url": "http://example.com", + "tenant_name": "Tenant", + "region": "Colorado"} + out = yaml.load(loader.render_to_string( + 'project/api_access/clouds.yaml.template', + context, + template.Context(context))) + + self.assertIn('clouds', out) + self.assertIn('openstack', out['clouds']) + self.assertNotIn('profile', out['clouds']['openstack']) + self.assertEqual( + "http://example.com", + out['clouds']['openstack']['auth']['auth_url']) + self.assertEqual("Colorado", out['clouds']['openstack']['region_name']) + self.assertNotIn('regions', out['clouds']['openstack']) + + def test_clouds_yaml_region_not_set(self): + context = { + "cloud_name": "openstack", + "user": FakeUser(), + "tenant_id": "some-cool-id", + "auth_url": "http://example.com", + "tenant_name": "Tenant"} + out = yaml.load(loader.render_to_string( + 'project/api_access/clouds.yaml.template', + context, + template.Context(context))) + + self.assertIn('clouds', out) + self.assertIn('openstack', out['clouds']) + self.assertNotIn('profile', out['clouds']['openstack']) + self.assertEqual( + "http://example.com", + out['clouds']['openstack']['auth']['auth_url']) + self.assertNotIn('region_name', out['clouds']['openstack']) + self.assertNotIn('regions', out['clouds']['openstack']) + + def test_clouds_yaml_regions(self): + regions = ['region1', 'region2'] + context = { + "cloud_name": "openstack", + "user": FakeUser(), + "tenant_id": "some-cool-id", + "auth_url": "http://example.com", + "tenant_name": "Tenant", + "regions": regions} + out = yaml.load(loader.render_to_string( + 'project/api_access/clouds.yaml.template', + context, + template.Context(context))) + + self.assertIn('clouds', out) + self.assertIn('openstack', out['clouds']) + self.assertNotIn('profile', out['clouds']['openstack']) + self.assertEqual( + "http://example.com", + out['clouds']['openstack']['auth']['auth_url']) + self.assertNotIn('region_name', out['clouds']['openstack']) + self.assertIn('regions', out['clouds']['openstack']) + self.assertEqual(regions, out['clouds']['openstack']['regions']) + + def test_clouds_yaml_profile(self): + regions = ['region1', 'region2'] + context = { + "cloud_name": "openstack", + "user": FakeUser(), + "profile": "example", + "tenant_id": "some-cool-id", + "auth_url": "http://example.com", + "tenant_name": "Tenant", + "regions": regions} + out = yaml.load(loader.render_to_string( + 'project/api_access/clouds.yaml.template', + context, + template.Context(context))) + + self.assertIn('clouds', out) + self.assertIn('openstack', out['clouds']) + self.assertIn('profile', out['clouds']['openstack']) + self.assertEqual('example', out['clouds']['openstack']['profile']) + self.assertNotIn('auth_url', out['clouds']['openstack']['auth']) + self.assertNotIn('region_name', out['clouds']['openstack']) + self.assertNotIn('regions', out['clouds']['openstack']) diff --git a/openstack_dashboard/test/api_tests/__init__.py b/openstack_dashboard/test/selenium/__init__.py similarity index 100% rename from openstack_dashboard/test/api_tests/__init__.py rename to openstack_dashboard/test/selenium/__init__.py diff --git a/openstack_dashboard/test/tests/selenium_tests.py b/openstack_dashboard/test/selenium/selenium_tests.py similarity index 100% rename from openstack_dashboard/test/tests/selenium_tests.py rename to openstack_dashboard/test/selenium/selenium_tests.py diff --git a/openstack_dashboard/test/tests/policy.py b/openstack_dashboard/test/tests/policy.py deleted file mode 100644 index 8c2a24fe76..0000000000 --- a/openstack_dashboard/test/tests/policy.py +++ /dev/null @@ -1,39 +0,0 @@ -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from django.test.utils import override_settings - -from openstack_dashboard import policy -from openstack_dashboard.test import helpers as test - - -class PolicyTestCase(test.TestCase): - @override_settings(POLICY_CHECK_FUNCTION='openstack_auth.policy.check') - def test_policy_check_set(self): - value = policy.check((("identity", "admin_required"),), - request=self.request) - self.assertFalse(value) - - @override_settings(POLICY_CHECK_FUNCTION=None) - def test_policy_check_not_set(self): - value = policy.check((("identity", "admin_required"),), - request=self.request) - self.assertTrue(value) - - -class PolicyBackendTestCaseAdmin(test.BaseAdminViewTests): - @override_settings(POLICY_CHECK_FUNCTION='openstack_auth.policy.check') - def test_policy_check_set_admin(self): - value = policy.check((("identity", "admin_required"),), - request=self.request) - self.assertTrue(value) diff --git a/openstack_dashboard/test/tests/templates.py b/openstack_dashboard/test/tests/templates.py deleted file mode 100644 index 852482f9a3..0000000000 --- a/openstack_dashboard/test/tests/templates.py +++ /dev/null @@ -1,189 +0,0 @@ -# Copyright (c) 2012 OpenStack Foundation -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import yaml - -from django import template -from django.template import loader - -from openstack_dashboard.test import helpers as test - - -class FakeUser(object): - username = "cool user" - - -class TemplateRenderTest(test.TestCase): - """Tests for templates render.""" - - def test_openrc_html_escape(self): - context = { - "user": FakeUser(), - "tenant_id": "some-cool-id", - "auth_url": "http://tests.com", - "tenant_name": "ENG Perf R&D"} - out = loader.render_to_string( - 'project/api_access/openrc.sh.template', - context, - template.Context(context)) - - self.assertNotIn("&", out) - self.assertIn("ENG Perf R&D", out) - - def test_openrc_html_evil_shell_escape(self): - context = { - "user": FakeUser(), - "tenant_id": "some-cool-id", - "auth_url": "http://tests.com", - "tenant_name": 'o"; sudo rm -rf /'} - out = loader.render_to_string( - 'project/api_access/openrc.sh.template', - context, - template.Context(context)) - - self.assertNotIn('o"', out) - self.assertIn('\"', out) - - def test_openrc_html_evil_shell_backslash_escape(self): - context = { - "user": FakeUser(), - "tenant_id": "some-cool-id", - "auth_url": "http://tests.com", - "tenant_name": 'o\"; sudo rm -rf /'} - out = loader.render_to_string( - 'project/api_access/openrc.sh.template', - context, - template.Context(context)) - - self.assertNotIn('o\"', out) - self.assertNotIn('o"', out) - self.assertIn('\\"', out) - - def test_openrc_set_region(self): - context = { - "user": FakeUser(), - "tenant_id": "some-cool-id", - "auth_url": "http://tests.com", - "tenant_name": "Tenant", - "region": "Colorado"} - out = loader.render_to_string( - 'project/api_access/openrc.sh.template', - context, - template.Context(context)) - - self.assertIn("OS_REGION_NAME=\"Colorado\"", out) - - def test_openrc_region_not_set(self): - context = { - "user": FakeUser(), - "tenant_id": "some-cool-id", - "auth_url": "http://tests.com", - "tenant_name": "Tenant"} - out = loader.render_to_string( - 'project/api_access/openrc.sh.template', - context, - template.Context(context)) - - self.assertIn("OS_REGION_NAME=\"\"", out) - - def test_clouds_yaml_set_region(self): - context = { - "cloud_name": "openstack", - "user": FakeUser(), - "tenant_id": "some-cool-id", - "auth_url": "http://example.com", - "tenant_name": "Tenant", - "region": "Colorado"} - out = yaml.load(loader.render_to_string( - 'project/api_access/clouds.yaml.template', - context, - template.Context(context))) - - self.assertIn('clouds', out) - self.assertIn('openstack', out['clouds']) - self.assertNotIn('profile', out['clouds']['openstack']) - self.assertEqual( - "http://example.com", - out['clouds']['openstack']['auth']['auth_url']) - self.assertEqual("Colorado", out['clouds']['openstack']['region_name']) - self.assertNotIn('regions', out['clouds']['openstack']) - - def test_clouds_yaml_region_not_set(self): - context = { - "cloud_name": "openstack", - "user": FakeUser(), - "tenant_id": "some-cool-id", - "auth_url": "http://example.com", - "tenant_name": "Tenant"} - out = yaml.load(loader.render_to_string( - 'project/api_access/clouds.yaml.template', - context, - template.Context(context))) - - self.assertIn('clouds', out) - self.assertIn('openstack', out['clouds']) - self.assertNotIn('profile', out['clouds']['openstack']) - self.assertEqual( - "http://example.com", - out['clouds']['openstack']['auth']['auth_url']) - self.assertNotIn('region_name', out['clouds']['openstack']) - self.assertNotIn('regions', out['clouds']['openstack']) - - def test_clouds_yaml_regions(self): - regions = ['region1', 'region2'] - context = { - "cloud_name": "openstack", - "user": FakeUser(), - "tenant_id": "some-cool-id", - "auth_url": "http://example.com", - "tenant_name": "Tenant", - "regions": regions} - out = yaml.load(loader.render_to_string( - 'project/api_access/clouds.yaml.template', - context, - template.Context(context))) - - self.assertIn('clouds', out) - self.assertIn('openstack', out['clouds']) - self.assertNotIn('profile', out['clouds']['openstack']) - self.assertEqual( - "http://example.com", - out['clouds']['openstack']['auth']['auth_url']) - self.assertNotIn('region_name', out['clouds']['openstack']) - self.assertIn('regions', out['clouds']['openstack']) - self.assertEqual(regions, out['clouds']['openstack']['regions']) - - def test_clouds_yaml_profile(self): - regions = ['region1', 'region2'] - context = { - "cloud_name": "openstack", - "user": FakeUser(), - "profile": "example", - "tenant_id": "some-cool-id", - "auth_url": "http://example.com", - "tenant_name": "Tenant", - "regions": regions} - out = yaml.load(loader.render_to_string( - 'project/api_access/clouds.yaml.template', - context, - template.Context(context))) - - self.assertIn('clouds', out) - self.assertIn('openstack', out['clouds']) - self.assertIn('profile', out['clouds']['openstack']) - self.assertEqual('example', out['clouds']['openstack']['profile']) - self.assertNotIn('auth_url', out['clouds']['openstack']['auth']) - self.assertNotIn('region_name', out['clouds']['openstack']) - self.assertNotIn('regions', out['clouds']['openstack']) diff --git a/openstack_dashboard/test/tests/__init__.py b/openstack_dashboard/test/unit/__init__.py similarity index 100% rename from openstack_dashboard/test/tests/__init__.py rename to openstack_dashboard/test/unit/__init__.py diff --git a/openstack_dashboard/test/unit/api/__init__.py b/openstack_dashboard/test/unit/api/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/openstack_dashboard/test/unit/api/rest/__init__.py b/openstack_dashboard/test/unit/api/rest/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/openstack_dashboard/test/api_tests/cinder_rest_tests.py b/openstack_dashboard/test/unit/api/rest/test_cinder.py similarity index 100% rename from openstack_dashboard/test/api_tests/cinder_rest_tests.py rename to openstack_dashboard/test/unit/api/rest/test_cinder.py diff --git a/openstack_dashboard/test/api_tests/config_rest_tests.py b/openstack_dashboard/test/unit/api/rest/test_config.py similarity index 100% rename from openstack_dashboard/test/api_tests/config_rest_tests.py rename to openstack_dashboard/test/unit/api/rest/test_config.py diff --git a/openstack_dashboard/test/api_tests/glance_rest_tests.py b/openstack_dashboard/test/unit/api/rest/test_glance.py similarity index 100% rename from openstack_dashboard/test/api_tests/glance_rest_tests.py rename to openstack_dashboard/test/unit/api/rest/test_glance.py diff --git a/openstack_dashboard/test/api_tests/keystone_rest_tests.py b/openstack_dashboard/test/unit/api/rest/test_keystone.py similarity index 100% rename from openstack_dashboard/test/api_tests/keystone_rest_tests.py rename to openstack_dashboard/test/unit/api/rest/test_keystone.py diff --git a/openstack_dashboard/test/api_tests/network_rest_tests.py b/openstack_dashboard/test/unit/api/rest/test_network.py similarity index 100% rename from openstack_dashboard/test/api_tests/network_rest_tests.py rename to openstack_dashboard/test/unit/api/rest/test_network.py diff --git a/openstack_dashboard/test/api_tests/neutron_rest_tests.py b/openstack_dashboard/test/unit/api/rest/test_neutron.py similarity index 100% rename from openstack_dashboard/test/api_tests/neutron_rest_tests.py rename to openstack_dashboard/test/unit/api/rest/test_neutron.py diff --git a/openstack_dashboard/test/api_tests/nova_rest_tests.py b/openstack_dashboard/test/unit/api/rest/test_nova.py similarity index 100% rename from openstack_dashboard/test/api_tests/nova_rest_tests.py rename to openstack_dashboard/test/unit/api/rest/test_nova.py diff --git a/openstack_dashboard/test/api_tests/policy_rest_tests.py b/openstack_dashboard/test/unit/api/rest/test_policy.py similarity index 100% rename from openstack_dashboard/test/api_tests/policy_rest_tests.py rename to openstack_dashboard/test/unit/api/rest/test_policy.py diff --git a/openstack_dashboard/test/api_tests/swift_rest_tests.py b/openstack_dashboard/test/unit/api/rest/test_swift.py similarity index 100% rename from openstack_dashboard/test/api_tests/swift_rest_tests.py rename to openstack_dashboard/test/unit/api/rest/test_swift.py diff --git a/openstack_dashboard/test/api_tests/rest_util_tests.py b/openstack_dashboard/test/unit/api/rest/test_utils.py similarity index 100% rename from openstack_dashboard/test/api_tests/rest_util_tests.py rename to openstack_dashboard/test/unit/api/rest/test_utils.py diff --git a/openstack_dashboard/test/api_tests/base_tests.py b/openstack_dashboard/test/unit/api/test_base.py similarity index 100% rename from openstack_dashboard/test/api_tests/base_tests.py rename to openstack_dashboard/test/unit/api/test_base.py diff --git a/openstack_dashboard/test/api_tests/cinder_tests.py b/openstack_dashboard/test/unit/api/test_cinder.py similarity index 100% rename from openstack_dashboard/test/api_tests/cinder_tests.py rename to openstack_dashboard/test/unit/api/test_cinder.py diff --git a/openstack_dashboard/test/api_tests/glance_tests.py b/openstack_dashboard/test/unit/api/test_glance.py similarity index 100% rename from openstack_dashboard/test/api_tests/glance_tests.py rename to openstack_dashboard/test/unit/api/test_glance.py diff --git a/openstack_dashboard/test/api_tests/keystone_tests.py b/openstack_dashboard/test/unit/api/test_keystone.py similarity index 100% rename from openstack_dashboard/test/api_tests/keystone_tests.py rename to openstack_dashboard/test/unit/api/test_keystone.py diff --git a/openstack_dashboard/test/api_tests/network_tests.py b/openstack_dashboard/test/unit/api/test_network.py similarity index 100% rename from openstack_dashboard/test/api_tests/network_tests.py rename to openstack_dashboard/test/unit/api/test_network.py diff --git a/openstack_dashboard/test/api_tests/neutron_tests.py b/openstack_dashboard/test/unit/api/test_neutron.py similarity index 100% rename from openstack_dashboard/test/api_tests/neutron_tests.py rename to openstack_dashboard/test/unit/api/test_neutron.py diff --git a/openstack_dashboard/test/api_tests/nova_tests.py b/openstack_dashboard/test/unit/api/test_nova.py similarity index 100% rename from openstack_dashboard/test/api_tests/nova_tests.py rename to openstack_dashboard/test/unit/api/test_nova.py diff --git a/openstack_dashboard/test/api_tests/swift_tests.py b/openstack_dashboard/test/unit/api/test_swift.py similarity index 100% rename from openstack_dashboard/test/api_tests/swift_tests.py rename to openstack_dashboard/test/unit/api/test_swift.py diff --git a/openstack_dashboard/test/tests/error_pages.py b/openstack_dashboard/test/unit/test_error_pages.py similarity index 100% rename from openstack_dashboard/test/tests/error_pages.py rename to openstack_dashboard/test/unit/test_error_pages.py diff --git a/openstack_dashboard/test/tests/policy_backend.py b/openstack_dashboard/test/unit/test_policy.py similarity index 88% rename from openstack_dashboard/test/tests/policy_backend.py rename to openstack_dashboard/test/unit/test_policy.py index b1eec4803f..b3ac2094bb 100644 --- a/openstack_dashboard/test/tests/policy_backend.py +++ b/openstack_dashboard/test/unit/test_policy.py @@ -1,3 +1,4 @@ +# # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at @@ -17,6 +18,20 @@ from openstack_dashboard import policy from openstack_dashboard.test import helpers as test +class PolicyTestCase(test.TestCase): + @override_settings(POLICY_CHECK_FUNCTION='openstack_auth.policy.check') + def test_policy_check_set(self): + value = policy.check((("identity", "admin_required"),), + request=self.request) + self.assertFalse(value) + + @override_settings(POLICY_CHECK_FUNCTION=None) + def test_policy_check_not_set(self): + value = policy.check((("identity", "admin_required"),), + request=self.request) + self.assertTrue(value) + + class PolicyBackendTestCase(test.TestCase): def test_policy_file_load(self): policy_backend.reset() diff --git a/openstack_dashboard/test/themes.py b/openstack_dashboard/test/unit/test_themes.py similarity index 100% rename from openstack_dashboard/test/themes.py rename to openstack_dashboard/test/unit/test_themes.py diff --git a/openstack_dashboard/test/views.py b/openstack_dashboard/test/unit/test_views.py similarity index 100% rename from openstack_dashboard/test/views.py rename to openstack_dashboard/test/unit/test_views.py diff --git a/openstack_dashboard/test/unit/usage/__init__.py b/openstack_dashboard/test/unit/usage/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/openstack_dashboard/test/tests/quotas.py b/openstack_dashboard/test/unit/usage/test_quotas.py similarity index 100% rename from openstack_dashboard/test/tests/quotas.py rename to openstack_dashboard/test/unit/usage/test_quotas.py diff --git a/openstack_dashboard/test/unit/utils/__init__.py b/openstack_dashboard/test/unit/utils/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/openstack_dashboard/test/tests/utils.py b/openstack_dashboard/test/unit/utils/test_config_types.py similarity index 70% rename from openstack_dashboard/test/tests/utils.py rename to openstack_dashboard/test/unit/utils/test_config_types.py index 9534019923..2893eeb30c 100644 --- a/openstack_dashboard/test/tests/utils.py +++ b/openstack_dashboard/test/unit/utils/test_config_types.py @@ -1,6 +1,3 @@ -# Copyright (c) 2013 OpenStack Foundation -# All Rights Reserved. -# # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at @@ -15,31 +12,7 @@ import unittest -from oslo_utils import uuidutils - from openstack_dashboard.utils import config_types -from openstack_dashboard.utils import filters - - -class UtilsFilterTests(unittest.TestCase): - def test_accept_valid_integer(self): - val = 100 - ret = filters.get_int_or_uuid(val) - self.assertEqual(val, ret) - - def test_accept_valid_integer_string(self): - val = '100' - ret = filters.get_int_or_uuid(val) - self.assertEqual(int(val), ret) - - def test_accept_valid_uuid(self): - val = uuidutils.generate_uuid() - ret = filters.get_int_or_uuid(val) - self.assertEqual(val, ret) - - def test_reject_random_string(self): - val = '55WbJTpJDf' - self.assertRaises(ValueError, filters.get_int_or_uuid, val) class ConfigTypesTest(unittest.TestCase): diff --git a/openstack_dashboard/test/unit/utils/test_filters.py b/openstack_dashboard/test/unit/utils/test_filters.py new file mode 100644 index 0000000000..e6bfff252b --- /dev/null +++ b/openstack_dashboard/test/unit/utils/test_filters.py @@ -0,0 +1,41 @@ +# Copyright (c) 2013 OpenStack Foundation +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import unittest + +from oslo_utils import uuidutils + +from openstack_dashboard.utils import filters + + +class UtilsFilterTests(unittest.TestCase): + def test_accept_valid_integer(self): + val = 100 + ret = filters.get_int_or_uuid(val) + self.assertEqual(val, ret) + + def test_accept_valid_integer_string(self): + val = '100' + ret = filters.get_int_or_uuid(val) + self.assertEqual(int(val), ret) + + def test_accept_valid_uuid(self): + val = uuidutils.generate_uuid() + ret = filters.get_int_or_uuid(val) + self.assertEqual(val, ret) + + def test_reject_random_string(self): + val = '55WbJTpJDf' + self.assertRaises(ValueError, filters.get_int_or_uuid, val)