EMAIL_TEMPLATE/tests/test_forms.py
Patsy dec4fbe68d
Some checks failed
CI/CD Pipeline / test (push) Has been cancelled
Phase 1 done
2026-08-07 16:46:44 +02:00

70 lines
No EOL
2 KiB
Python

"""
Tests for Café Bach Email Generator - Form Validation
"""
import pytest
from app.forms import EmailGeneratorForm
def test_email_form_valid_data():
"""Test form with valid data."""
form = EmailGeneratorForm(
title='Test Event',
date_time='2024-12-25 18:00:00',
location='Test Location',
description='This is a test event description.',
button_text='RSVP Now',
button_url='https://example.com/rsvp',
)
assert form.validate_on_submit() is False # validate_on_submit requires POST context
assert form.title.data == 'Test Event'
assert form.location.data == 'Test Location'
def test_email_form_missing_required_fields():
"""Test form with missing required fields."""
form = EmailGeneratorForm()
assert not form.validate()
def test_email_form_title_length():
"""Test title length validation."""
long_title = 'A' * 101
form = EmailGeneratorForm(title=long_title)
assert not form.validate()
def test_email_form_description_length():
"""Test description length validation."""
long_desc = 'A' * 2001
form = EmailGeneratorForm(description=long_desc)
assert not form.validate()
def test_email_form_button_text_length():
"""Test button text length validation."""
long_text = 'A' * 51
form = EmailGeneratorForm(button_text=long_text)
assert not form.validate()
def test_email_form_next_event_text_length():
"""Test next event text length validation."""
long_text = 'A' * 101
form = EmailGeneratorForm(next_event_text=long_text)
assert not form.validate()
def test_email_form_optional_image_url():
"""Test that image URL is optional."""
form = EmailGeneratorForm(
title='Test',
date_time='2024-12-25 18:00:00',
location='Test',
description='Test',
button_text='RSVP',
button_url='https://example.com',
)
# Should validate without image_url
assert form.title.is.data == 'Test'
assert form.location.data == 'Test'