Changes to work with api keystone. Changes for tests

This commit is contained in:
Rob Raymond 2014-06-30 11:04:59 -06:00
parent 1afb03ff0f
commit 48e19d9bbc
11 changed files with 192 additions and 14 deletions

View File

@ -22,4 +22,3 @@ import horizon
class Monitoring(horizon.Panel):
name = _("Alarms")
slug = 'alarms'
permissions = ('openstack.roles.admin', )

View File

@ -34,12 +34,10 @@ def monclient(request, password=None):
cacert = getattr(settings, 'OPENSTACK_SSL_CACERT', None)
endpoint = getattr(settings, 'MONITORING_ENDPOINT',
'http://192.168.10.4:8080/v2.0')
project_id = getattr(settings, 'MONITORING_PROJECT',
'82510970543135')
LOG.debug('monclient connection created using token "%s" and url "%s"' %
(request.user.token.id, endpoint))
kwargs = {
'token': project_id, # workaround API should be request.user.token.id
'token': request.user.token.id,
'insecure': insecure,
'ca_file': cacert,
'username': request.user.username,

View File

@ -22,4 +22,3 @@ import horizon
class Notifications(horizon.Panel):
name = _("Notifications")
slug = 'notifications'
permissions = ('openstack.roles.admin', )

View File

@ -0,0 +1,82 @@
#
# 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 os
import warnings
from django.core.handlers import wsgi
from django.utils import unittest
from monitoring.test.test_data import utils as test_data_utils
from openstack_dashboard.test import helpers as openstack_dashboard_helpers
# Makes output of failing mox tests much easier to read.
wsgi.WSGIRequest.__repr__ = lambda self: "<class 'django.http.HttpRequest'>"
# Silences the warning about with statements.
warnings.filterwarnings('ignore', 'With-statements now directly support '
'multiple context managers', DeprecationWarning,
r'^tuskar_ui[.].*[._]tests$')
def create_stubs(stubs_to_create={}):
return openstack_dashboard_helpers.create_stubs(stubs_to_create)
@unittest.skipIf(os.environ.get('SKIP_UNITTESTS', False),
"The SKIP_UNITTESTS env variable is set.")
class TestCase(openstack_dashboard_helpers.TestCase):
"""Specialized base test case class for Horizon which gives access to
numerous additional features:
* A full suite of test data through various attached objects and
managers (e.g. ``self.servers``, ``self.user``, etc.). See the
docs for :class:`~horizon.tests.test_data.utils.TestData` for more
information.
* The ``mox`` mocking framework via ``self.mox``.
* A set of request context data via ``self.context``.
* A ``RequestFactory`` class which supports Django's ``contrib.messages``
framework via ``self.factory``.
* A ready-to-go request object via ``self.request``.
* The ability to override specific time data controls for easier testing.
* Several handy additional assertion methods.
"""
def setUp(self):
super(TestCase, self).setUp()
# load tuskar-specific test data
test_data_utils.load_test_data(self)
class BaseAdminViewTests(openstack_dashboard_helpers.BaseAdminViewTests):
"""A ``TestCase`` subclass which sets an active user with the "admin" role
for testing admin-only views and functionality.
"""
def setUp(self):
super(BaseAdminViewTests, self).setUp()
# load tuskar-specific test data
test_data_utils.load_test_data(self)
class APITestCase(openstack_dashboard_helpers.APITestCase):
"""The ``APITestCase`` class is for use with tests which deal with the
underlying clients rather than stubbing out the
openstack_dashboard.api.* methods.
"""
def setUp(self):
super(APITestCase, self).setUp()
# load tuskar-specfic test data
test_data_utils.load_test_data(self)

View File

@ -32,7 +32,7 @@ STATIC_URL = '/static/'
SECRET_KEY = secret_key_utils.generate_or_read_from_file(
os.path.join(TEST_DIR, '.secret_key_store'))
ROOT_URLCONF = 'tuskar_ui.test.urls'
ROOT_URLCONF = 'monitoring.test.urls'
TEMPLATE_DIRS = (
os.path.join(TEST_DIR, 'templates'),
)

View File

View File

@ -0,0 +1,23 @@
#
# 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 monclient.openstack.common.apiclient import exceptions as monclient
from openstack_dashboard.test.test_data import exceptions
def data(TEST):
TEST.exceptions = exceptions.data
monitoring_exception = monclient.ClientException
TEST.exceptions.monitoring = exceptions.create_stubbed_exception(
monitoring_exception)

View File

@ -0,0 +1,15 @@
# 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.
def data(TEST):
pass

View File

@ -0,0 +1,43 @@
#
# 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 openstack_dashboard.test.test_data import utils
def load_test_data(load_onto=None):
from monitoring.test.test_data import exceptions
from monitoring.test.test_data import monitoring_data
from openstack_dashboard.test.test_data import cinder_data
from openstack_dashboard.test.test_data import glance_data
from openstack_dashboard.test.test_data import heat_data
from openstack_dashboard.test.test_data import keystone_data
from openstack_dashboard.test.test_data import neutron_data
from openstack_dashboard.test.test_data import nova_data
from openstack_dashboard.test.test_data import swift_data
# The order of these loaders matters, some depend on others.
loaders = (exceptions.data,
keystone_data.data,
glance_data.data,
nova_data.data,
cinder_data.data,
neutron_data.data,
swift_data.data,
heat_data.data,
monitoring_data.data)
if load_onto:
for data_func in loaders:
data_func(load_onto)
return load_onto
else:
return utils.TestData(*loaders)

27
monitoring/test/urls.py Normal file
View File

@ -0,0 +1,27 @@
#
# 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.conf import urls
from django.views import generic
import openstack_dashboard.urls
urlpatterns = urls.patterns(
'',
urls.url(
r'^qunit_tuskar',
generic.TemplateView.as_view(
template_name="infrastructure/qunit.html"),
name='qunit_tests'),
urls.url(r'', urls.include(openstack_dashboard.urls))
)

View File

@ -7,14 +7,6 @@ eventlet>=0.13.0
kombu>=2.4.8
iso8601>=0.1.8
netaddr>=0.7.6
python-cinderclient>=1.0.6
python-glanceclient>=0.9.0
python-heatclient>=0.2.3
python-keystoneclient>=0.4.1
python-novaclient>=2.15.0
python-neutronclient>=2.3.0,<3
python-swiftclient>=1.5
python-ceilometerclient>=1.0.6
pytz>=2010h
# Horizon Utility Requirements
# for SECURE_KEY generation