author | Denis Laxalde <denis.laxalde@logilab.fr> |
Tue, 21 Jun 2016 16:21:07 +0200 | |
changeset 11299 | f94f5e81fb9d |
parent 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 |
def setUp(self): |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
11 |
super(CubicWebTestTC, self).setUp() |
11016
d04703f54510
[devtools] Fix database creation issues for CubicWebTestTC tests
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9930
diff
changeset
|
12 |
self.config.global_set_option('base-url', 'http://localhost.local/') |
d04703f54510
[devtools] Fix database creation issues for CubicWebTestTC tests
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9930
diff
changeset
|
13 |
# call load_configuration again to let the config reset its datadir_url |
d04703f54510
[devtools] Fix database creation issues for CubicWebTestTC tests
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9930
diff
changeset
|
14 |
self.config.load_configuration() |
9930
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
15 |
webapp = handler.CubicWebWSGIApplication(self.config) |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
16 |
self.webapp = webtest.TestApp(webapp) |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
17 |
|
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
18 |
def tearDown(self): |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
19 |
del self.webapp |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
20 |
super(CubicWebTestTC, self).tearDown() |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
21 |
|
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
22 |
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
|
23 |
if user is None: |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
24 |
user = self.admlogin |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
25 |
if password is None: |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
26 |
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
|
27 |
args.update({ |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
28 |
'__login': user, |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
29 |
'__password': password |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
30 |
}) |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
31 |
return self.webapp.get('/login', args) |
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 |
def logout(self): |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
34 |
return self.webapp.get('/logout') |