def test_user_is_saved_in_db(self): """Test if the user has been successfully saved in the database""" user = UserModel(username="******", password="******") user.save_to_db() found_user = UserModel.find_by_username("test") self.assertIsNotNone(found_user)
def test_userprofile_is_saved_in_db(self): """Test if the user profile has been successfully saved in the database after creating a new user""" user = UserModel(username="******", password="******") user.save_to_db() userprofile = UserProfileModel(user_id=user.id) userprofile.save_to_db() found_userprofile = UserProfileModel.find_by_username(user.username) self.assertIsNotNone(found_userprofile)
def create_admin(self): """Create a user model and a user profile model and save them to the database""" with app.app_context(): hashed_pass = generate_password_hash(self.password) user = UserModel( username=self.username, password=hashed_pass, is_admin=True, is_staff=True, ) user.save_to_db() user_profile = UserProfileModel(user_id=user.id) user_profile.save_to_db()