Merge "openstack_dashboard: Move test files to match module structure"
This commit is contained in:
commit
58e18f0790
@ -12,14 +12,16 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from mox3.mox import IsA
|
||||||
import six
|
import six
|
||||||
|
import yaml
|
||||||
|
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from django.http import HttpRequest
|
from django.http import HttpRequest
|
||||||
|
from django import template
|
||||||
|
from django.template import loader
|
||||||
from django.test.utils import override_settings
|
from django.test.utils import override_settings
|
||||||
|
|
||||||
from mox3.mox import IsA
|
|
||||||
|
|
||||||
from openstack_dashboard import api
|
from openstack_dashboard import api
|
||||||
from openstack_dashboard.test import helpers as test
|
from openstack_dashboard.test import helpers as test
|
||||||
|
|
||||||
@ -202,3 +204,171 @@ class UnicodeTenantNameRCTests(test.TestCase):
|
|||||||
encode('latin-1')
|
encode('latin-1')
|
||||||
self.assertEqual(expected,
|
self.assertEqual(expected,
|
||||||
result_content_disposition)
|
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'])
|
||||||
|
@ -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)
|
|
@ -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'])
|
|
0
openstack_dashboard/test/unit/api/__init__.py
Normal file
0
openstack_dashboard/test/unit/api/__init__.py
Normal file
0
openstack_dashboard/test/unit/api/rest/__init__.py
Normal file
0
openstack_dashboard/test/unit/api/rest/__init__.py
Normal file
@ -1,3 +1,4 @@
|
|||||||
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# 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
|
# not use this file except in compliance with the License. You may obtain
|
||||||
# a copy of the License at
|
# a copy of the License at
|
||||||
@ -17,6 +18,20 @@ from openstack_dashboard import policy
|
|||||||
from openstack_dashboard.test import helpers as test
|
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):
|
class PolicyBackendTestCase(test.TestCase):
|
||||||
def test_policy_file_load(self):
|
def test_policy_file_load(self):
|
||||||
policy_backend.reset()
|
policy_backend.reset()
|
0
openstack_dashboard/test/unit/usage/__init__.py
Normal file
0
openstack_dashboard/test/unit/usage/__init__.py
Normal file
0
openstack_dashboard/test/unit/utils/__init__.py
Normal file
0
openstack_dashboard/test/unit/utils/__init__.py
Normal file
@ -1,6 +1,3 @@
|
|||||||
# Copyright (c) 2013 OpenStack Foundation
|
|
||||||
# All Rights Reserved.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# 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
|
# not use this file except in compliance with the License. You may obtain
|
||||||
# a copy of the License at
|
# a copy of the License at
|
||||||
@ -15,31 +12,7 @@
|
|||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from oslo_utils import uuidutils
|
|
||||||
|
|
||||||
from openstack_dashboard.utils import config_types
|
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):
|
class ConfigTypesTest(unittest.TestCase):
|
41
openstack_dashboard/test/unit/utils/test_filters.py
Normal file
41
openstack_dashboard/test/unit/utils/test_filters.py
Normal file
@ -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)
|
Loading…
Reference in New Issue
Block a user