web/test/test_views.py
changeset 0 b97547f5f1fa
child 473 c0bf9e1e8b36
equal deleted inserted replaced
-1:000000000000 0:b97547f5f1fa
       
     1 """automatic tests"""
       
     2 
       
     3 from mx.DateTime import now
       
     4 
       
     5 from cubicweb.devtools.testlib import WebTest, AutomaticWebTest
       
     6 from cubicweb.common.view import AnyRsetView
       
     7 
       
     8 AutomaticWebTest.application_rql = [
       
     9     'Any L,F WHERE E is EUser, E login L, E firstname F',
       
    10     'Any L,F,E WHERE E is EUser, E login L, E firstname F',
       
    11     'Any COUNT(X) WHERE X is EUser',
       
    12     ]
       
    13 
       
    14 class ComposityCopy(WebTest):
       
    15 
       
    16     def test_regr_copy_view(self):
       
    17         """regression test: make sure we can ask a copy of a
       
    18         composite entity
       
    19         """
       
    20         rset = self.execute('EUser X WHERE X login "admin"')
       
    21         self.view('copy', rset)
       
    22 
       
    23 
       
    24 
       
    25 class SomeView(AnyRsetView):
       
    26     id = 'someview'
       
    27     
       
    28     def call(self):
       
    29         self.req.add_js('spam.js')
       
    30         self.req.add_js('spam.js')
       
    31 
       
    32 
       
    33 class ManualWebTests(WebTest):
       
    34     def setup_database(self):
       
    35         self.auto_populate(10)
       
    36 
       
    37     def test_manual_tests(self):
       
    38         rset = self.execute('Any P,F,S WHERE P is EUser, P firstname F, P surname S')
       
    39         self.view('table', rset, template=None, displayfilter=True, displaycols=[0,2])
       
    40         rset = self.execute('Any P,F,S WHERE P is EUser, P firstname F, P surname S LIMIT 1')
       
    41         rset.req.form['rtype'] = 'firstname'
       
    42         self.view('editrelation', rset, template=None, htmlcheck=False)
       
    43         rset.req.form['rtype'] = 'use_email'
       
    44         self.view('editrelation', rset, template=None, htmlcheck=False)
       
    45         
       
    46 
       
    47     def test_sortable_js_added(self):
       
    48         rset = self.execute('EUser X')
       
    49         # sortable.js should not be included by default
       
    50         self.failIf('jquery.tablesorter.js' in self.view('oneline', rset))
       
    51         # but should be included by the tableview
       
    52         rset = self.execute('Any P,F,S WHERE P is EUser, P firstname F, P surname S LIMIT 1')
       
    53         self.failUnless('jquery.tablesorter.js' in self.view('table', rset))
       
    54 
       
    55     def test_js_added_only_once(self):
       
    56         self.vreg.register_vobject_class(SomeView)
       
    57         rset = self.execute('EUser X')
       
    58         source = self.view('someview', rset).source
       
    59         self.assertEquals(source.count('spam.js'), 1)
       
    60 
       
    61 
       
    62 
       
    63 class ExplicitViewsTest(WebTest):
       
    64     
       
    65     def test_unrelateddivs(self):
       
    66         rset = self.execute('Any X WHERE X is EUser, X login "admin"')
       
    67         group = self.add_entity('EGroup', name=u'R&D')
       
    68         req = self.request(relation='in_group_subject')
       
    69         self.view('unrelateddivs', rset, req)
       
    70         
       
    71         
       
    72 
       
    73 if __name__ == '__main__':
       
    74     from logilab.common.testlib import unittest_main
       
    75     unittest_main()