"""Tests for WorksheetAccountContractTaxableRevenue schemas.""" from decimal import Decimal from marshmallow.exceptions import ValidationError import pytest from payment.schemas.worksheet_account_contract_taxable_revenue import ( WorksheetAccountContractTaxableRevenueCreateSchema, WorksheetAccountContractTaxableRevenueDetailSchema, WorksheetAccountContractTaxableRevenueListSchema, ) def test_worksheet_account_contract_taxable_revenue_create_schema_success(): """Test WorksheetAccountContractTaxableRevenueCreateSchema validation success.""" test_data = { 'account_id': 2, 'contract_id': 2, 'statement_period_id': 2, 'reference_payment_entity_id': 1, 'amount': '20.00', 'currency_code': 'USD', 'is_us_revenue': True, 'revenue_transaction_type': 'closing_balance', } result = WorksheetAccountContractTaxableRevenueCreateSchema().load(test_data) assert result == {**test_data, 'amount': Decimal(test_data['amount'])} def test_worksheet_account_contract_taxable_revenue_create_schema_failure(): """Test WorksheetAccountContractTaxableRevenueCreateSchema validation failure.""" with pytest.raises(ValidationError) as exc_info: WorksheetAccountContractTaxableRevenueCreateSchema().load({}) assert set(exc_info.value.messages_dict.keys()) == { 'account_id', 'contract_id', 'statement_period_id', 'reference_payment_entity_id', 'amount', 'currency_code', 'is_us_revenue', 'revenue_transaction_type', } def test_worksheet_account_contract_taxable_revenue_detail_schema(): """Test WorksheetAccountContractTaxableRevenueDetailSchema.""" test_data = { 'account_contract_taxable_revenue_id': 1, 'worksheet_account_contract_closing_balance_id': 1, 'account_id': 2, 'contract_id': 2, 'statement_period_id': 2, 'reference_payment_entity_id': 1, 'amount': Decimal('20.00'), 'currency_code': 'USD', 'is_us_revenue': True, 'revenue_transaction_type': 'closing_balance', } result = WorksheetAccountContractTaxableRevenueDetailSchema().dump(test_data) assert result == {**test_data, 'amount': str(test_data['amount'])} def test_worksheet_account_contract_taxable_revenue_list_schema(): """Test WorksheetAccountContractTaxableRevenueListSchema.""" test_data = { 'account_contract_taxable_revenue_id': 1, 'worksheet_account_contract_closing_balance_id': 1, 'account_id': 2, 'contract_id': 2, 'statement_period_id': 2, 'reference_payment_entity_id': 1, 'amount': Decimal('20.00'), 'currency_code': 'USD', 'is_us_revenue': True, 'revenue_transaction_type': 'closing_balance', } result = WorksheetAccountContractTaxableRevenueListSchema().dump( {'items': [test_data], 'total_count': 1} ) assert result == { 'items': [{**test_data, 'amount': str(test_data['amount'])}], 'total_count': 1, }