cubicweb/devtools/test/unittest_webtest.py
author Denis Laxalde <denis.laxalde@logilab.fr>
Wed, 29 Mar 2017 11:45:19 +0200
branch3.25
changeset 12112 0a54f49314f6
parent 11166 81fce01b4cc0
child 12567 26744ad37953
permissions -rw-r--r--
[server] Introduce an `has_scheduler` method on Repository This is to be used by client application to determine if looping tasks may be registered in the current process. By checking this, one will avoid the warning in looping_task method when the repository has no scheduler.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10604
d4bf85db41f2 [py3k] import HTTP client constants and exceptions using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10032
diff changeset
     1
from six.moves import http_client
9930
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)
10604
d4bf85db41f2 [py3k] import HTTP client constants and exceptions using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10032
diff changeset
    24
        self.assertEqual(http_client.FORBIDDEN, res.status_int)
9930
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)
10604
d4bf85db41f2 [py3k] import HTTP client constants and exceptions using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10032
diff changeset
    28
        self.assertEqual(http_client.FORBIDDEN, res.status_int)
9930
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('/')
10604
d4bf85db41f2 [py3k] import HTTP client constants and exceptions using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10032
diff changeset
    32
        self.assertEqual(http_client.OK, res.status_int)
9930
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)
10604
d4bf85db41f2 [py3k] import HTTP client constants and exceptions using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10032
diff changeset
    36
        self.assertEqual(http_client.FORBIDDEN, res.status_int)
9930
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__':
11166
81fce01b4cc0 [test] replace one use of lgc.testlib.unittest_main with unittest.main
Julien Cristau <julien.cristau@logilab.fr>
parents: 11057
diff changeset
    40
    import unittest
81fce01b4cc0 [test] replace one use of lgc.testlib.unittest_main with unittest.main
Julien Cristau <julien.cristau@logilab.fr>
parents: 11057
diff changeset
    41
    unittest.main()