Files
homm/backend/apps/loyalty/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

45 lines
1.5 KiB
Python

from decimal import Decimal
from django.test import TestCase
from rest_framework.test import APIClient
from .models import GiftCertificate, PromoCode
class LoyaltyApiTests(TestCase):
def setUp(self):
self.client = APIClient()
def test_promo_validate(self):
PromoCode.objects.create(
code="SALE10",
discount_type=PromoCode.DiscountType.PERCENT,
value=Decimal("10"),
)
response = self.client.post(
"/api/v1/loyalty/promo/validate/",
{"code": "SALE10", "subtotal": "1000.00"},
format="json",
)
self.assertEqual(response.status_code, 200, response.data)
self.assertEqual(Decimal(response.data["discount"]), Decimal("100.00"))
def test_certificate_validate_does_not_spend_balance(self):
certificate = GiftCertificate.objects.create(
code="CERT-1",
nominal=Decimal("1000.00"),
balance=Decimal("1000.00"),
status=GiftCertificate.Status.ACTIVE,
)
response = self.client.post(
"/api/v1/loyalty/certificate/validate/",
{"code": "CERT-1", "amount": "500.00"},
format="json",
)
self.assertEqual(response.status_code, 200, response.data)
self.assertEqual(Decimal(response.data["applied"]), Decimal("500.00"))
self.assertEqual(Decimal(response.data["remaining"]), Decimal("500.00"))
certificate.refresh_from_db()
self.assertEqual(certificate.balance, Decimal("1000.00"))