author | Rémi Cardona <remi.cardona@logilab.fr> |
Tue, 15 Dec 2015 19:05:41 +0100 | |
changeset 10990 | 3a98422df969 |
parent 10032 | fd1dafb0ab10 |
child 10604 | d4bf85db41f2 |
permissions | -rw-r--r-- |
9930
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
1 |
import httplib |
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 |
from logilab.common.testlib import Tags |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
4 |
from cubicweb.devtools.webtest import CubicWebTestTC |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
5 |
|
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
6 |
|
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
7 |
class CWTTC(CubicWebTestTC): |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
8 |
def test_response(self): |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
9 |
response = self.webapp.get('/') |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
10 |
self.assertEqual(200, response.status_int) |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
11 |
|
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
12 |
def test_base_url(self): |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
13 |
if self.config['base-url'] not in self.webapp.get('/').text: |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
14 |
self.fail('no mention of base url in retrieved page') |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
15 |
|
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
16 |
|
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
17 |
class CWTIdentTC(CubicWebTestTC): |
10032
fd1dafb0ab10
[devtools] use a specific test_db_id when disabling anon
Julien Cristau <julien.cristau@logilab.fr>
parents:
9930
diff
changeset
|
18 |
test_db_id = 'webtest-ident' |
9930
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
19 |
anonymous_allowed = False |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
20 |
tags = CubicWebTestTC.tags | Tags(('auth',)) |
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 test_reponse_denied(self): |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
23 |
res = self.webapp.get('/', expect_errors=True) |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
24 |
self.assertEqual(httplib.FORBIDDEN, res.status_int) |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
25 |
|
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
26 |
def test_login(self): |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
27 |
res = self.webapp.get('/', expect_errors=True) |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
28 |
self.assertEqual(httplib.FORBIDDEN, res.status_int) |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
29 |
|
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
30 |
self.login(self.admlogin, self.admpassword) |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
31 |
res = self.webapp.get('/') |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
32 |
self.assertEqual(httplib.OK, res.status_int) |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
33 |
|
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
34 |
self.logout() |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
35 |
res = self.webapp.get('/', expect_errors=True) |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
36 |
self.assertEqual(httplib.FORBIDDEN, res.status_int) |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
37 |
|
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
38 |
|
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
39 |
if __name__ == '__main__': |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
40 |
from logilab.common.testlib import unittest_main |
d20c2b262f55
[tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
41 |
unittest_main() |