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
This commit is contained in:
curo1305
2026-05-30 23:09:39 +02:00
parent a2ece9ee7d
commit b7df9719c2
+39
View File
@@ -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 @pytest_asyncio.fixture
async def admin_user(db_session: AsyncSession): async def admin_user(db_session: AsyncSession):
"""Create an admin user with a Quota row and return auth context. """Create an admin user with a Quota row and return auth context.