From cdfb746abe1d6137e1f8a6e349ddf36c68b75ec0 Mon Sep 17 00:00:00 2001 From: Peter Belanyi Date: Wed, 9 Apr 2014 16:20:30 +0200 Subject: [PATCH] Add selenium test-case Add the /qunit_tuskar path to the urls in the test environment and a selenium test-case to run the Javascript qunit tests. Change-Id: I44c253dc3ed8be9743faba1f8691aa941e4ed9dc Partial-Bug: #1282961 --- .../templates/infrastructure/qunit.html | 2 +- tuskar_ui/test/selenium.py | 32 +++++++++++++++++++ tuskar_ui/test/settings.py | 10 +++++- tuskar_ui/test/urls.py | 14 +++++--- 4 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 tuskar_ui/test/selenium.py diff --git a/tuskar_ui/infrastructure/templates/infrastructure/qunit.html b/tuskar_ui/infrastructure/templates/infrastructure/qunit.html index e0e0ba8a2..21f84efd5 100644 --- a/tuskar_ui/infrastructure/templates/infrastructure/qunit.html +++ b/tuskar_ui/infrastructure/templates/infrastructure/qunit.html @@ -4,7 +4,7 @@ Tuskar QUnit Test Suite - + {% include "horizon/_conf.html" %} diff --git a/tuskar_ui/test/selenium.py b/tuskar_ui/test/selenium.py new file mode 100644 index 000000000..d23762429 --- /dev/null +++ b/tuskar_ui/test/selenium.py @@ -0,0 +1,32 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2012 Nebula, Inc. +# +# 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 BrowserTests(test.SeleniumTestCase): + def test_qunit(self): + url = "%s%s" % (self.live_server_url, "/qunit_tuskar/") + 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 = self.selenium.find_element_by_class_name("failed") + self.assertEqual(int(failed.text), 0) diff --git a/tuskar_ui/test/settings.py b/tuskar_ui/test/settings.py index cb60d571c..4fe56457c 100644 --- a/tuskar_ui/test/settings.py +++ b/tuskar_ui/test/settings.py @@ -21,12 +21,20 @@ from horizon.utils import secret_key as secret_key_utils from tuskar_ui import exceptions +DEBUG = True +TEMPLATE_DEBUG = DEBUG + TEST_DIR = os.path.dirname(os.path.abspath(__file__)) ROOT_PATH = os.path.abspath(os.path.join(TEST_DIR, "..")) +MEDIA_ROOT = os.path.abspath(os.path.join(ROOT_PATH, '..', 'media')) +MEDIA_URL = '/media/' +STATIC_ROOT = os.path.abspath(os.path.join(ROOT_PATH, '..', 'static')) +STATIC_URL = '/static/' + SECRET_KEY = secret_key_utils.generate_or_read_from_file( os.path.join(TEST_DIR, '.secret_key_store')) -ROOT_URLCONF = 'openstack_dashboard.urls' +ROOT_URLCONF = 'tuskar_ui.test.urls' TEMPLATE_DIRS = ( os.path.join(TEST_DIR, 'templates'), ) diff --git a/tuskar_ui/test/urls.py b/tuskar_ui/test/urls.py index 08b8a9802..4e6e290f7 100644 --- a/tuskar_ui/test/urls.py +++ b/tuskar_ui/test/urls.py @@ -14,8 +14,14 @@ from django.conf import urls from django.views import generic +import openstack_dashboard.urls -urlpatterns = urls.patterns('', urls.url( - r'^$', - generic.TemplateView.as_view(template_name="infrastructure/qunit.html"), - name='qunit_tests')) +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)) +)