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
This commit is contained in:
Matt Borland 2015-02-18 13:03:02 -07:00
parent 36e87c6b75
commit e168c95678
7 changed files with 230 additions and 1 deletions

View File

@ -0,0 +1,15 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Jasmine Spec Runner Index</title>
</head>
<h1>Available tests</h1>
<ul>
{% for class_name in classes %}
<li><a href="{{ class_name }}">{{ class_name }}</a></li>
{% endfor %}
</ul>
<body>
</body>
</html>

View File

@ -0,0 +1,84 @@
{% load url from future %}
<!DOCTYPE html>
<html>
<head>
<title>Jasmine Spec Runner</title>
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}horizon/lib/jasmine/jasmine.css">
<script src="{% url 'horizon:jsi18n' 'horizon' %}"></script>
<script src="{{ STATIC_URL }}horizon/lib/jasmine/jasmine.js"></script>
<script src="{{ STATIC_URL }}horizon/lib/jasmine/jasmine-html.js"></script>
<script src="{{ STATIC_URL }}horizon/lib/jasmine/boot.js"></script>
<script src='{{ STATIC_URL }}horizon/lib/jquery/jquery.js'></script>
<script src="{{ STATIC_URL }}horizon/lib/angular/angular.js"></script>
<script src="{{ STATIC_URL }}horizon/lib/angular/angular-mocks.js"></script>
<script src="{{ STATIC_URL }}horizon/lib/angular/angular-cookies.js"></script>
<script src="{{ STATIC_URL }}horizon/lib/angular/angular-bootstrap.js"></script>
<script src="{{ STATIC_URL }}horizon/lib/smart-table/smart-table.js"></script>
<script type="text/javascript">
/* Load angular modules extensions list before we include angular/horizon.js */
var angularModuleExtension = {{ HORIZON_CONFIG.angular_modules|default:"[]"|safe }};
</script>
<!-- source files -->
{% for file in sources %}
<script src="{{ STATIC_URL }}{{ file }}"></script>
{% endfor %}
<!-- spec files -->
{% for file in specs %}
<script src="{{ STATIC_URL }}{{ file }}"></script>
{% endfor %}
<!-- plugin source files -->
{% for file in HORIZON_CONFIG.js_files %}
<script src='{{ STATIC_URL }}{{ file }}'></script>
{% endfor %}
<!-- plugin spec files -->
{% for file in HORIZON_CONFIG.js_spec_files %}
<script src='{{ STATIC_URL }}{{ file }}'></script>
{% endfor %}
</head>
<body>
<div id="main_content" class="hidden" style="visibility:hidden; height: 0">
{% block content %}
{% endblock %}
</div>
<script type="text/javascript">
(function () { 'use strict';
// Caching all external angular templates
var templates = [
{% for externalTemplate in externalTemplates %}
'{{ STATIC_URL }}{{ externalTemplate }}',
{% endfor %}
];
var tplmodule = angular.module('templates', []);
templates.forEach(function (template) {
cacheTemplate(template, tplmodule);
});
function cacheTemplate(template, tplmodule) {
tplmodule.run(function ($templateCache) {
$templateCache.put(template, loadSync(template));
});
}
function loadSync(url) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, false);
xhr.send();
return xhr.status === 200 ? xhr.responseText : null;
}
})();
</script>
</body>
</html>

View File

@ -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)

View File

@ -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 = [
]

View File

@ -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'),
)

View File

@ -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')
)