Add and extend test coverage for models and their methods
All checks were successful
Build and Push Docker Images / changes (push) Successful in 4s
Build and Push Docker Images / build-backend (push) Successful in 49s
Build and Push Docker Images / build-frontend (push) Has been skipped

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:
2025-02-28 15:57:32 +01:00
parent c15c55d691
commit 1fd1144bc1
6 changed files with 256 additions and 6 deletions

View File

@@ -46,7 +46,8 @@ class EventMedia(Base, UUIDMixin, TimestampMixin):
uploader = relationship("User", foreign_keys=[uploaded_by])
def __repr__(self):
return f"<EventMedia {self.original_filename} ({self.media_type}) for event={self.event_id}>"
return f"<EventMedia {self.original_filename} ({self.media_type.value}) for event={self.event_id}>"
@validates('display_order')
def validate_display_order(self, key, value):

View File

@@ -174,6 +174,13 @@ class GiftCategory(Base, UUIDMixin, TimestampMixin):
Args:
gift_ids: List of gift IDs in desired order
"""
# Validate gift IDs
existing_gift_ids = {gift.id for gift in self.gifts}
for gift_id in gift_ids:
if gift_id not in existing_gift_ids:
raise ValueError(f"Gift ID {gift_id} not found in category")
# Reorder logic
gift_order = {gift_id: idx for idx, gift_id in enumerate(gift_ids)}
for gift in self.gifts:
if gift.id in gift_order: