Skip to content

Commit 99a18ad

Browse files
2 parents 9beee0e + 2259f11 commit 99a18ad

File tree

6 files changed

+187
-68
lines changed

6 files changed

+187
-68
lines changed

docs/static/schema.png

52.4 KB
Loading

migrations/set_up_db.py

Lines changed: 0 additions & 30 deletions
This file was deleted.

poetry.lock

Lines changed: 148 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ mypy = "^1.11.2"
2828
jupyter = "^1.1.1"
2929
notebook = "^7.2.2"
3030
pytest = "^8.3.3"
31+
sqlalchemy-schemadisplay = "^2.0"
3132

3233
[build-system]
3334
requires = ["poetry-core"]

tests/conftest.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import pytest
2+
from dotenv import load_dotenv
23
from sqlmodel import create_engine, Session, delete
3-
from utils.db import get_connection_url, set_up_db, tear_down_db
4+
from fastapi.testclient import TestClient
5+
from utils.db import get_connection_url, set_up_db, tear_down_db, get_session
46
from utils.models import User, PasswordResetToken
5-
from dotenv import load_dotenv
7+
from utils.auth import get_password_hash
8+
from main import app
69

710
load_dotenv()
811

@@ -49,3 +52,36 @@ def clean_db(session: Session):
4952
session.exec(delete(User)) # type: ignore
5053

5154
session.commit()
55+
56+
57+
# Test client fixture
58+
@pytest.fixture()
59+
def client(session: Session):
60+
"""
61+
Provides a TestClient instance with the session fixture.
62+
Overrides the get_session dependency to use the test session.
63+
"""
64+
def get_session_override():
65+
return session
66+
67+
app.dependency_overrides[get_session] = get_session_override
68+
client = TestClient(app)
69+
yield client
70+
app.dependency_overrides.clear()
71+
72+
73+
# Test user fixture
74+
@pytest.fixture()
75+
def test_user(session: Session):
76+
"""
77+
Creates a test user in the database.
78+
"""
79+
user = User(
80+
name="Test User",
81+
82+
hashed_password=get_password_hash("Test123!@#")
83+
)
84+
session.add(user)
85+
session.commit()
86+
session.refresh(user)
87+
return user

tests/test_authentication.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
from main import app
1111
from utils.models import User, PasswordResetToken
12-
from utils.db import get_session
1312
from utils.auth import (
1413
create_access_token,
1514
create_refresh_token,
@@ -23,39 +22,6 @@
2322
# --- Fixture setup ---
2423

2524

26-
# Test client fixture
27-
@pytest.fixture(name="client")
28-
def client_fixture(session: Session):
29-
"""
30-
Provides a TestClient instance with the session fixture.
31-
Overrides the get_session dependency to use the test session.
32-
"""
33-
def get_session_override():
34-
return session
35-
36-
app.dependency_overrides[get_session] = get_session_override
37-
client = TestClient(app)
38-
yield client
39-
app.dependency_overrides.clear()
40-
41-
42-
# Test user fixture
43-
@pytest.fixture(name="test_user")
44-
def test_user_fixture(session: Session):
45-
"""
46-
Creates a test user in the database.
47-
"""
48-
user = User(
49-
name="Test User",
50-
51-
hashed_password=get_password_hash("Test123!@#")
52-
)
53-
session.add(user)
54-
session.commit()
55-
session.refresh(user)
56-
return user
57-
58-
5925
# Mock email response fixture
6026
@pytest.fixture
6127
def mock_email_response():

0 commit comments

Comments
 (0)