def test_login(self, db_client): user, token = yield User.login(USERS[0]['email'], 'password0') assert user.id == USERS[0]['_id'] assert token saved_token = db_client().save_doc.call_args[0][0] assert saved_token['_id'] == token assert saved_token['user_id'] == user.id
def post(self): """Create token""" # TODO: what if unverified user? data = self.get_json_body(required=['email', 'password']) try: user, token = yield User.login(data['email'], data['password']) except Unauthorized: raise HTTPError(401, 'Invalid email and/or password') self.finish({ 'status': 200, 'data': { 'token': token, 'user': user.clean() } })
def test_login_unverified_user(self, db_client): """Check logging in an unverified user doesn't raise an exception""" # TODO: should we allow unverified users to login? yield User.login(UNVERIFIED_USER['email'], 'password1')
def test_login_incorrect_email(self, db_client): with pytest.raises(exceptions.Unauthorized): yield User.login('does not exist', 'password')
def test_login_incorrect_password(self, db_client): with pytest.raises(exceptions.Unauthorized): yield User.login(USERS[0]['email'], 'password1')