Add tests for EmailTemplate and NotificationLog models
Introduced comprehensive unit tests for EmailTemplate and NotificationLog, including creation, field validation, and custom methods. Added relevant test fixtures to support these models and expanded `conftest.py` for reusability. Validates functionality and maintains model integrity.
This commit is contained in:
@@ -5,7 +5,8 @@ from datetime import datetime, timezone
|
||||
import pytest
|
||||
|
||||
from app.models import GiftItem, GiftStatus, GiftPriority, RSVP, RSVPStatus, EventMedia, MediaType, MediaPurpose, \
|
||||
EventTheme, Guest, GuestStatus, ActivityType, ActivityLog
|
||||
EventTheme, Guest, GuestStatus, ActivityType, ActivityLog, EmailTemplate, TemplateType, NotificationLog, \
|
||||
NotificationType, NotificationStatus
|
||||
from app.models.user import User
|
||||
from app.utils.test_utils import setup_test_db, teardown_test_db
|
||||
|
||||
@@ -193,3 +194,48 @@ def activity_log_fixture(db_session, mock_user, guest_fixture):
|
||||
db_session.add(activity_log_entry)
|
||||
db_session.commit()
|
||||
return activity_log_entry
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def email_template_fixture(db_session, mock_user):
|
||||
"""
|
||||
Fixture to create and return a default EmailTemplate instance.
|
||||
"""
|
||||
email_template = EmailTemplate(
|
||||
id=uuid.uuid4(),
|
||||
name="Invitation Template",
|
||||
description="A template for event invitations.",
|
||||
template_type=TemplateType.INVITATION,
|
||||
subject="You're invited to {{event_name}}!",
|
||||
html_content="<h1>Welcome to {{event_name}}</h1><p>We look forward to seeing you!</p>",
|
||||
text_content="Welcome to {{event_name}}. We look forward to seeing you!",
|
||||
variables={"event_name": "Birthday Party"},
|
||||
event_id=None, # Global template
|
||||
created_by=mock_user.id,
|
||||
is_active=True,
|
||||
is_system=False,
|
||||
)
|
||||
db_session.add(email_template)
|
||||
db_session.commit()
|
||||
return email_template
|
||||
|
||||
@pytest.fixture
|
||||
def notification_log_fixture(db_session, email_template_fixture, guest_fixture):
|
||||
"""
|
||||
Fixture to create and return a default NotificationLog entry.
|
||||
"""
|
||||
notification_log = NotificationLog(
|
||||
id=uuid.uuid4(),
|
||||
notification_type=NotificationType.EMAIL,
|
||||
status=NotificationStatus.QUEUED,
|
||||
subject="You're invited!",
|
||||
content_preview="Join us for an unforgettable event.",
|
||||
template_id=email_template_fixture.id,
|
||||
event_id=guest_fixture.event_id,
|
||||
guest_id=guest_fixture.id,
|
||||
recipient="example@example.com",
|
||||
notification_metadata={"extra_info": "Email sent via SendGrid"},
|
||||
)
|
||||
db_session.add(notification_log)
|
||||
db_session.commit()
|
||||
return notification_log
|
||||
Reference in New Issue
Block a user