"""Test Reference VAT Rate schema.""" from datetime import date from decimal import Decimal from ledger.schemas.reference_vat_rate import ReferenceVatRateListSchema from tests.utils.factories import ReferenceVatRateFactory def test_reference_var_rate_list_load(): """Test Reference VAT Rate list schema loading.""" test_data = { 'vat_type': 'supplier', 'country_of_tax_residence': 'GBR', 'country_of_tax_policy': 'GBR', 'is_sba_signed': 1, 'is_tax_applicable': 1, 'is_vat_registered_in_country_of_tax_policy': 1, 'transaction_type': None, 'tax_rate': Decimal('20.00'), 'effective_date': '2002-05-10', } entry = ReferenceVatRateListSchema().load(test_data) assert entry == { 'vat_type': test_data['vat_type'], 'country_of_tax_residence': test_data['country_of_tax_residence'], 'country_of_tax_policy': test_data['country_of_tax_policy'], 'is_sba_signed': test_data['is_sba_signed'], 'is_tax_applicable': test_data['is_tax_applicable'], 'is_vat_registered_in_country_of_tax_policy': test_data[ 'is_vat_registered_in_country_of_tax_policy' ], 'transaction_type': test_data['transaction_type'], 'tax_rate': test_data['tax_rate'], 'effective_date': date.fromisoformat(test_data['effective_date']), } def test_reference_var_rate_list_load_dump(): """Test Reference VAT Rate list schema dumping.""" entity = ReferenceVatRateFactory.create() res = ReferenceVatRateListSchema().dump(entity) assert res == { 'reference_vat_rate_id': entity.reference_vat_rate_id, 'vat_type': entity.vat_type, 'country_of_tax_residence': entity.country_of_tax_residence, 'country_of_tax_policy': entity.country_of_tax_policy, 'is_sba_signed': entity.is_sba_signed, 'is_tax_applicable': entity.is_tax_applicable, 'is_vat_registered_in_country_of_tax_policy': entity.is_vat_registered_in_country_of_tax_policy, 'transaction_type': entity.transaction_type, 'tax_rate': str(entity.tax_rate), 'effective_date': entity.effective_date.strftime('%Y-%m-%d'), }