Add validation for display_order and EventMedia tests
Introduce a `validate_display_order` method to ensure a default value of 0 for `display_order`. Extend testing infrastructure with fixtures and unit tests for `EventMedia` to validate properties, metadata, and default behaviors.
This commit is contained in:
@@ -3,6 +3,7 @@ import pytest
|
||||
import uuid
|
||||
from app.models.user import User
|
||||
from app.utils.test_utils import setup_test_db, teardown_test_db
|
||||
from app.models import GiftItem, GiftStatus, GiftPriority, RSVP, RSVPStatus, EventMedia, MediaType, MediaPurpose
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
@@ -39,3 +40,74 @@ def mock_user(db_session):
|
||||
db_session.add(mock_user)
|
||||
db_session.commit()
|
||||
return mock_user
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def gift_item_fixture(db_session, mock_user):
|
||||
"""
|
||||
Fixture to create and return a default GiftItem instance.
|
||||
The event_id, added_by, and other necessary attributes are predefined.
|
||||
"""
|
||||
gift_item = GiftItem(
|
||||
id=uuid.uuid4(),
|
||||
event_id=uuid.uuid4(),
|
||||
added_by=mock_user.id,
|
||||
name="Default Gift",
|
||||
description="Default gift description.",
|
||||
price=100.00,
|
||||
currency="USD",
|
||||
quantity_requested=5,
|
||||
quantity_received=0,
|
||||
status=GiftStatus.AVAILABLE,
|
||||
priority=GiftPriority.MEDIUM,
|
||||
is_visible=True
|
||||
)
|
||||
db_session.add(gift_item)
|
||||
db_session.commit()
|
||||
return gift_item
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def rsvp_fixture(db_session, mock_user):
|
||||
"""
|
||||
Fixture to create and return a default RSVP instance.
|
||||
The event_id and guest_id fields are predefined for testing.
|
||||
"""
|
||||
rsvp = RSVP(
|
||||
id=uuid.uuid4(),
|
||||
event_id=uuid.uuid4(),
|
||||
guest_id=uuid.uuid4(),
|
||||
status=RSVPStatus.ATTENDING,
|
||||
number_of_guests=2,
|
||||
response_message="Looking forward to the event!",
|
||||
dietary_requirements="Vegetarian",
|
||||
)
|
||||
db_session.add(rsvp)
|
||||
db_session.commit()
|
||||
return rsvp
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def event_media_fixture(db_session, mock_user):
|
||||
"""
|
||||
Fixture to create and return a default EventMedia instance.
|
||||
"""
|
||||
event_media = EventMedia(
|
||||
id=uuid.uuid4(),
|
||||
event_id=uuid.uuid4(),
|
||||
uploaded_by=mock_user.id,
|
||||
file_path="uploads/sample.jpg",
|
||||
original_filename="sample.jpg",
|
||||
media_type=MediaType.IMAGE,
|
||||
content_type="image/jpeg",
|
||||
file_size=2048,
|
||||
purpose=MediaPurpose.GALLERY,
|
||||
is_public=True,
|
||||
display_order=1,
|
||||
title="Sample Image",
|
||||
description="A sample image for testing.",
|
||||
media_metadata={"resolution": "1920x1080"},
|
||||
)
|
||||
db_session.add(event_media)
|
||||
db_session.commit()
|
||||
return event_media
|
||||
|
||||
Reference in New Issue
Block a user