"""Test Ledger Accounting Run Balance schema.""" from decimal import Decimal from ledger.schemas.ledger_accounting_run_balance import ( LedgerAccountingRunBalanceDetailSchema, LedgerAccountingRunBalancePostSchema, LedgerAccountingRunBalanceVatDetailSchema, ) from tests.utils.factories import LedgerAccountingRunBalanceFactory def test_ledger_accounting_run_balance_schema_load(): """Test Ledger Accounting Run Balance schema loading.""" test_data = [ { 'abacus_event_id': 1, 'adjusted_net_revenue': Decimal('436.31'), 'contract_id': 1, 'currency_code': 'EUR', 'distribution_fee': Decimal('95.00'), 'total_gross_revenue_amount': Decimal('531.31'), 'total_net_revenue_amount': Decimal('436.31'), } ] entries = LedgerAccountingRunBalancePostSchema(many=True).load(test_data) assert entries[0] == test_data[0] def test_ledger_accounting_run_balance_schema_dump(mock_event_fixtures): """Test Ledger Accounting Run Balance schema dumping.""" entity = LedgerAccountingRunBalanceFactory.create() res = LedgerAccountingRunBalanceDetailSchema().dump(entity) assert res == { 'ledger_accounting_run_balance_id': entity.ledger_accounting_run_balance_id, 'accounting_run_id': entity.accounting_run_id, 'abacus_event_id': entity.abacus_event_id, 'adjusted_net_revenue': str(entity.adjusted_net_revenue), 'contract_id': entity.contract_id, 'currency_code': entity.currency_code, 'distribution_fee': str(entity.distribution_fee), 'mechanical_deduction_admin_fee_total': str( entity.mechanical_deduction_admin_fee_total ), 'mechanical_deduction_total': str(entity.mechanical_deduction_total), 'total_gross_revenue_amount': str(entity.total_gross_revenue_amount), 'total_net_revenue_amount': str(entity.total_net_revenue_amount), } def test_ledger_accounting_run_balance_vat_schema_dump(mock_event_fixtures): """Test Ledger Accounting Run Balance schema dumping.""" entity = LedgerAccountingRunBalanceFactory.create() entity.country_of_tax_residence = 'GBR' entity.payment_entity_id = 1 entity.is_vat_exempt = 1 res = LedgerAccountingRunBalanceVatDetailSchema().dump(entity) assert res == { 'ledger_accounting_run_balance_id': entity.ledger_accounting_run_balance_id, 'accounting_run_id': entity.accounting_run_id, 'abacus_event_id': entity.abacus_event_id, 'adjusted_net_revenue': str(entity.adjusted_net_revenue), 'contract_id': entity.contract_id, 'country_of_tax_residence': entity.country_of_tax_residence, 'currency_code': entity.currency_code, 'distribution_fee': str(entity.distribution_fee), 'is_vat_exempt': True, 'mechanical_deduction_admin_fee_total': str( entity.mechanical_deduction_admin_fee_total ), 'mechanical_deduction_total': str(entity.mechanical_deduction_total), 'total_gross_revenue_amount': str(entity.total_gross_revenue_amount), 'total_net_revenue_amount': str(entity.total_net_revenue_amount), 'payment_entity_id': entity.payment_entity_id, }