pyramid_cubicweb/tests/test_login.py
author Christophe de Vienne <christophe@unlish.com>
Mon, 23 Feb 2015 17:17:43 +0100
changeset 11559 136dd873dca2
child 11562 a49f08423f02
permissions -rw-r--r--
[login] Test the login views
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)
136dd873dca2 [login] Test the login views
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    21
        cookie = self.webapp.cookiejar._cookies[
136dd873dca2 [login] Test the login views
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    22
            'localhost.local']['/']['auth_tkt']
136dd873dca2 [login] Test the login views
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    23
        self.assertIsNone(cookie.expires)
136dd873dca2 [login] Test the login views
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    24
136dd873dca2 [login] Test the login views
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    25
        res = self.webapp.get('/logout')
136dd873dca2 [login] Test the login views
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    26
        self.assertEqual(res.status_int, 303)
136dd873dca2 [login] Test the login views
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    27
136dd873dca2 [login] Test the login views
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    28
        res = self.webapp.post('/login', {
136dd873dca2 [login] Test the login views
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    29
            '__login': self.admlogin, '__password': self.admpassword,
136dd873dca2 [login] Test the login views
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    30
            '__setauthcookie': 1})
136dd873dca2 [login] Test the login views
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    31
        self.assertEqual(res.status_int, 303)
136dd873dca2 [login] Test the login views
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    32
        cookie = self.webapp.cookiejar._cookies[
136dd873dca2 [login] Test the login views
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    33
            'localhost.local']['/']['auth_tkt']
136dd873dca2 [login] Test the login views
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    34
        self.assertIsNotNone(cookie.expires)