From e168c956786a00772edb3d1128bc1938c03a1388 Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Wed, 18 Feb 2015 13:03:02 -0700 Subject: [PATCH] Base dashboard Jasmine framework Establishes Jasmine testing features in openstack_dashboard, similar to the features in horizon. These features allow components specific to openstack_dashboard to be tested. Partially Implements: blueprint launch-instance-redesign Change-Id: I1f996e97f5cd01c9c32d7874eb5c0668d67e24bd --- .../templates/jasmine/index.html | 15 ++++ .../templates/jasmine/jasmine.html | 84 +++++++++++++++++++ openstack_dashboard/test/jasmine/__init__.py | 0 openstack_dashboard/test/jasmine/jasmine.py | 50 +++++++++++ .../test/jasmine/jasmine_tests.py | 28 +++++++ openstack_dashboard/test/settings.py | 2 +- openstack_dashboard/test/urls.py | 52 ++++++++++++ 7 files changed, 230 insertions(+), 1 deletion(-) create mode 100644 openstack_dashboard/templates/jasmine/index.html create mode 100644 openstack_dashboard/templates/jasmine/jasmine.html create mode 100644 openstack_dashboard/test/jasmine/__init__.py create mode 100644 openstack_dashboard/test/jasmine/jasmine.py create mode 100644 openstack_dashboard/test/jasmine/jasmine_tests.py create mode 100644 openstack_dashboard/test/urls.py diff --git a/openstack_dashboard/templates/jasmine/index.html b/openstack_dashboard/templates/jasmine/index.html new file mode 100644 index 000000000..3082deb73 --- /dev/null +++ b/openstack_dashboard/templates/jasmine/index.html @@ -0,0 +1,15 @@ + + + + Jasmine Spec Runner Index + +

Available tests

+ + + + diff --git a/openstack_dashboard/templates/jasmine/jasmine.html b/openstack_dashboard/templates/jasmine/jasmine.html new file mode 100644 index 000000000..aa34f8e03 --- /dev/null +++ b/openstack_dashboard/templates/jasmine/jasmine.html @@ -0,0 +1,84 @@ +{% load url from future %} + + + + Jasmine Spec Runner + + + + + + + + + + + + + + + + + {% for file in sources %} + + {% endfor %} + + + {% for file in specs %} + + {% endfor %} + + + {% for file in HORIZON_CONFIG.js_files %} + + {% endfor %} + + + {% for file in HORIZON_CONFIG.js_spec_files %} + + {% endfor %} + + + + + + + + diff --git a/openstack_dashboard/test/jasmine/__init__.py b/openstack_dashboard/test/jasmine/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/openstack_dashboard/test/jasmine/jasmine.py b/openstack_dashboard/test/jasmine/jasmine.py new file mode 100644 index 000000000..102b78945 --- /dev/null +++ b/openstack_dashboard/test/jasmine/jasmine.py @@ -0,0 +1,50 @@ +# +# (c) Copyright 2015 Hewlett-Packard Development Company, L.P. +# +# 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 inspect +import sys + +import django.shortcuts +import django.views.defaults + + +def dispatcher(request, test_name): + # import is included in this non-standard location to avoid + # problems importing mox. See bug/1288245 + from openstack_dashboard.test.jasmine import jasmine_tests as tests + classes = inspect.getmembers(sys.modules[tests.__name__], + inspect.isclass) + + if not test_name: + return django.shortcuts.render( + request, + "jasmine/index.html", + {'classes': (cls_name for cls_name, _ in classes)} + ) + else: + for cls_name, cls in classes: + if cls_name == test_name: + template = cls.template_name + + if not template: + template = "jasmine/jasmine.html" + + return django.shortcuts.render( + request, + template, + {'specs': cls.specs, 'sources': cls.sources, + 'externalTemplates': cls.externalTemplates}) + + return django.views.defaults.page_not_found(request) diff --git a/openstack_dashboard/test/jasmine/jasmine_tests.py b/openstack_dashboard/test/jasmine/jasmine_tests.py new file mode 100644 index 000000000..368776b4d --- /dev/null +++ b/openstack_dashboard/test/jasmine/jasmine_tests.py @@ -0,0 +1,28 @@ +# +# (c) Copyright 2015 Hewlett-Packard Development Company, L.P. +# +# 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 horizon.test import helpers as test + + +class ServicesTests(test.JasmineTests): + # sources would go here + sources = [ + ] + # spec files would go here + specs = [ + ] + externalTemplates = [ + ] diff --git a/openstack_dashboard/test/settings.py b/openstack_dashboard/test/settings.py index 642b59c15..14e95b73a 100644 --- a/openstack_dashboard/test/settings.py +++ b/openstack_dashboard/test/settings.py @@ -23,7 +23,7 @@ STATIC_ROOT = os.path.abspath(os.path.join(ROOT_PATH, '..', 'static')) SECRET_KEY = secret_key.generate_or_read_from_file( os.path.join(TEST_DIR, '.secret_key_store')) -ROOT_URLCONF = 'openstack_dashboard.urls' +ROOT_URLCONF = 'openstack_dashboard.test.urls' TEMPLATE_DIRS = ( os.path.join(TEST_DIR, 'templates'), ) diff --git a/openstack_dashboard/test/urls.py b/openstack_dashboard/test/urls.py new file mode 100644 index 000000000..79552c946 --- /dev/null +++ b/openstack_dashboard/test/urls.py @@ -0,0 +1,52 @@ +# +# (c) Copyright 2015 Hewlett-Packard Development Company, L.P. +# +# 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. + +""" +URL patterns for the OpenStack Dashboard. +""" + +from django.conf import settings +from django.conf.urls import include +from django.conf.urls import patterns +from django.conf.urls.static import static # noqa +from django.conf.urls import url +from django.contrib.staticfiles.urls import staticfiles_urlpatterns # noqa + +from openstack_dashboard.test.jasmine import jasmine + +import horizon + +urlpatterns = patterns( + '', + url(r'^$', 'openstack_dashboard.views.splash', name='splash'), + url(r'^auth/', include('openstack_auth.urls')), + url(r'^api/', include('openstack_dashboard.api.rest.urls')), + url(r'^jasmine/(.*?)$', jasmine.dispatcher), + url(r'', include(horizon.urls)), +) + +# Development static app and project media serving using the staticfiles app. +urlpatterns += staticfiles_urlpatterns() + +# Convenience function for serving user-uploaded media during +# development. Only active if DEBUG==True and the URL prefix is a local +# path. Production media should NOT be served by Django. +urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + +if settings.DEBUG: + urlpatterns += patterns( + '', + url(r'^500/$', 'django.views.defaults.server_error') + )