Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand All @@ -229,27 +241,34 @@ 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():
return {
"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(),
Expand All @@ -260,4 +279,4 @@ def user_response_data():

@pytest.fixture
def login_request_data():
return {"username": "john_doe_123", "password": "SecurePassword123!"}
return {"username": "john_doe_123", "password": "SecurePassword123!", "email": "johndoe@example.com"}
2 changes: 1 addition & 1 deletion tests/test_schemas/test_user_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down