From 441f534c941fd4836d1a822b731e993d01a7d67d Mon Sep 17 00:00:00 2001 From: root Date: Wed, 4 Dec 2024 09:09:22 -0500 Subject: [PATCH] change files --- tests/conftest.py | 31 ++++++++++++++++++++----- tests/test_schemas/test_user_schemas.py | 2 +- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 6bd7998ac..a96dd6874 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -82,6 +82,15 @@ async def setup_database(): await conn.run_sync(Base.metadata.drop_all) await engine.dispose() +from app.services.jwt_service import create_access_token +import pytest + +@pytest.fixture(scope="function") +async def admin_token(admin_user, db_session): + """Fixture to generate an authentication token for the admin user.""" + token = create_access_token(user_id=str(admin_user.id), role=admin_user.role) + return token + @pytest.fixture(scope="function") async def db_session(setup_database): async with AsyncSessionScoped() as session: @@ -195,6 +204,8 @@ async def admin_user(db_session: AsyncSession): await db_session.commit() return user + + @pytest.fixture async def manager_user(db_session: AsyncSession): user = User( @@ -219,7 +230,8 @@ def user_base_data(): "email": "john.doe@example.com", "full_name": "John Doe", "bio": "I am a software engineer with over 5 years of experience.", - "profile_picture_url": "https://example.com/profile_pictures/john_doe.jpg" + "profile_picture_url": "https://example.com/profile_pictures/john_doe.jpg", + "nickname": "John" } @pytest.fixture @@ -229,13 +241,14 @@ def user_base_data_invalid(): "email": "john.doe.example.com", "full_name": "John Doe", "bio": "I am a software engineer with over 5 years of experience.", - "profile_picture_url": "https://example.com/profile_pictures/john_doe.jpg" + "profile_picture_url": "https://example.com/profile_pictures/john_doe.jpg", + "nickname": "John" } @pytest.fixture def user_create_data(user_base_data): - return {**user_base_data, "password": "SecurePassword123!"} + return {**user_base_data, "password": "SecurePassword123!", "nickname": "Doe"} @pytest.fixture def user_update_data(): @@ -243,13 +256,19 @@ def user_update_data(): "email": "john.doe.new@example.com", "full_name": "John H. Doe", "bio": "I specialize in backend development with Python and Node.js.", - "profile_picture_url": "https://example.com/profile_pictures/john_doe_updated.jpg" + "profile_picture_url": "https://example.com/profile_pictures/john_doe_updated.jpg", + "first_name": "John" } +import uuid +import pytest +from datetime import datetime + + @pytest.fixture def user_response_data(): return { - "id": "unique-id-string", + "id": str(uuid.uuid4()), #unique-id-string "username": "testuser", "email": "test@example.com", "last_login_at": datetime.now(), @@ -260,4 +279,4 @@ def user_response_data(): @pytest.fixture def login_request_data(): - return {"username": "john_doe_123", "password": "SecurePassword123!"} \ No newline at end of file + return {"username": "john_doe_123", "password": "SecurePassword123!", "email": "johndoe@example.com"} \ No newline at end of file diff --git a/tests/test_schemas/test_user_schemas.py b/tests/test_schemas/test_user_schemas.py index c5b92e148..4a01f7b07 100644 --- a/tests/test_schemas/test_user_schemas.py +++ b/tests/test_schemas/test_user_schemas.py @@ -25,7 +25,7 @@ def test_user_update_valid(user_update_data): # Tests for UserResponse def test_user_response_valid(user_response_data): user = UserResponse(**user_response_data) - assert user.id == user_response_data["id"] + assert str(user.id) == user_response_data["id"] # assert user.last_login_at == user_response_data["last_login_at"] # Tests for LoginRequest