|
| 1 | +"""Validate complete MAC addresses and regional identifiers.""" |
| 2 | + |
| 3 | +from typing import Callable |
| 4 | + |
| 5 | +import pytest |
| 6 | + |
| 7 | +from validators import ValidationError, mac_address |
| 8 | +from validators.i18n.fi import fi_business_id, fi_ssn |
| 9 | +from validators.i18n.fr import fr_ssn |
| 10 | +from validators.i18n.ind import ind_aadhar |
| 11 | + |
| 12 | + |
| 13 | +@pytest.mark.parametrize( |
| 14 | + "validate,value", |
| 15 | + [ |
| 16 | + (mac_address, "01:23:45:67:ab:CD"), |
| 17 | + (mac_address, "01-23-45-67-ab-CD"), |
| 18 | + (fi_business_id, "0112038-9"), |
| 19 | + (fi_ssn, "010101-0101"), |
| 20 | + (fr_ssn, "1 84 12 76 451 089 46"), |
| 21 | + (fr_ssn, "1 84 12 76 451 089"), |
| 22 | + (ind_aadhar, "3675 9834 6015"), |
| 23 | + ], |
| 24 | +) |
| 25 | +@pytest.mark.parametrize("suffix", ["", "\n", "\r\n", " ", "\nextra"]) |
| 26 | +def test_complete_identifier(validate: Callable[[str], object], value: str, suffix: str): |
| 27 | + """Accept the identifier alone and reject any trailing characters.""" |
| 28 | + if suffix: |
| 29 | + assert isinstance(validate(value + suffix), ValidationError) |
| 30 | + else: |
| 31 | + assert validate(value) is True |
0 commit comments