def test_login(self): exp = User('*****@*****.**') obs = User.login('*****@*****.**', 'password') self.assertEqual(obs, exp) with self.assertRaises(LabmanUnknownIdError): User.login('*****@*****.**', 'password') with self.assertRaises(LabmanLoginError): User.login('*****@*****.**', 'wrongpassword')
def test_access_handler_post(self): tester = User('*****@*****.**') response = self.post('/auth/access/', { 'email': '*****@*****.**', 'operation': 'grant' }) self.assertEqual(response.code, 200) self.assertEqual(User.login('*****@*****.**', 'password'), tester) response = self.post('/auth/access/', { 'email': '*****@*****.**', 'operation': 'revoke' }) self.assertEqual(response.code, 200) with self.assertRaises(LabmanLoginDisabledError): User.login('*****@*****.**', 'password') response = self.post('/auth/access/', { 'email': '*****@*****.**', 'operation': 'unknown' }) self.assertEqual(response.code, 400)
def post(self): username = self.get_argument('username', '').strip().lower() passwd = self.get_argument('password', '') error_msg = "" user = None try: user = User.login(username, passwd) except LabmanUnknownIdError: error_msg = "Unknown user name" except LabmanLoginError: error_msg = "Incorrect password" if user: self.set_current_user(username) self.redirect("/") else: self.render("index.html", message=error_msg, level='danger')