Add more tests for the users repo and fix bugs they uncovered
This commit is contained in:
parent
6c46a1df3a
commit
acb343f559
2 changed files with 14 additions and 3 deletions
|
|
@ -73,5 +73,6 @@ class UserRepoImpl(CRUDRepo[UserModel, User, UserDTO], UserRepo):
|
|||
|
||||
try:
|
||||
self._hasher.verify(full_user.password_hash.expose_secret(), user.raw_password.expose_secret())
|
||||
return full_user
|
||||
except VerifyMismatchError:
|
||||
return None
|
||||
|
|
|
|||
|
|
@ -5,12 +5,10 @@ from src.infra.users import UserRepoImpl
|
|||
from src.infra.db_test import mock_db
|
||||
import pytest
|
||||
|
||||
DB = mock_db()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def db():
|
||||
return DB
|
||||
return mock_db()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
|
@ -29,3 +27,15 @@ def users(repo: UserRepo):
|
|||
def test_getting_a_user_by_email(users: list[User], repo: UserRepo):
|
||||
assert repo.get_user_by_email('example@example.com') == users[0]
|
||||
assert repo.get_user_by_email('fred@example.com') is None
|
||||
|
||||
|
||||
def test_authenticating_as_a_user_can_succeed(users: list[User], repo: UserRepo):
|
||||
assert repo.auth_as_user(UserDTO('example@example.com', SecretBox('hunter1'))) == users[0]
|
||||
|
||||
|
||||
def test_authenticating_fails_with_bad_password(users: list[User], repo: UserRepo):
|
||||
assert repo.auth_as_user(UserDTO('example@example.com', SecretBox('something-wrong'))) is None
|
||||
|
||||
|
||||
def test_authenticating_fails_for_nonexistent_user(users: list[User], repo: UserRepo):
|
||||
assert repo.auth_as_user(UserDTO('rando@example.com', SecretBox('test123'))) is None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue