Files
eventspace/backend/tests/schemas/test_event_themes.py
Felipe Cardoso cbcd04d8e1 Rename schema and test files for consistency
Renamed `event_theme` and `test_user_schema` file paths and imports to follow consistent plural naming conventions. This improves code clarity and aligns file and import naming across the project.
2025-03-05 12:48:18 +01:00

114 lines
4.0 KiB
Python

import pytest
from uuid import UUID
from pydantic import ValidationError
from app.schemas.event_themes import (
EventThemeCreate,
EventThemeUpdate,
EventThemeResponse,
EventTheme
)
class TestEventThemeSchemas:
def test_valid_theme_create(self, theme_data):
"""Test creating a valid theme with all required fields"""
theme = EventThemeCreate(**theme_data)
assert theme.name == theme_data["name"]
assert theme.description == theme_data["description"]
assert theme.preview_image_url == theme_data["preview_image_url"]
assert theme.color_palette == theme_data["color_palette"]
assert theme.fonts == theme_data["fonts"]
@pytest.mark.parametrize("invalid_data,expected_error", [
(
{"name": "", "color_palette": {"primary": "#000"}, "fonts": {"main": "Arial"}},
"name"
),
(
{"name": "Theme", "color_palette": {}, "fonts": {"main": "Arial"}},
"color_palette"
),
(
{"name": "Theme", "color_palette": {"primary": "#000"}, "fonts": {}},
"fonts"
),
(
{},
"name"
),
])
def test_invalid_theme_create(self, invalid_data, expected_error):
"""Test validation errors for invalid theme data"""
with pytest.raises(ValidationError) as exc_info:
EventThemeCreate(**invalid_data)
assert expected_error in str(exc_info.value)
def test_theme_update_partial(self):
"""Test updating theme with partial data"""
update_data = {
"name": "Updated Theme"
}
theme = EventThemeUpdate(**update_data)
assert theme.name == "Updated Theme"
assert theme.color_palette is None
assert theme.fonts is None
def test_theme_response(self, theme_data):
"""Test theme response schema with ID"""
response_data = {
**theme_data,
"id": "123e4567-e89b-12d3-a456-426614174000"
}
theme = EventThemeResponse(**response_data)
assert isinstance(theme.id, UUID)
assert str(theme.id) == "123e4567-e89b-12d3-a456-426614174000"
assert theme.name == theme_data["name"]
def test_color_palette_validation(self):
"""Test color palette validation"""
valid_data = {
"name": "Test Theme",
"color_palette": {"primary": "#000000", "secondary": "#FFFFFF"},
"fonts": {"main": "Arial"}
}
theme = EventThemeCreate(**valid_data)
assert theme.color_palette == valid_data["color_palette"]
def test_fonts_validation(self):
"""Test fonts validation"""
valid_data = {
"name": "Test Theme",
"color_palette": {"primary": "#000000"},
"fonts": {"main": "Arial", "secondary": "Helvetica"}
}
theme = EventThemeCreate(**valid_data)
assert theme.fonts == valid_data["fonts"]
def test_optional_fields(self):
"""Test optional fields handling"""
minimal_data = {
"name": "Minimal Theme",
"color_palette": {"primary": "#000000"},
"fonts": {"main": "Arial"}
}
theme = EventThemeCreate(**minimal_data)
assert theme.description is None
assert theme.preview_image_url is None
@pytest.mark.parametrize("field,value", [
("name", "Updated Name"),
("color_palette", {"new": "#123456"}),
("fonts", {"new": "Times New Roman"}),
("description", "New description"),
("preview_image_url", "https://new-image.jpg"),
])
def test_update_individual_fields(self, field, value):
"""Test updating individual fields"""
update_data = {field: value}
theme = EventThemeUpdate(**update_data)
assert getattr(theme, field) == value
def test_theme_model_config(self):
"""Test model configuration"""
assert hasattr(EventThemeResponse.Config, 'from_attributes')
assert EventThemeResponse.Config.from_attributes is True