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.
83 lines
2.9 KiB
Python
83 lines
2.9 KiB
Python
from decimal import Decimal
|
|
|
|
from django.conf import settings
|
|
from django.test import TestCase
|
|
from rest_framework.test import APIClient
|
|
|
|
from apps.catalog.models import Product
|
|
from apps.orders.models import Order
|
|
|
|
|
|
class IntegrationApiTests(TestCase):
|
|
def setUp(self):
|
|
self.client = APIClient()
|
|
self.token = settings.INTEGRATION_API_TOKEN
|
|
|
|
def test_requires_token(self):
|
|
response = self.client.get("/api/v1/integration/1c/health/")
|
|
self.assertEqual(response.status_code, 401)
|
|
|
|
def test_catalog_sync(self):
|
|
payload = {
|
|
"sync_id": "sync-1",
|
|
"categories": [{"external_id": "c1", "name": "Кресла"}],
|
|
"products": [
|
|
{
|
|
"external_id": "p1",
|
|
"sku": "SKU-1",
|
|
"name": "Кресло Эймс",
|
|
"price": "1000.00",
|
|
"stock": 3,
|
|
"category_external_id": "c1",
|
|
"images": [
|
|
{"url": "https://example.com/1.jpg", "is_main": True}
|
|
],
|
|
}
|
|
],
|
|
}
|
|
response = self.client.post(
|
|
"/api/v1/integration/1c/catalog/sync/",
|
|
payload,
|
|
format="json",
|
|
HTTP_X_INTEGRATION_TOKEN=self.token,
|
|
)
|
|
self.assertEqual(response.status_code, 200, response.data)
|
|
self.assertEqual(response.data["stats"]["products_created"], 1)
|
|
|
|
product = Product.objects.get(external_id="p1")
|
|
self.assertEqual(product.price, Decimal("1000.00"))
|
|
self.assertEqual(product.stock, 3)
|
|
self.assertEqual(product.images.count(), 1)
|
|
|
|
def test_order_status_update(self):
|
|
order = Order.objects.create(
|
|
customer_name="Иван",
|
|
phone="+79991234567",
|
|
total=Decimal("1000.00"),
|
|
)
|
|
response = self.client.post(
|
|
f"/api/v1/integration/1c/orders/{order.number}/status/",
|
|
{"status": "Выполнен", "comment": "Выдан клиенту"},
|
|
format="json",
|
|
HTTP_X_INTEGRATION_TOKEN=self.token,
|
|
)
|
|
self.assertEqual(response.status_code, 200, response.data)
|
|
order.refresh_from_db()
|
|
self.assertEqual(order.status, Order.Status.COMPLETED)
|
|
self.assertEqual(order.status_history.count(), 1)
|
|
|
|
def test_unknown_status_is_rejected(self):
|
|
order = Order.objects.create(
|
|
customer_name="Иван",
|
|
phone="+79991234567",
|
|
total=Decimal("1000.00"),
|
|
)
|
|
response = self.client.post(
|
|
f"/api/v1/integration/1c/orders/{order.number}/status/",
|
|
{"status": "Неизвестный статус"},
|
|
format="json",
|
|
HTTP_X_INTEGRATION_TOKEN=self.token,
|
|
)
|
|
self.assertEqual(response.status_code, 400)
|
|
self.assertEqual(response.data["error"]["code"], "unknown_status")
|