Set up an extremely lightweight set of tests for the user infra implementation
This commit is contained in:
parent
0d270c9cfb
commit
32e3fe04a2
5 changed files with 47 additions and 0 deletions
4
pytest.ini
Normal file
4
pytest.ini
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
[pytest]
|
||||||
|
testpaths = src
|
||||||
|
python_files = *_test.py
|
||||||
|
addopts = -ra -q
|
||||||
3
setup.py
3
setup.py
|
|
@ -6,5 +6,8 @@ setup(
|
||||||
packages=find_packages(),
|
packages=find_packages(),
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
package_data={'src': ['templates/**/*.html', 'templates/**/*.txt']},
|
package_data={'src': ['templates/**/*.html', 'templates/**/*.txt']},
|
||||||
|
exclude_package_data={
|
||||||
|
'': ['*_test.py'],
|
||||||
|
},
|
||||||
scripts=['./src/main.py'],
|
scripts=['./src/main.py'],
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ mkShell {
|
||||||
python313Packages.ruff
|
python313Packages.ruff
|
||||||
python313Packages.python-lsp-server
|
python313Packages.python-lsp-server
|
||||||
python313Packages.jedi-language-server
|
python313Packages.jedi-language-server
|
||||||
|
python313Packages.pytest
|
||||||
ty
|
ty
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
8
src/infra/db_test.py
Normal file
8
src/infra/db_test.py
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
from src.infra import Base
|
||||||
|
from sqlalchemy import Engine, create_engine
|
||||||
|
|
||||||
|
|
||||||
|
def mock_db() -> Engine:
|
||||||
|
engine = create_engine('sqlite:///:memory:', echo=True)
|
||||||
|
Base.metadata.create_all(engine)
|
||||||
|
return engine
|
||||||
31
src/infra/users_test.py
Normal file
31
src/infra/users_test.py
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
from src.utils.secret import SecretBox
|
||||||
|
from src.services.users.data import UserDTO, User
|
||||||
|
from src.services.users.repo import UserRepo
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def repo(db):
|
||||||
|
return UserRepoImpl(db)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def users(repo: UserRepo):
|
||||||
|
return [
|
||||||
|
repo.create(UserDTO('example@example.com', SecretBox('hunter1')), None),
|
||||||
|
repo.create(UserDTO('example2@example.com', SecretBox('hunter2')), None),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue