author | Julien Cristau <julien.cristau@logilab.fr> |
Fri, 13 Feb 2015 11:48:13 +0100 | |
changeset 10249 | e38b8d37c5d8 |
parent 9930 | d20c2b262f55 |
child 11016 | d04703f54510 |
permissions | -rw-r--r-- |
9930
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
1 |
from __future__ import absolute_import |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
2 |
|
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
3 |
import webtest |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
4 |
|
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
5 |
from cubicweb.wsgi import handler |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
6 |
from cubicweb.devtools.testlib import CubicWebTC |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
7 |
|
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
8 |
|
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
9 |
class CubicWebTestTC(CubicWebTC): |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
10 |
@classmethod |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
11 |
def init_config(cls, config): |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
12 |
super(CubicWebTestTC, cls).init_config(config) |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
13 |
config.global_set_option('base-url', 'http://localhost.local/') |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
14 |
|
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
15 |
def setUp(self): |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
16 |
super(CubicWebTestTC, self).setUp() |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
17 |
webapp = handler.CubicWebWSGIApplication(self.config) |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
18 |
self.webapp = webtest.TestApp(webapp) |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
19 |
|
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
20 |
def tearDown(self): |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
21 |
del self.webapp |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
22 |
super(CubicWebTestTC, self).tearDown() |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
23 |
|
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
24 |
def login(self, user=None, password=None, **args): |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
25 |
if user is None: |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
26 |
user = self.admlogin |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
27 |
if password is None: |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
28 |
password = self.admpassword if user == self.admlogin else user |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
29 |
args.update({ |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
30 |
'__login': user, |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
31 |
'__password': password |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
32 |
}) |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
33 |
return self.webapp.get('/login', args) |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
34 |
|
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
35 |
def logout(self): |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
36 |
return self.webapp.get('/logout') |