pyramid_cubicweb/tests/test_login.py
author David Douard <david.douard@logilab.fr>
Tue, 22 Mar 2016 14:01:44 +0100
changeset 11611 9d2bb6bdb5c8
parent 11562 a49f08423f02
child 11628 0f12ee84f30a
permissions -rw-r--r--
[tests] add a __main__ handler the relative import in test_rest_api.py needs to be modified to prevent a ValueError: Attempted relative import in non-package
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11559
136dd873dca2 [login] Test the login views
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     1
from pyramid_cubicweb.tests import PyramidCWTest
136dd873dca2 [login] Test the login views
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     2
136dd873dca2 [login] Test the login views
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     3
136dd873dca2 [login] Test the login views
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     4
class LoginTest(PyramidCWTest):
136dd873dca2 [login] Test the login views
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     5
    def test_login_form(self):
136dd873dca2 [login] Test the login views
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     6
        res = self.webapp.get('/login')
136dd873dca2 [login] Test the login views
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     7
        self.assertIn('__login', res.text)
136dd873dca2 [login] Test the login views
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     8
136dd873dca2 [login] Test the login views
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     9
    def test_login_password_login(self):
136dd873dca2 [login] Test the login views
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    10
        res = self.webapp.post('/login', {
136dd873dca2 [login] Test the login views
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    11
            '__login': self.admlogin, '__password': self.admpassword})
136dd873dca2 [login] Test the login views
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    12
        self.assertEqual(res.status_int, 303)
136dd873dca2 [login] Test the login views
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    13
136dd873dca2 [login] Test the login views
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    14
        res = self.webapp.get('/login')
136dd873dca2 [login] Test the login views
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    15
        self.assertEqual(res.status_int, 303)
136dd873dca2 [login] Test the login views
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    16
136dd873dca2 [login] Test the login views
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    17
    def test_login_password_login_cookie_expires(self):
136dd873dca2 [login] Test the login views
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    18
        res = self.webapp.post('/login', {
136dd873dca2 [login] Test the login views
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    19
            '__login': self.admlogin, '__password': self.admpassword})
136dd873dca2 [login] Test the login views
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    20
        self.assertEqual(res.status_int, 303)
11562
a49f08423f02 [auth] Use a second authtkt policy for 'rememberme'
Christophe de Vienne <christophe@unlish.com>
parents: 11559
diff changeset
    21
a49f08423f02 [auth] Use a second authtkt policy for 'rememberme'
Christophe de Vienne <christophe@unlish.com>
parents: 11559
diff changeset
    22
        cookies = self.webapp.cookiejar._cookies['localhost.local']['/']
a49f08423f02 [auth] Use a second authtkt policy for 'rememberme'
Christophe de Vienne <christophe@unlish.com>
parents: 11559
diff changeset
    23
        self.assertNotIn('pauth_tkt', cookies)
a49f08423f02 [auth] Use a second authtkt policy for 'rememberme'
Christophe de Vienne <christophe@unlish.com>
parents: 11559
diff changeset
    24
        self.assertIn('auth_tkt', cookies)
a49f08423f02 [auth] Use a second authtkt policy for 'rememberme'
Christophe de Vienne <christophe@unlish.com>
parents: 11559
diff changeset
    25
        self.assertIsNone(cookies['auth_tkt'].expires)
11559
136dd873dca2 [login] Test the login views
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    26
136dd873dca2 [login] Test the login views
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    27
        res = self.webapp.get('/logout')
136dd873dca2 [login] Test the login views
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    28
        self.assertEqual(res.status_int, 303)
136dd873dca2 [login] Test the login views
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    29
11562
a49f08423f02 [auth] Use a second authtkt policy for 'rememberme'
Christophe de Vienne <christophe@unlish.com>
parents: 11559
diff changeset
    30
        self.assertNotIn('auth_tkt', cookies)
a49f08423f02 [auth] Use a second authtkt policy for 'rememberme'
Christophe de Vienne <christophe@unlish.com>
parents: 11559
diff changeset
    31
        self.assertNotIn('pauth_tkt', cookies)
a49f08423f02 [auth] Use a second authtkt policy for 'rememberme'
Christophe de Vienne <christophe@unlish.com>
parents: 11559
diff changeset
    32
11559
136dd873dca2 [login] Test the login views
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    33
        res = self.webapp.post('/login', {
136dd873dca2 [login] Test the login views
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    34
            '__login': self.admlogin, '__password': self.admpassword,
136dd873dca2 [login] Test the login views
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    35
            '__setauthcookie': 1})
136dd873dca2 [login] Test the login views
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    36
        self.assertEqual(res.status_int, 303)
11562
a49f08423f02 [auth] Use a second authtkt policy for 'rememberme'
Christophe de Vienne <christophe@unlish.com>
parents: 11559
diff changeset
    37
a49f08423f02 [auth] Use a second authtkt policy for 'rememberme'
Christophe de Vienne <christophe@unlish.com>
parents: 11559
diff changeset
    38
        cookies = self.webapp.cookiejar._cookies['localhost.local']['/']
a49f08423f02 [auth] Use a second authtkt policy for 'rememberme'
Christophe de Vienne <christophe@unlish.com>
parents: 11559
diff changeset
    39
        self.assertNotIn('auth_tkt', cookies)
a49f08423f02 [auth] Use a second authtkt policy for 'rememberme'
Christophe de Vienne <christophe@unlish.com>
parents: 11559
diff changeset
    40
        self.assertIn('pauth_tkt', cookies)
a49f08423f02 [auth] Use a second authtkt policy for 'rememberme'
Christophe de Vienne <christophe@unlish.com>
parents: 11559
diff changeset
    41
        self.assertIsNotNone(cookies['pauth_tkt'].expires)
11611
9d2bb6bdb5c8 [tests] add a __main__ handler
David Douard <david.douard@logilab.fr>
parents: 11562
diff changeset
    42
9d2bb6bdb5c8 [tests] add a __main__ handler
David Douard <david.douard@logilab.fr>
parents: 11562
diff changeset
    43
9d2bb6bdb5c8 [tests] add a __main__ handler
David Douard <david.douard@logilab.fr>
parents: 11562
diff changeset
    44
if __name__ == '__main__':
9d2bb6bdb5c8 [tests] add a __main__ handler
David Douard <david.douard@logilab.fr>
parents: 11562
diff changeset
    45
    from unittest import main
9d2bb6bdb5c8 [tests] add a __main__ handler
David Douard <david.douard@logilab.fr>
parents: 11562
diff changeset
    46
    main()