# -*- 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')