# HG changeset patch # User Christophe de Vienne # Date 1424708263 -3600 # Node ID 136dd873dca20ef9d65659053b86508d82f415d7 # Parent 1e2ab5972b18331d5834ae1dc83d5b0c25b4f732 [login] Test the login views diff -r 1e2ab5972b18 -r 136dd873dca2 pyramid_cubicweb/tests/test_login.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pyramid_cubicweb/tests/test_login.py Mon Feb 23 17:17:43 2015 +0100 @@ -0,0 +1,34 @@ +from pyramid_cubicweb.tests 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) + cookie = self.webapp.cookiejar._cookies[ + 'localhost.local']['/']['auth_tkt'] + self.assertIsNone(cookie.expires) + + res = self.webapp.get('/logout') + self.assertEqual(res.status_int, 303) + + res = self.webapp.post('/login', { + '__login': self.admlogin, '__password': self.admpassword, + '__setauthcookie': 1}) + self.assertEqual(res.status_int, 303) + cookie = self.webapp.cookiejar._cookies[ + 'localhost.local']['/']['auth_tkt'] + self.assertIsNotNone(cookie.expires)