Skip to content

Commit

Permalink
test: 테스트시 인증 종속성 우회
Browse files Browse the repository at this point in the history
  • Loading branch information
2jun0 committed Jan 17, 2024
1 parent 7b5d057 commit 279de8c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
6 changes: 6 additions & 0 deletions backend/.test.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
DATABASE_URL=sqlite+aiosqlite:///test.db

JWT_SECRET=ee
OAUTH2_SECRET=ee
GOOGLE_OAUTH2_CLIENT_ID=ee
GOOGLE_OAUTH2_CLIENT_SECRET=ee

ENVIRONMENT=TEST
TEST_DATABASE_URL=sqlite:///test.db
13 changes: 13 additions & 0 deletions backend/tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
from sqlalchemy import Engine
from sqlmodel import Session

from src.auth.dependency import current_active_user
from src.main import app
from tests.database import engine
from tests.utils.auth import create_random_user
from tests.utils.database import create_all_table, drop_tables


Expand All @@ -28,3 +30,14 @@ def database():
def session(database: Engine) -> Generator[Session, Any, None]:
with Session(engine) as session:
yield session


"""override dependencies"""


@pytest.fixture(autouse=True)
def override_dependencies(session: Session):
def override_current_active_user():
return create_random_user(session, email="[email protected]")

app.dependency_overrides[current_active_user] = override_current_active_user
23 changes: 23 additions & 0 deletions backend/tests/utils/auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from sqlmodel import Session

from src.auth.model import User

QUIZ_SCREENSHOT_COUNT = 5


def create_random_user(
session: Session, *, email: str, is_active: bool = True, is_superuser: bool = False, is_verified: bool = False
) -> User:
user = User(
email=email,
hashed_password="hashed_password",
is_active=is_active,
is_superuser=is_superuser,
is_verified=is_verified,
)

session.add(user)
session.commit()
session.refresh(user)

return user

0 comments on commit 279de8c

Please sign in to comment.