def test_change_user_password(self): with self.app.app_context(): user = User.get_by_username("user1") user.change_password("password1") try: db.session.commit() except SQLAlchemyError: db.session.rollback() self.fail("failed to commit transaction") user = User.get_by_username("user1") self.assertTrue(check_password_hash(user.password, "password1"))
def test_get_user_by_username(self): with self.app.app_context(): user = User.get_by_username("user1") self.assertIsNotNone(user) self.assertIsNotNone(user.id) self.assertEqual(user.username, "user1") self.assertTrue(check_password_hash(user.password, "password"))
def run(self, username, password): user = User.get_by_username(username) if user is None: print("Failed to change user pasword") return user.change_password(password) db.session.commit()
def run(self, username, expires_at): secret = current_app.config['JWT_SECRET_KEY'] algorithm = current_app.config['JWT_ALGORITHM'] user = User.get_by_username(username) if user is None: print("Unknown user {}".format(username)) return token = create_token(user.id, user.jti, secret, algorithm, expires_at) print(token)
def test_fail_to_get_user_that_doesnt_exist(self): with self.app.app_context(): user = User.get_by_username("user2") self.assertIsNone(user)