Refactor tests and fix patch imports in event themes tests
Updated `@patch` targets to match their correct import paths and adjusted imports for clarity and consistency. Fixed indentation issues and resolved minor import ordering problems to improve code readability.
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
# tests/api/routes/test_event_themes.py
|
||||
import uuid
|
||||
from fastapi import status
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
from fastapi import status
|
||||
|
||||
from app.api.dependencies.common import get_storage_provider
|
||||
from app.api.routes.event_themes import router as themes_router
|
||||
from unittest.mock import patch, MagicMock
|
||||
|
||||
|
||||
class TestCreateEventTheme:
|
||||
@@ -57,7 +56,7 @@ class TestCreateEventTheme:
|
||||
|
||||
def test_create_theme_regular_user_forbidden(self, create_test_client, db_session, theme_data, mock_user):
|
||||
"""Test that regular users (non-superusers) cannot create themes."""
|
||||
# Create a client with a regular user (not superuser)
|
||||
# Create a client with a regular user (not superuser)
|
||||
client = create_test_client(
|
||||
router=themes_router,
|
||||
prefix="/themes",
|
||||
@@ -165,6 +164,7 @@ class TestCreateEventTheme:
|
||||
|
||||
def test_create_theme_with_uploaded_preview_image(self, db_session):
|
||||
"""Test creating a theme with an uploaded preview image that needs relocation."""
|
||||
|
||||
# Path to where the _relocate_theme_file is imported and used
|
||||
@patch('app.api.routes.event_themes._relocate_theme_file')
|
||||
def run_test(mock_relocate):
|
||||
@@ -212,10 +212,12 @@ class TestCreateEventTheme:
|
||||
assert call_args[2] == 'preview' # file_type
|
||||
|
||||
return data
|
||||
|
||||
return run_test()
|
||||
|
||||
def test_create_theme_with_uploaded_background_image(self, db_session):
|
||||
"""Test creating a theme with an uploaded background image that needs relocation."""
|
||||
|
||||
# Path to where the _relocate_theme_file is imported and used
|
||||
@patch('app.api.routes.event_themes._relocate_theme_file')
|
||||
def run_test(mock_relocate):
|
||||
@@ -269,6 +271,7 @@ class TestCreateEventTheme:
|
||||
|
||||
def test_create_theme_with_uploaded_foreground_image(self, db_session):
|
||||
"""Test creating a theme with an uploaded foreground image that needs relocation."""
|
||||
|
||||
# Path to where the _relocate_theme_file is imported and used
|
||||
@patch('app.api.routes.event_themes._relocate_theme_file')
|
||||
def run_test(mock_relocate):
|
||||
@@ -319,8 +322,10 @@ class TestCreateEventTheme:
|
||||
|
||||
# Run the test
|
||||
return run_test()
|
||||
|
||||
def test_create_theme_with_uploaded_asset_images(self, db_session):
|
||||
"""Test creating a theme with uploaded asset images that need relocation."""
|
||||
|
||||
# Path to where the _relocate_theme_file is imported and used
|
||||
@patch('app.api.routes.event_themes._relocate_theme_file')
|
||||
def run_test(mock_relocate):
|
||||
@@ -386,8 +391,10 @@ class TestCreateEventTheme:
|
||||
|
||||
# Run the test
|
||||
return run_test()
|
||||
|
||||
def test_create_theme_image_relocation_failure_handled(self, db_session):
|
||||
"""Test that theme creation handles image relocation failures gracefully."""
|
||||
|
||||
# Path to where the _relocate_theme_file is imported and used
|
||||
@patch('app.api.routes.event_themes._relocate_theme_file')
|
||||
def run_test(mock_relocate):
|
||||
@@ -440,7 +447,8 @@ class TestCreateEventTheme:
|
||||
|
||||
def test_create_theme_database_error_handled(self, db_session):
|
||||
"""Test that theme creation attempts to create the theme but fails correctly."""
|
||||
@patch('app.crud.event_theme.event_theme.create')
|
||||
|
||||
@patch('app.crud.event_theme.event_theme_crud.create')
|
||||
def run_test(mock_create):
|
||||
# Configure the mock to raise a SQLAlchemyError
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
@@ -566,4 +574,4 @@ class TestCreateEventTheme:
|
||||
assert db_theme is not None
|
||||
assert db_theme.name == theme_data["name"]
|
||||
|
||||
return data
|
||||
return data
|
||||
|
||||
Reference in New Issue
Block a user