def test_tax_numbers(): TAX_NUMBERS_TO_VALIDATE = [("12345", False, False), ("FI12345678", True, True), ("FI123456781", True, False), ("GBHA999", True, True), ("GBHA9999", True, False)] for tax_number, is_vat, is_valid in TAX_NUMBERS_TO_VALIDATE: if is_vat: if is_valid: assert validate(tax_number) == "vat" else: with pytest.raises(VatInvalidValidationError): validate(tax_number) else: assert validate(tax_number) == ("vat" if is_valid else "unknown")
def clean_tax_number(self): tax_number = self.cleaned_data["tax_number"].strip() if self.request and validate_tax_number(self.request.shop) and tax_number: if tax_numbers.validate(tax_number) != "vat": raise ValidationError(_("Tax number is not valid."), code="not_valid_tax_number") return tax_number
def clean_tax_number(self): tax_number = self.cleaned_data["tax_number"].strip() if tax_number: tax_numbers.validate(tax_number) return tax_number