Files
octopus/myproject/customers/tests/test_wallet_model.py
Andrey Smakotin dbbac933af Добавлены тесты защиты системного клиента и рефакторинг структуры тестов
- Создан новый класс 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)
2025-12-28 00:32:45 +03:00

50 lines
1.7 KiB
Python
Raw 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.
# -*- 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')