Files
homm/backend/apps/catalog/tests.py
T
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

50 lines
1.7 KiB
Python

from decimal import Decimal
from django.test import TestCase
from rest_framework.test import APIClient
from .models import Category, Product
class CatalogApiTests(TestCase):
def setUp(self):
self.client = APIClient()
self.category = Category.objects.create(
external_id="cat-1", name="Диваны", slug="divany"
)
self.product = Product.objects.create(
external_id="prod-1",
sku="SKU-1",
name="Диван Осло",
slug="divan-oslo",
category=self.category,
price=Decimal("49990.00"),
stock=5,
stock_status=Product.StockStatus.IN_STOCK,
is_hit=True,
is_new=True,
)
def test_product_list(self):
response = self.client.get("/api/v1/catalog/products/")
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data["count"], 1)
self.assertEqual(response.data["results"][0]["sku"], "SKU-1")
def test_hits_endpoint(self):
response = self.client.get("/api/v1/catalog/products/hits/")
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data["count"], 1)
def test_filter_by_price(self):
response = self.client.get(
"/api/v1/catalog/products/", {"price_min": "50000"}
)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data["count"], 0)
def test_product_detail(self):
response = self.client.get("/api/v1/catalog/products/divan-oslo/")
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data["name"], "Диван Осло")