1 # copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
|
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
|
3 # |
|
4 # This file is part of CubicWeb. |
|
5 # |
|
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
|
7 # terms of the GNU Lesser General Public License as published by the Free |
|
8 # Software Foundation, either version 2.1 of the License, or (at your option) |
|
9 # any later version. |
|
10 # |
|
11 # CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
|
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
|
14 # details. |
|
15 # |
|
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/>. |
|
18 """automatic tests""" |
|
19 from cubicweb.devtools.testlib import AutoPopulateTest, AutomaticWebTest |
|
20 from cubicweb.view import AnyRsetView |
|
21 |
|
22 class AutomaticWebTest(AutomaticWebTest): |
|
23 application_rql = [ |
|
24 'Any L,F WHERE E is CWUser, E login L, E firstname F', |
|
25 'Any L,F,E WHERE E is CWUser, E login L, E firstname F', |
|
26 'Any COUNT(X) WHERE X is CWUser', |
|
27 ] |
|
28 |
|
29 def to_test_etypes(self): |
|
30 # We do not really want to test cube views here. So we can drop testing |
|
31 # some EntityType. The two Blog types below require the sioc cube that |
|
32 # we do not want to add as a dependency. |
|
33 etypes = super(AutomaticWebTest, self).to_test_etypes() |
|
34 etypes -= set(('Blog', 'BlogEntry')) |
|
35 return etypes |
|
36 |
|
37 |
|
38 class SomeView(AnyRsetView): |
|
39 __regid__ = 'someview' |
|
40 |
|
41 def call(self): |
|
42 self._cw.add_js('spam.js') |
|
43 self._cw.add_js('spam.js') |
|
44 |
|
45 |
|
46 class ManualCubicWebTCs(AutoPopulateTest): |
|
47 |
|
48 def test_regr_copy_view(self): |
|
49 """regression test: make sure we can ask a copy of a |
|
50 composite entity |
|
51 """ |
|
52 with self.admin_access.web_request() as req: |
|
53 rset = req.execute(u'CWUser X WHERE X login "admin"') |
|
54 self.view('copy', rset, req=req) |
|
55 |
|
56 def test_sortable_js_added(self): |
|
57 with self.admin_access.web_request() as req: |
|
58 # sortable.js should not be included by default |
|
59 rset = req.execute('CWUser X') |
|
60 self.assertNotIn(b'jquery.tablesorter.js', self.view('oneline', rset, req=req).source) |
|
61 |
|
62 with self.admin_access.web_request() as req: |
|
63 # but should be included by the tableview |
|
64 rset = req.execute('Any P,F,S LIMIT 1 WHERE P is CWUser, P firstname F, P surname S') |
|
65 self.assertIn(b'jquery.tablesorter.js', self.view('table', rset, req=req).source) |
|
66 |
|
67 def test_js_added_only_once(self): |
|
68 with self.admin_access.web_request() as req: |
|
69 self.vreg._loadedmods[__name__] = {} |
|
70 self.vreg.register(SomeView) |
|
71 rset = req.execute('CWUser X') |
|
72 source = self.view('someview', rset, req=req).source |
|
73 self.assertEqual(source.count(b'spam.js'), 1) |
|
74 |
|
75 def test_unrelateddivs(self): |
|
76 with self.admin_access.client_cnx() as cnx: |
|
77 group = cnx.create_entity('CWGroup', name=u'R&D') |
|
78 cnx.commit() |
|
79 with self.admin_access.web_request(relation='in_group_subject') as req: |
|
80 rset = req.execute(u'Any X WHERE X is CWUser, X login "admin"') |
|
81 self.view('unrelateddivs', rset, req=req) |
|
82 |
|
83 |
|
84 if __name__ == '__main__': |
|
85 from logilab.common.testlib import unittest_main |
|
86 unittest_main() |
|