Files
santeh-ray/home/tests.py
Azimkin 52cbc1c2b3
All checks were successful
Build and Push Docker Image / build (push) Successful in 42s
feat: implement shopping cart feature with user authentication support
- Added `Cart` and `CartItem` models with migrations for managing user-specific carts and items
- Developed services for cart-related operations: adding, removing, and updating cart items
- Built specialized templates (`cart.html`) and styled them with new CSS assets (`cart.css`)
- Enabled real-time UI updates via AJAX in shopping cart interactions (`cart.js`)
- Modified header to dynamically display cart link with user authentication awareness
- Added Leaflet-based interactive map to the contacts page and integrated CSS/JS dependencies
- Expanded tests for cart functionality, item detail page cart integration, and contacts page maps
2026-05-15 23:18:16 +02:00

89 lines
3.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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")
class ContactsPageTests(TestCase):
def test_contacts_page_renders_contact_details(self):
response = self.client.get(reverse("contacts"))
self.assertEqual(response.status_code, 200)
self.assertContains(response, "КОНТАКТЫ")
self.assertContains(response, "Беларусь, г. Минск, ул. Тимирязева, д. 123, к.1, пав. 59")
self.assertContains(response, "info@santehray.by")
self.assertContains(response, "+375 (29) 688-18-19")
self.assertContains(response, "+375 (33) 337-67-81")
def test_contacts_page_includes_leaflet_map_assets(self):
response = self.client.get(reverse("contacts"))
self.assertEqual(response.status_code, 200)
self.assertContains(response, "https://unpkg.com/leaflet@1.9.4/dist/leaflet.css")
self.assertContains(response, "https://unpkg.com/leaflet@1.9.4/dist/leaflet.js")
self.assertContains(response, 'id="contacts-map"', html=False)
self.assertContains(response, "L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'")
self.assertContains(response, "OpenStreetMap")
def test_contacts_page_does_not_include_yandex_api(self):
response = self.client.get(reverse("contacts"))
self.assertEqual(response.status_code, 200)
self.assertNotContains(response, "api-maps.yandex.ru")
self.assertNotContains(response, "YANDEX_MAPS_API_KEY")
self.assertContains(response, 'data-lat="53.9334960"', html=False)
self.assertContains(response, 'data-lon="27.4551021"', html=False)
self.assertContains(response, "Открыть адрес в OpenStreetMap")