Files
santeh-ray/home/tests.py
Azimkin 4f4a1a55e5
All checks were successful
Build and Push Docker Image / build (push) Successful in 43s
feat: add FAQ question form with email notifications and validations
- Created `FaqQuestionForm` in `forms.py` with custom field validations
- Added FAQ form to the FAQ section with CSRF protection and error handling
- Integrated email notifications to administrator upon FAQ submission
- Updated styles and scripts for form inputs, validation messages, and messages UI
- Adjusted FAQ section layout in `faq.html` and related CSS for responsiveness
- Implemented tests for FAQ form submission and email notifications
2026-04-19 22:51:56 +02:00

39 lines
1.6 KiB
Python

from django.core import mail
from django.test import TestCase, override_settings
from django.urls import reverse
@override_settings(EMAIL_BACKEND="django.core.mail.backends.locmem.EmailBackend", ADMINISTRATOR_EMAIL="admin@example.com")
class FaqQuestionTests(TestCase):
def test_faq_question_form_sends_email_to_administrator(self):
response = self.client.post(
reverse("home"),
data={
"name": "Иван Петров",
"phone": "+375291112233",
"question": "Сколько стоит доставка?",
"accept": "on",
},
)
self.assertEqual(response.status_code, 302)
self.assertEqual(response["Location"], reverse("home") + "#faq-section")
self.assertEqual(len(mail.outbox), 1)
self.assertEqual(mail.outbox[0].to, ["admin@example.com"])
self.assertIn("Иван Петров", mail.outbox[0].body)
self.assertIn("Сколько стоит доставка?", mail.outbox[0].body)
def test_faq_question_form_requires_consent(self):
response = self.client.post(
reverse("home"),
data={
"name": "Иван Петров",
"phone": "+375291112233",
"question": "Сколько стоит доставка?",
},
)
self.assertEqual(response.status_code, 200)
self.assertEqual(len(mail.outbox), 0)
self.assertContains(response, "Необходимо согласие на обработку персональных данных.")