"""Test Reference Tax Withholding schema.""" from decimal import Decimal from marshmallow.exceptions import ValidationError import pytest from payment.schemas.reference_tax_withholding import ( ReferenceTaxWithholdingDetailSchema, ReferenceTaxWithholdingListFilterParamsSchema, ) from tests.utils.factories import ReferenceTaxWithholdingFactory def test_reference_tax_withholding_list_load(): """Test Reference Tax Withholding list schema loading.""" test_data = { 'country_of_withholding': 'GBR', 'country_of_tax_residence': 'TWN', 'tax_rate': Decimal('10.00'), } entry = ReferenceTaxWithholdingDetailSchema().load(test_data) assert entry == { 'country_of_withholding': test_data['country_of_withholding'], 'country_of_tax_residence': test_data['country_of_tax_residence'], 'tax_rate': test_data['tax_rate'], } def test_reference_tax_withholding_list_load_dump(): """Test Reference Tax Withholding list schema dumping.""" entity = ReferenceTaxWithholdingFactory.create() res = ReferenceTaxWithholdingDetailSchema().dump(entity) assert res == { 'reference_tax_withholding_id': entity.reference_tax_withholding_id, 'country_of_withholding': entity.country_of_withholding, 'country_of_tax_residence': entity.country_of_tax_residence, 'tax_rate': str(entity.tax_rate), 'is_resource_provisioned': entity.is_resource_provisioned, } def test_reference_tax_withholding_list_filter_params_load(): """Test ReferenceTaxWithholdingListFilterParamsSchema schema.""" correct_data = {'country_of_withholding': 'USA', 'country_of_tax_residence': 'USA'} res = ReferenceTaxWithholdingListFilterParamsSchema().load(correct_data) assert res == correct_data with pytest.raises(ValidationError) as exc_info: ReferenceTaxWithholdingListFilterParamsSchema().load( {'country_of_withholding': 'US', 'country_of_tax_residence': 'USAU'} ) assert exc_info.value.messages == { 'country_of_tax_residence': ['Length must be 3.'], 'country_of_withholding': ['Length must be 3.'], } res = ReferenceTaxWithholdingListFilterParamsSchema().load({}) assert res == {}