Skip to content

Commit ed78ad6

Browse files
committed
test: add background task on user registration
1 parent fb552d6 commit ed78ad6

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

Pipfile.lock

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

app/tests/unit/test_user_services.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from app.schemas.user_schema import UserCreateSchema
88
from app.models.users import User
99
from fastapi_pundra.common.password import compare_hashed_password
10+
from fastapi import BackgroundTasks
1011

1112
@pytest.fixture
1213
def user_service():
@@ -33,13 +34,14 @@ async def test_get_users(user_service, db):
3334
@pytest.mark.asyncio
3435
async def test_registration_success(user_service, db):
3536
mock_request = Mock(spec=Request)
37+
background_tasks = BackgroundTasks()
3638
user_data = UserCreateSchema(
3739
3840
password="password123",
3941
name="Test User mostafa"
4042
)
4143

42-
result = await user_service.s_registration(mock_request, db, user_data)
44+
result = await user_service.s_registration(mock_request, db, user_data, background_tasks)
4345

4446
assert result["message"] == "Registration successful"
4547
assert result["user"]["email"] == "[email protected]"
@@ -49,14 +51,15 @@ async def test_registration_success(user_service, db):
4951
@pytest.mark.asyncio
5052
async def test_registration_duplicate_email(user_service, db):
5153
mock_request = Mock(spec=Request)
54+
background_tasks = BackgroundTasks()
5255
user_data = UserCreateSchema(
5356
email="[email protected]", # Using the same email as existing_user
5457
password="password123",
5558
name="Test User mostafa"
5659
)
5760

5861
with pytest.raises(BaseAPIException) as exc:
59-
await user_service.s_registration(mock_request, db, user_data)
62+
await user_service.s_registration(mock_request, db, user_data, background_tasks)
6063
assert str(exc.value.message) == "Email already registered" # Fixed assertion to be outside the with block
6164

6265
@pytest.mark.asyncio

0 commit comments

Comments
 (0)