Add and extend test coverage for models and their methods
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.
This commit is contained in:
@@ -4,7 +4,8 @@ from datetime import datetime, timezone
|
||||
|
||||
import pytest
|
||||
|
||||
from app.models import GiftItem, GiftStatus, GiftPriority, RSVP, RSVPStatus, EventMedia, MediaType, MediaPurpose, \
|
||||
from app.models import Event, GiftItem, GiftStatus, GiftPriority, GiftCategory, GiftPurchase, RSVP, RSVPStatus, \
|
||||
EventMedia, MediaType, MediaPurpose, \
|
||||
EventTheme, Guest, GuestStatus, ActivityType, ActivityLog, EmailTemplate, TemplateType, NotificationLog, \
|
||||
NotificationType, NotificationStatus
|
||||
from app.models.user import User
|
||||
@@ -47,6 +48,31 @@ def mock_user(db_session):
|
||||
return mock_user
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def event_fixture(db_session, mock_user):
|
||||
"""
|
||||
Fixture to create and return an Event instance with valid data.
|
||||
"""
|
||||
event = Event(
|
||||
id=uuid.uuid4(),
|
||||
title="Birthday Party",
|
||||
slug="birthday-party-1", # Required unique slug
|
||||
description="A special 1st birthday celebration event.",
|
||||
event_date=datetime(2023, 12, 25, tzinfo=timezone.utc),
|
||||
timezone="UTC", # Required timezone
|
||||
created_by=mock_user.id, # Reference to a valid mock_user
|
||||
is_public=False, # Default value
|
||||
is_active=True, # Default value
|
||||
rsvp_enabled=False, # Default value
|
||||
gift_registry_enabled=True, # Default value
|
||||
updates_enabled=True # Default value
|
||||
)
|
||||
db_session.add(event)
|
||||
db_session.commit()
|
||||
return event
|
||||
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def gift_item_fixture(db_session, mock_user):
|
||||
"""
|
||||
@@ -219,6 +245,7 @@ def email_template_fixture(db_session, mock_user):
|
||||
db_session.commit()
|
||||
return email_template
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def notification_log_fixture(db_session, email_template_fixture, guest_fixture):
|
||||
"""
|
||||
@@ -238,4 +265,43 @@ def notification_log_fixture(db_session, email_template_fixture, guest_fixture):
|
||||
)
|
||||
db_session.add(notification_log)
|
||||
db_session.commit()
|
||||
return notification_log
|
||||
return notification_log
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def gift_purchase_fixture(db_session, gift_item_fixture, guest_fixture):
|
||||
"""
|
||||
Fixture to create and return a GiftPurchase instance.
|
||||
"""
|
||||
gift_purchase = GiftPurchase(
|
||||
id=uuid.uuid4(),
|
||||
gift_id=gift_item_fixture.id,
|
||||
guest_id=guest_fixture.id,
|
||||
quantity=1,
|
||||
purchased_at=datetime.now(timezone.utc),
|
||||
purchase_price=25.0,
|
||||
purchase_currency="USD",
|
||||
notes="Gift purchased through store link"
|
||||
)
|
||||
db_session.add(gift_purchase)
|
||||
db_session.commit()
|
||||
return gift_purchase
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def gift_category_fixture(db_session, mock_user, event_fixture):
|
||||
"""
|
||||
Fixture to create and return a GiftCategory instance.
|
||||
"""
|
||||
gift_category = GiftCategory(
|
||||
id=uuid.uuid4(),
|
||||
name="Electronics",
|
||||
description="Category for electronic gifts",
|
||||
event_id=event_fixture.id,
|
||||
created_by=mock_user.id,
|
||||
display_order=0,
|
||||
is_visible=True
|
||||
)
|
||||
db_session.add(gift_category)
|
||||
db_session.commit()
|
||||
return gift_category
|
||||
|
||||
Reference in New Issue
Block a user