Add test infrastructure for QUnit tests
With a single example failing test. The tests are only available when debug is enabled. Change-Id: I2f3b2933d3cf3c8bf4343dfd57e3da8d356bd32b
This commit is contained in:
parent
40b15ad3ec
commit
3e4c1fe168
52
test/selenium.py
Normal file
52
test/selenium.py
Normal file
@ -0,0 +1,52 @@
|
||||
#
|
||||
# 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 __future__ import absolute_import
|
||||
|
||||
import logging
|
||||
|
||||
from horizon.test import helpers
|
||||
from selenium.common import exceptions as selenium_exceptions
|
||||
|
||||
|
||||
class BrowserTests(helpers.SeleniumTestCase):
|
||||
def test_qunit(self):
|
||||
url = "%s%s" % (self.live_server_url, "/infrastructure/qunit-tuskar-boxes/")
|
||||
self.selenium.get(url)
|
||||
wait = self.ui.WebDriverWait(self.selenium, 10)
|
||||
|
||||
def qunit_done(driver):
|
||||
text = driver.find_element_by_id("qunit-testresult").text
|
||||
return "Tests completed" in text
|
||||
|
||||
wait.until(qunit_done)
|
||||
|
||||
failed_elem = self.selenium.find_element_by_class_name("failed")
|
||||
failed = int(failed_elem.text)
|
||||
if failed:
|
||||
self.log_failure_messages()
|
||||
self.assertEqual(failed, 0)
|
||||
|
||||
def log_failure_messages(self):
|
||||
logger = logging.getLogger('selenium')
|
||||
logger.error("Errors found during qunit test:")
|
||||
fail_elems = self.selenium.find_elements_by_class_name("fail")
|
||||
for elem in fail_elems:
|
||||
try:
|
||||
module = elem.find_element_by_class_name("module-name").text
|
||||
except selenium_exceptions.NoSuchElementException:
|
||||
continue
|
||||
message = elem.find_element_by_class_name("test-message").text
|
||||
source = elem.find_element_by_tag_name("pre").text
|
||||
logger.error("Module: %s, message: %s, source: %s" % (
|
||||
module, message, source))
|
@ -12,7 +12,9 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from django.conf import settings
|
||||
from django.conf import urls
|
||||
from django.views import generic
|
||||
from tuskar_ui.infrastructure.overview import urls as tuskar_urls
|
||||
|
||||
import tuskar_boxes.overview.views as views
|
||||
@ -23,3 +25,9 @@ urlpatterns.extend(urls.patterns(
|
||||
'',
|
||||
urls.url(r'^$', views.IndexView.as_view(), name='index'),
|
||||
))
|
||||
|
||||
if settings.DEBUG:
|
||||
urlpatterns.append(urls.url(
|
||||
r'^qunit-tuskar-boxes$',
|
||||
generic.TemplateView.as_view(template_name="tuskar_boxes/qunit.html"),
|
||||
))
|
||||
|
9
tuskar_boxes/static/tuskar_boxes/tests/tuskar.boxes.js
Normal file
9
tuskar_boxes/static/tuskar_boxes/tests/tuskar.boxes.js
Normal file
@ -0,0 +1,9 @@
|
||||
horizon.addInitFunction(function () {
|
||||
"use strict";
|
||||
|
||||
module("Tuskar boxes (tuskar.boxes.js)");
|
||||
|
||||
test("Passing test", function () {
|
||||
equal(1, 1);
|
||||
});
|
||||
});
|
26
tuskar_boxes/templates/tuskar_boxes/qunit.html
Normal file
26
tuskar_boxes/templates/tuskar_boxes/qunit.html
Normal file
@ -0,0 +1,26 @@
|
||||
<!DOCTYPE html>
|
||||
<html><head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>Tuskar-UI Extras QUnit Test Suite</title>
|
||||
<link rel="stylesheet" href="{{ STATIC_URL }}horizon/lib/qunit/qunit.css" type="text/css" media="screen">
|
||||
<script type="text/javascript" src="{{ STATIC_URL }}horizon/lib/jquery/jquery.js"></script>
|
||||
<script type="text/javascript" src="{{ STATIC_URL }}horizon/lib/qunit/qunit.js"></script>
|
||||
{% include "horizon/_conf.html" %}
|
||||
|
||||
{% comment %}Load test modules here.{% endcomment %}
|
||||
<script type="text/javascript" src="{{ STATIC_URL }}tuskar_boxes/tests/tuskar.boxes.js"></script>
|
||||
{% comment %}End test modules.{% endcomment %}
|
||||
|
||||
{% include "horizon/_scripts.html" %}
|
||||
{% include "infrastructure/_scripts.html" %}
|
||||
<script type="text/javascript" src="{{ STATIC_URL }}tuskar_boxes/js/tuskar.boxes.js"></script>
|
||||
<script type="text/javascript" src="{{ STATIC_URL }}tuskar_boxes/js/tuskar.boxes_progress.js"></script>
|
||||
</head><body ng-app="hz">
|
||||
<h1 id="qunit-header">Tuskar-UI Extras JavaScript Tests</h1>
|
||||
<h2 id="qunit-banner"></h2>
|
||||
<div id="qunit-testrunner-toolbar"></div>
|
||||
<h2 id="qunit-userAgent"></h2>
|
||||
<ol id="qunit-tests"></ol>
|
||||
<div id="qunit-fixture">
|
||||
</div>
|
||||
</body></html>
|
Loading…
Reference in New Issue
Block a user