cubicweb/pyramid/test/test_login.py
author Yann Voté <yann.vote@logilab.fr>
Mon, 26 Sep 2016 14:52:12 +0200
changeset 11631 faf279e33298
parent 11628 pyramid_cubicweb/tests/test_login.py@0f12ee84f30a
child 11816 6392f34fcdad
permissions -rw-r--r--
Merge with pyramid-cubicweb The following tasks have been done: - merge packaging files - merge documentation - move pyramid_cubicweb package at cubicweb/pyramid and update imports accordingly - rename tests directory into test - move pyramid-cubicweb README.rst into README.pyramid.rst until better idea - add a test dependency on unreleased cubicweb-pyramid to have both py27 and py34 tests pass Closes #14023058.

from cubicweb.pyramid.test import PyramidCWTest


class LoginTest(PyramidCWTest):
    def test_login_form(self):
        res = self.webapp.get('/login')
        self.assertIn('__login', res.text)

    def test_login_password_login(self):
        res = self.webapp.post('/login', {
            '__login': self.admlogin, '__password': self.admpassword})
        self.assertEqual(res.status_int, 303)

        res = self.webapp.get('/login')
        self.assertEqual(res.status_int, 303)

    def test_login_password_login_cookie_expires(self):
        res = self.webapp.post('/login', {
            '__login': self.admlogin, '__password': self.admpassword})
        self.assertEqual(res.status_int, 303)

        cookies = self.webapp.cookiejar._cookies['localhost.local']['/']
        self.assertNotIn('pauth_tkt', cookies)
        self.assertIn('auth_tkt', cookies)
        self.assertIsNone(cookies['auth_tkt'].expires)

        res = self.webapp.get('/logout')
        self.assertEqual(res.status_int, 303)

        self.assertNotIn('auth_tkt', cookies)
        self.assertNotIn('pauth_tkt', cookies)

        res = self.webapp.post('/login', {
            '__login': self.admlogin, '__password': self.admpassword,
            '__setauthcookie': 1})
        self.assertEqual(res.status_int, 303)

        cookies = self.webapp.cookiejar._cookies['localhost.local']['/']
        self.assertNotIn('auth_tkt', cookies)
        self.assertIn('pauth_tkt', cookies)
        self.assertIsNotNone(cookies['pauth_tkt'].expires)

    def test_login_bad_password(self):
        res = self.webapp.post('/login', {
            '__login': self.admlogin, '__password': 'empty'}, status=403)
        self.assertIn('Authentication failed', res.text)


if __name__ == '__main__':
    from unittest import main
    main()