Enhanced test coverage includes `repr` methods, model functionality, and validation logic for key models like `GiftItem`, `GiftCategory`, `EventMedia`, `RSVP`, and `GiftPurchase`. Refactored and added fixtures to support comprehensive testing scenarios. Addresses validation for gift reordering and updates `EventMedia` representation format for consistency.
113 lines
3.4 KiB
Python
113 lines
3.4 KiB
Python
# tests/models/test_event_media.py
|
|
import uuid
|
|
from app.models.event_media import EventMedia, MediaType, MediaPurpose
|
|
|
|
|
|
def test_create_event_media(db_session, mock_user):
|
|
# Arrange
|
|
event_media = EventMedia(
|
|
id=uuid.uuid4(),
|
|
event_id=uuid.uuid4(),
|
|
uploaded_by=mock_user.id,
|
|
file_path="uploads/test_image.jpg",
|
|
original_filename="test_image.jpg",
|
|
media_type=MediaType.IMAGE,
|
|
content_type="image/jpeg",
|
|
file_size=1024,
|
|
purpose=MediaPurpose.BANNER,
|
|
is_public=False,
|
|
display_order=0,
|
|
title="Test Image",
|
|
description="This is a test image.",
|
|
media_metadata={"resolution": "1024x768"},
|
|
)
|
|
db_session.add(event_media)
|
|
|
|
# Act
|
|
db_session.commit()
|
|
created_media = db_session.query(EventMedia).filter_by(id=event_media.id).first()
|
|
|
|
# Assert
|
|
assert created_media is not None
|
|
assert created_media.file_path == "uploads/test_image.jpg"
|
|
assert created_media.original_filename == "test_image.jpg"
|
|
assert created_media.media_type == MediaType.IMAGE
|
|
assert created_media.file_size == 1024
|
|
assert created_media.purpose == MediaPurpose.BANNER
|
|
assert created_media.is_public is False
|
|
assert created_media.media_metadata == {"resolution": "1024x768"}
|
|
|
|
|
|
def test_is_image_property(event_media_fixture):
|
|
# Act
|
|
is_image = event_media_fixture.is_image
|
|
|
|
# Assert
|
|
assert is_image is True # Fixture sets media_type to MediaType.IMAGE
|
|
|
|
# Update media type to VIDEO and re-check
|
|
event_media_fixture.media_type = MediaType.VIDEO
|
|
assert event_media_fixture.is_image is False
|
|
|
|
|
|
def test_is_video_property(event_media_fixture):
|
|
# Act
|
|
is_video = event_media_fixture.is_video
|
|
|
|
# Assert
|
|
assert is_video is False # Fixture sets media_type to MediaType.IMAGE
|
|
|
|
# Update media type to VIDEO and re-check
|
|
event_media_fixture.media_type = MediaType.VIDEO
|
|
assert event_media_fixture.is_video is True
|
|
|
|
|
|
def test_is_document_property(event_media_fixture):
|
|
# Act
|
|
is_document = event_media_fixture.is_document
|
|
|
|
# Assert
|
|
assert is_document is False # Fixture sets media_type to MediaType.IMAGE
|
|
|
|
# Update media type to DOCUMENT and re-check
|
|
event_media_fixture.media_type = MediaType.DOCUMENT
|
|
assert event_media_fixture.is_document is True
|
|
|
|
|
|
def test_url_property(event_media_fixture):
|
|
# Act
|
|
url = event_media_fixture.url
|
|
|
|
# Assert
|
|
# Since the `url` method is not implemented, it should currently return None
|
|
assert url is None # Implement this logic if further changes are made
|
|
|
|
|
|
def test_default_display_order(event_media_fixture):
|
|
# Arrange
|
|
event_media_fixture.display_order = None
|
|
|
|
# Assert default value
|
|
# Ensure display_order defaults to 0
|
|
assert event_media_fixture.display_order == 0
|
|
|
|
|
|
def test_media_metadata(event_media_fixture):
|
|
# Act
|
|
metadata = event_media_fixture.media_metadata
|
|
|
|
# Assert
|
|
assert metadata == {"resolution": "1920x1080"}
|
|
|
|
# Update and check
|
|
event_media_fixture.media_metadata = {"resolution": "1280x720"}
|
|
assert event_media_fixture.media_metadata == {"resolution": "1280x720"}
|
|
|
|
def test_event_media_repr(event_media_fixture):
|
|
# Act
|
|
result = repr(event_media_fixture)
|
|
|
|
# Assert
|
|
expected = f"<EventMedia {event_media_fixture.original_filename} ({event_media_fixture.media_type.value}) for event={event_media_fixture.event_id}>"
|
|
assert result == expected
|