Files
apuc 756f40353b Add Django backend, 1C integration, deploy config and API docs
Backend (Django 4.2 + DRF):
- accounts: phone OTP login, JWT, profile, addresses
- catalog: categories, products, images, filters, search, hits/new/related
- orders: creation with Idempotency-Key, stock reservation, status history, cancel
- loyalty: bonus accounts, promo codes, gift certificates
- payments: payment records and YooKassa webhook handling
- content: static pages, banners, site settings
- integration: 1C exchange (catalog sync, order push via outbox, statuses, bonuses)
- common: error envelope, pagination, request-id, integration auth, admin dashboard

Infrastructure: Dockerfile, docker-compose (Postgres, Redis, Celery worker/beat, Nginx),
requirements split by environment, OpenAPI contracts for site and 1C, architecture doc.

Tests: 22 pytest cases covering catalog, orders, idempotency, OTP, integration.
2026-11-22 21:54:16 +03:00

70 lines
2.7 KiB
Python
Raw Permalink 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 datetime import timedelta
from django.test import TestCase
from django.utils import timezone
from rest_framework.test import APIClient
from .models import Banner, SiteSettings, StaticPage
class ContentApiTests(TestCase):
def setUp(self):
self.client = APIClient()
def test_settings(self):
SiteSettings.objects.create(site_name="HOMM", phone="+79991234567")
response = self.client.get("/api/v1/content/settings/")
self.assertEqual(response.status_code, 200, response.data)
self.assertEqual(response.data["site_name"], "HOMM")
self.assertEqual(response.data["phone"], "+79991234567")
def test_pages_only_published(self):
StaticPage.objects.create(slug="about", title="О компании", is_published=True)
StaticPage.objects.create(slug="draft", title="Черновик", is_published=False)
response = self.client.get("/api/v1/content/pages/")
self.assertEqual(response.status_code, 200, response.data)
self.assertEqual(len(response.data), 1)
self.assertEqual(response.data[0]["slug"], "about")
def test_page_detail(self):
StaticPage.objects.create(slug="delivery", title="Доставка и оплата")
response = self.client.get("/api/v1/content/pages/delivery/")
self.assertEqual(response.status_code, 200, response.data)
self.assertEqual(response.data["title"], "Доставка и оплата")
def test_banners_filter_by_position_and_dates(self):
now = timezone.now()
Banner.objects.create(
title="Активный",
image_url="https://example.com/1.jpg",
position=Banner.Position.HOME_TOP,
is_active=True,
)
Banner.objects.create(
title="Неактивный",
image_url="https://example.com/2.jpg",
position=Banner.Position.HOME_TOP,
is_active=False,
)
Banner.objects.create(
title="Просроченный",
image_url="https://example.com/3.jpg",
position=Banner.Position.HOME_TOP,
is_active=True,
ends_at=now - timedelta(days=1),
)
Banner.objects.create(
title="Другая позиция",
image_url="https://example.com/4.jpg",
position=Banner.Position.CATEGORY,
is_active=True,
)
response = self.client.get(
"/api/v1/content/banners/", {"position": "home_top"}
)
self.assertEqual(response.status_code, 200, response.data)
self.assertEqual(len(response.data), 1)
self.assertEqual(response.data[0]["title"], "Активный")