- Создан новый класс SystemCustomerProtectionTestCase с 5 критичными тестами - Тест создания системного клиента с правильными атрибутами - Тест защиты от удаления системного клиента (ValidationError) - Тест защиты email системного клиента от изменения - Тест защиты флага is_system_customer от изменения - Тест что обычные клиенты не затронуты защитой - Исправлена логика в Customer.save(): проверка теперь использует original.is_system_customer - Добавлен импорт ValidationError из django.core.exceptions - Рефакторинг структуры тестов customers: - Разделены тесты по отдельным модулям в папке customers/tests/ - test_search_strategies.py - тесты стратегий поиска - test_system_customer.py - тесты защиты системного клиента - test_wallet_balance.py - тесты баланса кошелька - test_wallet_service.py - тесты WalletService - test_wallet_model.py - тесты модели WalletTransaction - Обновлён анализ тестов: 50 тестов (было 45), все проходят успешно - Критичная функциональность POS системы теперь покрыта тестами - Учтена tenant-система (используется TenantTestCase)
50 lines
1.7 KiB
Python
50 lines
1.7 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""
|
||
Тесты для модели WalletTransaction.
|
||
|
||
Используем TenantTestCase для корректной работы с tenant-системой.
|
||
"""
|
||
from decimal import Decimal
|
||
|
||
from django.core.cache import cache
|
||
from django_tenants.test.cases import TenantTestCase
|
||
|
||
from customers.models import Customer, WalletTransaction
|
||
|
||
|
||
class WalletTransactionModelTestCase(TenantTestCase):
|
||
"""Тесты модели WalletTransaction."""
|
||
|
||
def setUp(self):
|
||
self.customer = Customer.objects.create(name="Тестовый клиент")
|
||
cache.clear()
|
||
|
||
def test_str_representation_positive(self):
|
||
"""__str__ для положительной суммы содержит +."""
|
||
txn = WalletTransaction.objects.create(
|
||
customer=self.customer,
|
||
signed_amount=Decimal('100.00'),
|
||
transaction_type='deposit',
|
||
balance_category='money'
|
||
)
|
||
self.assertIn('+100', str(txn))
|
||
|
||
def test_str_representation_negative(self):
|
||
"""__str__ для отрицательной суммы содержит -."""
|
||
txn = WalletTransaction.objects.create(
|
||
customer=self.customer,
|
||
signed_amount=Decimal('-50.00'),
|
||
transaction_type='spend',
|
||
balance_category='money'
|
||
)
|
||
self.assertIn('-50', str(txn))
|
||
|
||
def test_default_balance_category(self):
|
||
"""По умолчанию balance_category = 'money'."""
|
||
txn = WalletTransaction.objects.create(
|
||
customer=self.customer,
|
||
signed_amount=Decimal('100.00'),
|
||
transaction_type='deposit'
|
||
)
|
||
self.assertEqual(txn.balance_category, 'money')
|