From b7df9719c2aef6bd6e72e3ced40d25946e33e6cc Mon Sep 17 00:00:00 2001 From: curo1305 Date: Sat, 30 May 2026 23:09:39 +0200 Subject: [PATCH] feat(6.1-01): add second_auth_user fixture to conftest.py - Add @pytest_asyncio.fixture second_auth_user with handle prefix 'user2_' - Creates User + Quota row following the same pattern as auth_user - Returns {user, token, headers} dict shape for use in sharing tests --- backend/tests/conftest.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/backend/tests/conftest.py b/backend/tests/conftest.py index 71990cf..e75e6a2 100644 --- a/backend/tests/conftest.py +++ b/backend/tests/conftest.py @@ -226,6 +226,45 @@ async def auth_user(db_session: AsyncSession): } +@pytest_asyncio.fixture +async def second_auth_user(db_session: AsyncSession): + """Create a second regular user with a Quota row and return auth context. + + Returns the same dict shape as auth_user but with a distinct handle prefix + ("user2_") so sharing tests can have a sharer and a recipient in the same + test without handle collisions. + """ + import uuid as _uuid + from db.models import User, Quota + from services.auth import hash_password, create_access_token + + user_id = _uuid.uuid4() + user = User( + id=user_id, + handle=f"user2_{user_id.hex[:8]}", + email=f"user2_{user_id.hex[:8]}@example.com", + password_hash=hash_password("Testpassword123!"), + role="user", + is_active=True, + password_must_change=False, + ) + quota = Quota( + user_id=user_id, + limit_bytes=104857600, # 100 MB + used_bytes=0, + ) + db_session.add(user) + db_session.add(quota) + await db_session.commit() + + token = create_access_token(str(user_id), "user") + return { + "user": user, + "token": token, + "headers": {"Authorization": f"Bearer {token}"}, + } + + @pytest_asyncio.fixture async def admin_user(db_session: AsyncSession): """Create an admin user with a Quota row and return auth context.