All checks were successful
Build and Push Docker Image / build (push) Successful in 45s
57 lines
2.2 KiB
Python
57 lines
2.2 KiB
Python
from django.conf import settings
|
|
from django.core import mail
|
|
from django.test import SimpleTestCase, TestCase, override_settings
|
|
from django.urls import reverse, resolve
|
|
|
|
|
|
@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, "Необходимо согласие на обработку персональных данных.")
|
|
|
|
|
|
class FaviconTests(SimpleTestCase):
|
|
def test_favicon_route_returns_icon(self):
|
|
response = self.client.get(reverse("favicon"))
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
self.assertEqual(response["Content-Type"], "image/svg+xml")
|
|
self.assertIn(b"<svg", response.content)
|
|
|
|
|
|
class MediaUrlTests(SimpleTestCase):
|
|
def test_media_route_is_registered(self):
|
|
match = resolve(f"{settings.MEDIA_URL}items/example.jpg")
|
|
|
|
self.assertEqual(match.func.__module__, "django.views.static")
|
|
self.assertEqual(match.func.__name__, "serve")
|