def test_user_update(app): user = User.find_by_id(_SOME_USER_ID) assert user.name != _UPDATED_NAME user.update({"name": _UPDATED_NAME}) user.save() user = User.find_by_id(_SOME_USER_ID) assert user.name == _UPDATED_NAME
def test_user_update_password(app): user = User.find_by_id(_SOME_USER_ID) current_hash = user.password some_pass = "******" user.update({"password": some_pass}) user.save() user = User.find_by_id(_SOME_USER_ID) assert user.password != current_hash assert user.verify_passw(some_pass, user.password)
def test_get_user_messages(app): user = User.find_by_id(_SOME_USER_ID) all_messages: Dict[str, List] = user.get_messages() received_message_ids = {message.id for message in all_messages["received"]} sent_message_ids = {message.id for message in all_messages["sent"]} assert received_message_ids == _RECEIVED_MESSAGES_IDS_BY_SOME_USER assert sent_message_ids == _SENT_MESSAGES_IDS_BY_SOME_USER
def test_some_user_password(app): user = User.find_by_id(_SOME_USER_ID) assert user.password != _SOME_USER_PASSWORD # same string if generate again shows different hash assert user.password != user.generate_passw(_SOME_USER_PASSWORD) # check that some_password and hash that stored are actually the same assert user.verify_passw(_SOME_USER_PASSWORD, user.password)
def create_new_message(recipient: int, subject="Lorem", body: str = "Lorem"): if (recipient := User.find_by_id(recipient)) is None: return errors.bad_request("Recipient is not found.")
def test_user_delete(app): user = User.find_by_id(_SOME_USER_ID) assert user.delete()
def test_some_user_exists(app): assert User.find_by_id(_SOME_USER_ID) is not None
def identity(payload): user_id = payload['identity'] return User.find_by_id(user_id)