Add CRUD operations and tests for Event model
This commit introduces a new CRUDEvent class to manage event-related database operations, including retrieval, creation, updating, and deletion of events. It includes corresponding unit tests to ensure the correctness of these functionalities, updates event schemas for enhanced validation, and refines timezone handling for event dates and deadlines.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# tests/conftest.py
|
||||
import uuid
|
||||
from datetime import datetime, timezone
|
||||
from datetime import datetime, timezone, timedelta
|
||||
from typing import Dict
|
||||
|
||||
import pytest
|
||||
@@ -73,28 +73,25 @@ def mock_user(db_session):
|
||||
|
||||
@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
|
||||
)
|
||||
"""Create a test event fixture."""
|
||||
event_data = {
|
||||
"title": "Birthday Party",
|
||||
"slug": "birthday-party",
|
||||
"description": "A test birthday party",
|
||||
"event_date": datetime.now(tz=timezone.utc) + timedelta(days=30),
|
||||
"timezone": "UTC",
|
||||
"is_public": True, # Make sure this is set to True
|
||||
"created_by": mock_user.id
|
||||
}
|
||||
|
||||
event = Event(**event_data)
|
||||
db_session.add(event)
|
||||
db_session.commit()
|
||||
db_session.refresh(event)
|
||||
return event
|
||||
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def gift_item_fixture(db_session, mock_user):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user