Introduce a new pytest fixture for creating EventTheme instances and add comprehensive unit tests covering its properties, relationships, and behaviors. These changes improve test coverage and ensure the EventTheme model functions as expected.
105 lines
2.7 KiB
Python
105 lines
2.7 KiB
Python
# tests/models/test_event_theme.py
|
|
import uuid
|
|
from app.models.event_theme import EventTheme
|
|
|
|
|
|
def test_create_event_theme(db_session):
|
|
# Arrange
|
|
event_theme = EventTheme(
|
|
id=uuid.uuid4(),
|
|
name="Festive Theme",
|
|
description="A vibrant and colorful theme for celebrations.",
|
|
preview_image_url="https://example.com/preview/festive_theme.jpg",
|
|
color_palette={
|
|
"primary": "#e91e63",
|
|
"secondary": "#9c27b0",
|
|
"background": "#f9f9f9",
|
|
"text": "#333333"
|
|
},
|
|
fonts={
|
|
"header": "Lora",
|
|
"body": "Muli"
|
|
}
|
|
)
|
|
db_session.add(event_theme)
|
|
|
|
# Act
|
|
db_session.commit()
|
|
created_theme = db_session.query(EventTheme).filter_by(id=event_theme.id).first()
|
|
|
|
# Assert
|
|
assert created_theme is not None
|
|
assert created_theme.name == "Festive Theme"
|
|
assert created_theme.description == "A vibrant and colorful theme for celebrations."
|
|
assert created_theme.preview_image_url == "https://example.com/preview/festive_theme.jpg"
|
|
assert created_theme.color_palette == {
|
|
"primary": "#e91e63",
|
|
"secondary": "#9c27b0",
|
|
"background": "#f9f9f9",
|
|
"text": "#333333"
|
|
}
|
|
assert created_theme.fonts == {
|
|
"header": "Lora",
|
|
"body": "Muli"
|
|
}
|
|
|
|
|
|
def test_event_theme_relationship(event_theme_fixture, db_session):
|
|
# Assert
|
|
assert event_theme_fixture.events == [] # No events associated yet
|
|
|
|
|
|
def test_repr_method(event_theme_fixture):
|
|
# Act
|
|
repr_output = repr(event_theme_fixture)
|
|
|
|
# Assert
|
|
assert repr_output == f"<EventTheme {event_theme_fixture.name}>"
|
|
|
|
|
|
def test_color_palette_property(event_theme_fixture):
|
|
# Act
|
|
color_palette = event_theme_fixture.color_palette
|
|
|
|
# Assert
|
|
assert color_palette == {
|
|
"primary": "#ff5722",
|
|
"secondary": "#4caf50",
|
|
"background": "#ffffff",
|
|
"text": "#000000"
|
|
}
|
|
|
|
# Update and check
|
|
event_theme_fixture.color_palette = {
|
|
"primary": "#0000ff",
|
|
"secondary": "#00ff00",
|
|
"background": "#fefefe",
|
|
"text": "#111111"
|
|
}
|
|
assert event_theme_fixture.color_palette == {
|
|
"primary": "#0000ff",
|
|
"secondary": "#00ff00",
|
|
"background": "#fefefe",
|
|
"text": "#111111"
|
|
}
|
|
|
|
|
|
def test_fonts_property(event_theme_fixture):
|
|
# Act
|
|
fonts = event_theme_fixture.fonts
|
|
|
|
# Assert
|
|
assert fonts == {
|
|
"header": "Roboto",
|
|
"body": "Open Sans"
|
|
}
|
|
|
|
# Update and check
|
|
event_theme_fixture.fonts = {
|
|
"header": "Arial",
|
|
"body": "Verdana"
|
|
}
|
|
assert event_theme_fixture.fonts == {
|
|
"header": "Arial",
|
|
"body": "Verdana"
|
|
} |