13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
14 # details. |
14 # details. |
15 # |
15 # |
16 # You should have received a copy of the GNU Lesser General Public License along |
16 # You should have received a copy of the GNU Lesser General Public License along |
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
|
18 from __future__ import absolute_import |
18 |
19 |
19 import os, os.path as osp |
20 import os, os.path as osp |
20 import errno |
21 import errno |
21 from tempfile import mkdtemp |
22 from tempfile import mkdtemp |
22 from subprocess import Popen, PIPE, STDOUT |
23 from subprocess import Popen, PIPE, STDOUT |
23 |
24 |
24 from six.moves.queue import Queue, Empty |
25 from six.moves.queue import Queue, Empty |
25 |
26 |
26 # imported by default to simplify further import statements |
27 # imported by default to simplify further import statements |
27 from logilab.common.testlib import unittest_main, with_tempdir, InnerTest, Tags |
28 from logilab.common.testlib import unittest_main, with_tempdir, InnerTest, Tags |
|
29 import webtest.http |
28 |
30 |
29 import cubicweb |
31 import cubicweb |
30 from cubicweb.view import View |
32 from cubicweb.view import View |
31 from cubicweb.web.controller import Controller |
33 from cubicweb.web.controller import Controller |
32 from cubicweb.web.views.staticcontrollers import StaticFileController, STATIC_CONTROLLERS |
34 from cubicweb.web.views.staticcontrollers import StaticFileController, STATIC_CONTROLLERS |
33 from cubicweb.devtools.httptest import CubicWebServerTC |
35 from cubicweb.devtools import webtest as cwwebtest |
34 |
36 |
35 |
37 |
36 class FirefoxHelper(object): |
38 class FirefoxHelper(object): |
37 |
39 |
38 def __init__(self, url=None): |
40 def __init__(self, url=None): |
84 self.test_queue = Queue() |
86 self.test_queue = Queue() |
85 class MyQUnitResultController(QUnitResultController): |
87 class MyQUnitResultController(QUnitResultController): |
86 tc = self |
88 tc = self |
87 test_queue = self.test_queue |
89 test_queue = self.test_queue |
88 self._qunit_controller = MyQUnitResultController |
90 self._qunit_controller = MyQUnitResultController |
89 self.vreg.register(MyQUnitResultController) |
91 self.webapp.app.appli.vreg.register(MyQUnitResultController) |
90 self.vreg.register(QUnitView) |
92 self.webapp.app.appli.vreg.register(QUnitView) |
91 self.vreg.register(CWDevtoolsStaticController) |
93 self.webapp.app.appli.vreg.register(CWDevtoolsStaticController) |
|
94 self.server = webtest.http.StopableWSGIServer.create(self.webapp.app) |
|
95 self.config.global_set_option('base-url', self.server.application_url) |
92 |
96 |
93 def tearDown(self): |
97 def tearDown(self): |
|
98 self.server.shutdown() |
|
99 self.webapp.app.appli.vreg.unregister(self._qunit_controller) |
|
100 self.webapp.app.appli.vreg.unregister(QUnitView) |
|
101 self.webapp.app.appli.vreg.unregister(CWDevtoolsStaticController) |
94 super(QUnitTestCase, self).tearDown() |
102 super(QUnitTestCase, self).tearDown() |
95 self.vreg.unregister(self._qunit_controller) |
|
96 self.vreg.unregister(QUnitView) |
|
97 self.vreg.unregister(CWDevtoolsStaticController) |
|
98 |
103 |
99 def test_javascripts(self): |
104 def test_javascripts(self): |
100 for args in self.all_js_tests: |
105 for args in self.all_js_tests: |
101 self.assertIn(len(args), (1, 2)) |
106 self.assertIn(len(args), (1, 2)) |
102 test_file = args[0] |
107 test_file = args[0] |
203 test_file = None |
208 test_file = None |
204 |
209 |
205 def call(self, **kwargs): |
210 def call(self, **kwargs): |
206 w = self.w |
211 w = self.w |
207 req = self._cw |
212 req = self._cw |
208 data = { |
|
209 'jquery': req.data_url('jquery.js'), |
|
210 'devtools': req.build_url('devtools'), |
|
211 } |
|
212 w(u'''<!DOCTYPE html> |
213 w(u'''<!DOCTYPE html> |
213 <html> |
214 <html> |
214 <head> |
215 <head> |
215 <meta http-equiv="content-type" content="application/html; charset=UTF-8"/> |
216 <meta http-equiv="content-type" content="application/html; charset=UTF-8"/> |
216 <!-- JS lib used as testing framework --> |
217 <!-- JS lib used as testing framework --> |
217 <link rel="stylesheet" type="text/css" media="all" href="%(devtools)s/qunit.css" /> |
218 <link rel="stylesheet" type="text/css" media="all" href="/devtools/qunit.css" /> |
218 <script src="%(jquery)s" type="text/javascript"></script> |
219 <script src="/data/jquery.js" type="text/javascript"></script> |
219 <script src="%(devtools)s/cwmock.js" type="text/javascript"></script> |
220 <script src="/devtools/cwmock.js" type="text/javascript"></script> |
220 <script src="%(devtools)s/qunit.js" type="text/javascript"></script>''' |
221 <script src="/devtools/qunit.js" type="text/javascript"></script>''') |
221 % data) |
|
222 w(u'<!-- result report tools -->') |
222 w(u'<!-- result report tools -->') |
223 w(u'<script type="text/javascript">') |
223 w(u'<script type="text/javascript">') |
224 w(u"var BASE_URL = '%s';" % req.base_url()) |
224 w(u"var BASE_URL = '%s';" % req.base_url()) |
225 w(u''' |
225 w(u''' |
226 QUnit.moduleStart(function (details) { |
226 QUnit.moduleStart(function (details) { |