--- a/devtools/qunit.py Thu Dec 03 14:55:10 2015 +0100
+++ b/devtools/qunit.py Thu Dec 03 16:19:03 2015 +0100
@@ -15,6 +15,7 @@
#
# You should have received a copy of the GNU Lesser General Public License along
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>.
+from __future__ import absolute_import
import os, os.path as osp
import errno
@@ -25,12 +26,13 @@
# imported by default to simplify further import statements
from logilab.common.testlib import unittest_main, with_tempdir, InnerTest, Tags
+import webtest.http
import cubicweb
from cubicweb.view import View
from cubicweb.web.controller import Controller
from cubicweb.web.views.staticcontrollers import StaticFileController, STATIC_CONTROLLERS
-from cubicweb.devtools.httptest import CubicWebServerTC
+from cubicweb.devtools import webtest as cwwebtest
class FirefoxHelper(object):
@@ -72,30 +74,32 @@
self.stop()
-class QUnitTestCase(CubicWebServerTC):
+class QUnitTestCase(cwwebtest.CubicWebTestTC):
- tags = CubicWebServerTC.tags | Tags(('qunit',))
+ tags = cwwebtest.CubicWebTestTC.tags | Tags(('qunit',))
# testfile, (dep_a, dep_b)
all_js_tests = ()
def setUp(self):
- self.config.global_set_option('access-control-allow-origin', '*')
super(QUnitTestCase, self).setUp()
self.test_queue = Queue()
class MyQUnitResultController(QUnitResultController):
tc = self
test_queue = self.test_queue
self._qunit_controller = MyQUnitResultController
- self.vreg.register(MyQUnitResultController)
- self.vreg.register(QUnitView)
- self.vreg.register(CWDevtoolsStaticController)
+ self.webapp.app.appli.vreg.register(MyQUnitResultController)
+ self.webapp.app.appli.vreg.register(QUnitView)
+ self.webapp.app.appli.vreg.register(CWDevtoolsStaticController)
+ self.server = webtest.http.StopableWSGIServer.create(self.webapp.app)
+ self.config.global_set_option('base-url', self.server.application_url)
def tearDown(self):
+ self.server.shutdown()
+ self.webapp.app.appli.vreg.unregister(self._qunit_controller)
+ self.webapp.app.appli.vreg.unregister(QUnitView)
+ self.webapp.app.appli.vreg.unregister(CWDevtoolsStaticController)
super(QUnitTestCase, self).tearDown()
- self.vreg.unregister(self._qunit_controller)
- self.vreg.unregister(QUnitView)
- self.vreg.unregister(CWDevtoolsStaticController)
def test_javascripts(self):
for args in self.all_js_tests:
@@ -206,20 +210,15 @@
def call(self, **kwargs):
w = self.w
req = self._cw
- data = {
- 'jquery': req.data_url('jquery.js'),
- 'devtools': req.build_url('devtools'),
- }
w(u'''<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="application/html; charset=UTF-8"/>
<!-- JS lib used as testing framework -->
- <link rel="stylesheet" type="text/css" media="all" href="%(devtools)s/qunit.css" />
- <script src="%(jquery)s" type="text/javascript"></script>
- <script src="%(devtools)s/cwmock.js" type="text/javascript"></script>
- <script src="%(devtools)s/qunit.js" type="text/javascript"></script>'''
- % data)
+ <link rel="stylesheet" type="text/css" media="all" href="/devtools/qunit.css" />
+ <script src="/data/jquery.js" type="text/javascript"></script>
+ <script src="/devtools/cwmock.js" type="text/javascript"></script>
+ <script src="/devtools/qunit.js" type="text/javascript"></script>''')
w(u'<!-- result report tools -->')
w(u'<script type="text/javascript">')
w(u"var BASE_URL = '%s';" % req.base_url())
--- a/web/test/data/static/jstests/test_ajax.js Thu Dec 03 14:55:10 2015 +0100
+++ b/web/test/data/static/jstests/test_ajax.js Thu Dec 03 16:19:03 2015 +0100
@@ -26,7 +26,7 @@
assert.expect(3);
assert.equal($('#qunit-fixture').children().length, 0);
var done = assert.async();
- $('#qunit-fixture').loadxhtml('static/jstests/ajax_url0.html')
+ $('#qunit-fixture').loadxhtml('static/jstests/ajax_url0.html', null, 'GET')
.addCallback(function() {
try {
assert.equal($('#qunit-fixture').children().length, 1);
@@ -43,7 +43,7 @@
var scriptsIncluded = jsSources();
assert.equal(jQuery.inArray('http://foo.js', scriptsIncluded), - 1);
var done = assert.async();
- $('#qunit-fixture').loadxhtml('static/jstests/ajax_url1.html')
+ $('#qunit-fixture').loadxhtml('static/jstests/ajax_url1.html', null, 'GET')
.addCallback(function() {
try {
var origLength = scriptsIncluded.length;
@@ -66,7 +66,7 @@
assert.expect(3);
assert.equal($('#qunit-fixture').children().length, 0);
var done = assert.async();
- var d = $('#qunit-fixture').loadxhtml('static/jstests/ajax_url0.html');
+ var d = $('#qunit-fixture').loadxhtml('static/jstests/ajax_url0.html', null, 'GET');
d.addCallback(function() {
try {
assert.equal($('#qunit-fixture').children().length, 1);
@@ -105,7 +105,7 @@
assert.expect(3);
assert.equal($('#qunit-fixture').children().length, 0);
var done = assert.async();
- var d = $('#qunit-fixture').loadxhtml('static/jstests/ajax_url0.html');
+ var d = $('#qunit-fixture').loadxhtml('static/jstests/ajax_url0.html', null, 'GET');
d.addCallback(function(data, req, arg1, arg2) {
try {
assert.equal(arg1, 'Hello');
@@ -155,7 +155,7 @@
QUnit.test('test addErrback', function (assert) {
assert.expect(1);
var done = assert.async();
- var d = $('#qunit-fixture').loadxhtml('static/jstests/nonexistent.html');
+ var d = $('#qunit-fixture').loadxhtml('static/jstests/nonexistent.html', null, 'GET');
d.addCallback(function() {
// should not be executed
assert.ok(false, "callback is executed");
@@ -173,7 +173,7 @@
assert.expect(3);
var counter = 0;
var done = assert.async();
- var d = $('#qunit-fixture').loadxhtml('static/jstests/ajax_url0.html');
+ var d = $('#qunit-fixture').loadxhtml('static/jstests/ajax_url0.html', null, 'GET');
d.addCallback(function() {
assert.equal(++counter, 1); // should be executed first
});
@@ -198,7 +198,7 @@
/* use endswith because in pytest context we have an absolute path */
assert.ok($('head link').attr('href').endswith('/qunit.css'), 'qunit.css is loaded');
var done = assert.async();
- $('#qunit-fixture').loadxhtml('static/jstests/ajax_url1.html')
+ $('#qunit-fixture').loadxhtml('static/jstests/ajax_url1.html', null, 'GET')
.addCallback(function() {
var origLength = scriptsIncluded.length;
scriptsIncluded = jsSources();
@@ -235,7 +235,7 @@
// check that server-response event on CubicWeb is triggered
events = 'CubicWeb';
});
- $('#qunit-fixture').loadxhtml('static/jstests/ajax_url0.html')
+ $('#qunit-fixture').loadxhtml('static/jstests/ajax_url0.html', null, 'GET')
.addCallback(function() {
try {
assert.equal(events, 'CubicWeb');
@@ -256,7 +256,7 @@
$(CubicWeb).bind('server-response', function() {
nodes.push('CubicWeb');
});
- $('#qunit-fixture').loadxhtml('static/jstests/ajax_url0.html')
+ $('#qunit-fixture').loadxhtml('static/jstests/ajax_url0.html', null, 'GET')
.addCallback(function() {
try {
assert.equal(nodes.length, 2);