"""Tests for WorksheetTaxCorrectionVAT schemas.""" from decimal import Decimal from marshmallow.exceptions import ValidationError import pytest from payment.schemas.worksheet_tax_correction_vat import ( WorksheetTaxCorrectionsVATDeleteSchema, WorksheetTaxCorrectionVATCreateSchema, ) def test_worksheet_tax_correction_create_schema_success(): """Test WorksheetTaxCorrectionCreateSchema validation success.""" test_data = { 'payable_detail_type_id': 1, 'contract_id': 1, 'account_id': 1, 'correction_statement_period_id': 1, 'vat_category': 'closing_balance', 'base_amount_payee_currency': '10.00', 'payee_currency_code': 'USD', 'vat_currency_code': 'USD', 'vat_rate': '10.00', 'vat_amount_payee_currency': '10.00', 'vat_amount_vat_currency': '10.00', 'net_amount_payee_currency': '10.00', 'note': 'test note 1', } result = WorksheetTaxCorrectionVATCreateSchema().load(test_data) assert result == { **test_data, 'base_amount_payee_currency': Decimal(test_data['base_amount_payee_currency']), 'vat_rate': Decimal(test_data['vat_rate']), 'vat_amount_payee_currency': Decimal(test_data['vat_amount_payee_currency']), 'vat_amount_vat_currency': Decimal(test_data['vat_amount_vat_currency']), 'net_amount_payee_currency': Decimal(test_data['net_amount_payee_currency']), } def test_worksheet_tax_correction_create_schema_wht_success(): """Test WorksheetTaxCorrectionCreateSchema validation success.""" test_data = { 'payable_detail_type_id': 1, 'contract_id': 1, 'account_id': 1, 'correction_statement_period_id': 1, 'vat_category': 'closing_balance', 'base_amount_payee_currency': '10.00', 'payee_currency_code': 'USD', 'vat_currency_code': 'USD', 'vat_rate': '10.00', 'vat_amount_payee_currency': '10.00', 'vat_amount_vat_currency': '10.00', 'net_amount_payee_currency': '10.00', 'wht_rate': '10.00', 'wht_amount_payee_currency': '10.01', 'wht_amount_vat_currency': '10.02', 'note': 'test note 1', } result = WorksheetTaxCorrectionVATCreateSchema().load(test_data) assert result == { **test_data, 'base_amount_payee_currency': Decimal(test_data['base_amount_payee_currency']), 'vat_rate': Decimal(test_data['vat_rate']), 'vat_amount_payee_currency': Decimal(test_data['vat_amount_payee_currency']), 'vat_amount_vat_currency': Decimal(test_data['vat_amount_vat_currency']), 'net_amount_payee_currency': Decimal(test_data['net_amount_payee_currency']), 'wht_rate': Decimal(test_data['wht_rate']), 'wht_amount_payee_currency': Decimal(test_data['wht_amount_payee_currency']), 'wht_amount_vat_currency': Decimal(test_data['wht_amount_vat_currency']), } def test_worksheet_tax_correction_create_schema_failure(): """Test WorksheetTaxCorrectionVATCreateSchema validation failure.""" with pytest.raises(ValidationError) as exc_info: WorksheetTaxCorrectionVATCreateSchema().load({'vat_category': 'fake_category'}) assert set(exc_info.value.messages_dict.keys()) == { 'contract_id', 'account_id', 'correction_statement_period_id', 'payable_detail_type_id', 'base_amount_payee_currency', 'payee_currency_code', 'vat_category', 'vat_currency_code', 'vat_rate', 'vat_amount_payee_currency', 'vat_amount_vat_currency', 'net_amount_payee_currency', } def test_worksheet_tax_correction_delete_schema_success(): """Test WorksheetTaxCorrectionDeleteSchema validation success.""" test_data = { 'worksheet_tax_correction_vat_ids': [1, 2, 3], } result = WorksheetTaxCorrectionsVATDeleteSchema().load(test_data) assert result == test_data def test_worksheet_tax_correction_delete_schema_failure(): """Test WorksheetTaxCorrectionDeleteSchema validation failure.""" with pytest.raises(ValidationError) as exc_info: WorksheetTaxCorrectionsVATDeleteSchema().load( { 'worksheet_tax_correction_vat_ids': ['1a', '2b'], } ) assert set(exc_info.value.messages_dict.keys()) == { 'worksheet_tax_correction_vat_ids', } with pytest.raises(ValidationError) as exc_info: WorksheetTaxCorrectionsVATDeleteSchema().load({}) assert set(exc_info.value.messages_dict.keys()) == { 'worksheet_tax_correction_vat_ids', }