devtools/webtest.py
changeset 9930 d20c2b262f55
child 11016 d04703f54510
equal deleted inserted replaced
9929:16163ee1cdf9 9930:d20c2b262f55
       
     1 from __future__ import absolute_import
       
     2 
       
     3 import webtest
       
     4 
       
     5 from cubicweb.wsgi import handler
       
     6 from cubicweb.devtools.testlib import CubicWebTC
       
     7 
       
     8 
       
     9 class CubicWebTestTC(CubicWebTC):
       
    10     @classmethod
       
    11     def init_config(cls, config):
       
    12         super(CubicWebTestTC, cls).init_config(config)
       
    13         config.global_set_option('base-url', 'http://localhost.local/')
       
    14 
       
    15     def setUp(self):
       
    16         super(CubicWebTestTC, self).setUp()
       
    17         webapp = handler.CubicWebWSGIApplication(self.config)
       
    18         self.webapp = webtest.TestApp(webapp)
       
    19 
       
    20     def tearDown(self):
       
    21         del self.webapp
       
    22         super(CubicWebTestTC, self).tearDown()
       
    23 
       
    24     def login(self, user=None, password=None, **args):
       
    25         if user is None:
       
    26             user = self.admlogin
       
    27         if password is None:
       
    28             password = self.admpassword if user == self.admlogin else user
       
    29         args.update({
       
    30             '__login': user,
       
    31             '__password': password
       
    32         })
       
    33         return self.webapp.get('/login', args)
       
    34 
       
    35     def logout(self):
       
    36         return self.webapp.get('/logout')