def test_login(self): from ptahcrowd import login from ptahcrowd.provider import CrowdUser user = CrowdUser(username='******', email='email', password='******') CrowdUser.__type__.add(user) request = self.make_request() form = login.LoginForm(None, request) form.update_form() data, errors = form.extract() self.assertEqual(len(errors), 2) form.login_handler() self.assertIn('Please fix indicated errors.', request.render_messages()) request = self.make_request(POST={ 'login': '******', 'password': '******' }) request.environ['HTTP_HOST'] = 'example.com' form = login.LoginForm(None, request) form.update_form() res = form.login_handler() self.assertIsInstance(res, HTTPFound) self.assertEqual(res.headers['location'], 'http://example.com/login-success.html')
def test_login_unvalidated(self): from ptahcrowd import login from ptahcrowd.provider import CrowdUser user = CrowdUser(username='******', email='email', password='******') CrowdUser.__type__.add(user) user.validated = False cfg = ptah.get_settings(ptahcrowd.CFG_ID_CROWD) cfg['allow-unvalidated'] = False request = self.make_request(POST={ 'login': '******', 'password': '******' }) request.environ['HTTP_HOST'] = 'example.com' form = login.LoginForm(None, request) form.update_form() form.login_handler() self.assertIn('Account is not validated.', request.render_messages())
def test_login_update(self): from ptahcrowd import login request = self.make_request() cfg = ptah.get_settings(ptahcrowd.CFG_ID_CROWD) cfg['join'] = False cfg['join-url'] = 'http://test/login.html' form = login.LoginForm(None, request) form.update_form() self.assertFalse(form.join) self.assertEqual(form.joinurl, 'http://test/login.html') res = login.LoginForm(None, request)() self.assertNotIn('head over to the registration form', res.text)
def test_login_auth(self): from ptahcrowd import login request = self.make_request() ptah.auth_service.set_userid('test') res = login.LoginForm(None, request)() self.assertEqual(res.status, '302 Found') self.assertEqual(res.headers['location'], 'http://example.com/login-success.html')
def test_login_update_join(self): from ptahcrowd import login request = self.make_request() request.registry = self.registry cfg = ptah.get_settings(ptahcrowd.CFG_ID_CROWD, self.registry) cfg['join'] = True cfg['join-url'] = '' form = login.LoginForm(None, request) form.update_form() self.assertTrue(form.join) self.assertEqual(form.joinurl, 'http://example.com/join.html')
def test_login_wrong_login(self): from ptahcrowd import login from ptahcrowd.provider import CrowdUser user = CrowdUser(username='******', email='email', password='******') CrowdUser.__type__.add(user) request = self.make_request(POST={ 'login': '******', 'password': '******' }) request.environ['HTTP_HOST'] = 'example.com' form = login.LoginForm(None, request) form.update_form() form.login_handler() self.assertIn("You have entered the wrong login or password.", request.render_messages())
def test_login_suspended(self): from ptahcrowd import login from ptahcrowd.provider import CrowdUser user = CrowdUser(username='******', email='email', password='******') CrowdUser.__type__.add(user) user.suspended = True request = self.make_request(POST={ 'login': '******', 'password': '******' }) request.environ['HTTP_HOST'] = 'example.com' form = login.LoginForm(None, request) form.update_form() res = form.login_handler() self.assertEqual(res.headers['location'], 'http://example.com/login-suspended.html')