Additional fixes for gift models

This commit is contained in:
2025-03-16 15:33:17 +01:00
parent b5f1c7ddcb
commit 19f3534f22
4 changed files with 116 additions and 34 deletions

View File

@@ -135,7 +135,6 @@ def test_create_gift_category(db_session, mock_user):
# Arrange
category = GiftCategory(
id=uuid.uuid4(),
event_id=uuid.uuid4(),
created_by=mock_user.id,
name="Toys",
description="All kinds of educational toys."
@@ -153,18 +152,29 @@ def test_create_gift_category(db_session, mock_user):
def test_gift_category_total_gifts(db_session, mock_user):
# Arrange
event_id = uuid.uuid4()
category = GiftCategory(
id=uuid.uuid4(),
event_id=uuid.uuid4(),
created_by=mock_user.id,
name="Baby Essentials",
)
db_session.add(category)
db_session.commit()
# Create the association between the category and the event
from app.models.gift import EventGiftCategory
event_gift_category = EventGiftCategory(
event_id=event_id,
category_id=category.id,
display_order=0,
is_visible=True
)
db_session.add(event_gift_category)
db_session.commit()
gift1 = GiftItem(
id=uuid.uuid4(),
event_id=category.event_id,
event_id=event_id,
category_id=category.id,
name="Bottle Set",
quantity_requested=2,
@@ -173,7 +183,7 @@ def test_gift_category_total_gifts(db_session, mock_user):
)
gift2 = GiftItem(
id=uuid.uuid4(),
event_id=category.event_id,
event_id=event_id,
category_id=category.id,
name="Diaper Bag",
quantity_requested=1,
@@ -200,6 +210,12 @@ def test_gift_category_available_gifts(db_session, gift_category_fixture, gift_i
"""
Test that the available_gifts method correctly counts the available gifts.
"""
# Get the event_id from the EventGiftCategory association
from app.models.gift import EventGiftCategory
event_gift_category = db_session.query(EventGiftCategory).filter_by(
category_id=gift_category_fixture.id
).first()
# Update gift_item_fixture to match the gift_category_fixture
gift_item = GiftItem(
name="Toy Car",
@@ -211,7 +227,7 @@ def test_gift_category_available_gifts(db_session, gift_category_fixture, gift_i
status=GiftStatus.AVAILABLE,
is_visible=True,
category_id=gift_category_fixture.id,
event_id=gift_category_fixture.event_id, # Ensure event linkage
event_id=event_gift_category.event_id, # Get event_id from association
added_by=gift_category_fixture.created_by # Link to a user
)
db_session.add(gift_item)
@@ -225,6 +241,12 @@ def test_gift_category_reorder_gifts(db_session, gift_category_fixture, mock_use
Test that the reorder_gifts method correctly updates gift display_order
based on the provided order of gift IDs.
"""
# Get the event_id from the EventGiftCategory association
from app.models.gift import EventGiftCategory
event_gift_category = db_session.query(EventGiftCategory).filter_by(
category_id=gift_category_fixture.id
).first()
# Create GiftItems with proper required fields and UUID objects (not strings)
gift1_id = uuid.uuid4()
gift2_id = uuid.uuid4()
@@ -235,7 +257,7 @@ def test_gift_category_reorder_gifts(db_session, gift_category_fixture, mock_use
name="Gift 1",
display_order=0,
category_id=gift_category_fixture.id,
event_id=gift_category_fixture.event_id, # Required field
event_id=event_gift_category.event_id, # Get event_id from association
added_by=gift_category_fixture.created_by, # Required field
status=GiftStatus.AVAILABLE # Required field
)
@@ -244,7 +266,7 @@ def test_gift_category_reorder_gifts(db_session, gift_category_fixture, mock_use
name="Gift 2",
display_order=1,
category_id=gift_category_fixture.id,
event_id=gift_category_fixture.event_id,
event_id=event_gift_category.event_id, # Get event_id from association
added_by=gift_category_fixture.created_by,
status=GiftStatus.AVAILABLE
)
@@ -253,7 +275,7 @@ def test_gift_category_reorder_gifts(db_session, gift_category_fixture, mock_use
name="Gift 3",
display_order=2,
category_id=gift_category_fixture.id,
event_id=gift_category_fixture.event_id,
event_id=event_gift_category.event_id, # Get event_id from association
added_by=gift_category_fixture.created_by,
status=GiftStatus.AVAILABLE
)
@@ -345,4 +367,4 @@ def test_gift_purchase_repr(db_session, gift_purchase_fixture):
repr_output = repr(gift_purchase_fixture)
# Assert
assert repr_output == f"<GiftPurchase gift_id={gift_purchase_fixture.gift_id} guest_id={gift_purchase_fixture.guest_id}>"
assert repr_output == f"<GiftPurchase gift_id={gift_purchase_fixture.gift_id} guest_id={gift_purchase_fixture.guest_id}>"