|
| 1 | +import pytest |
| 2 | + |
| 3 | +from codicefiscale import codicefiscale |
| 4 | + |
| 5 | + |
| 6 | +@pytest.fixture |
| 7 | +def omocode_test_cases(): |
| 8 | + return [ |
| 9 | + ("CCCFBA85D03L219P", False), |
| 10 | + ("CCCFBA85D03L21VE", True), |
| 11 | + ("CCCFBA85D03L2MVP", True), |
| 12 | + ("CCCFBA85D03LNMVE", True), |
| 13 | + ("CCCFBA85D0PLNMVA", True), |
| 14 | + ("CCCFBA85DLPLNMVL", True), |
| 15 | + ("CCCFBA8RDLPLNMVX", True), |
| 16 | + ("CCCFBAURDLPLNMVU", True), |
| 17 | + ] |
| 18 | + |
| 19 | + |
| 20 | +@pytest.fixture |
| 21 | +def valid_fiscal_code_test_cases(): |
| 22 | + return [ |
| 23 | + ("CCCFBA85D03L219P", True), |
| 24 | + ("CCC FBA 85 D03 L219 P", True), |
| 25 | + ("CCC-FBA-85-D03-L219-P", True), |
| 26 | + ("CCCFBA85D03L219PP", False), # too long |
| 27 | + ("CCCFBA85D03L219B", False), # wrong CIN |
| 28 | + ("CCCFBA85D03L219", False), # too short |
| 29 | + ("CCCFBA85D00L219", False), # wrong birthdate day |
| 30 | + ("CCCFBA85D99L219", False), # wrong birthdate day |
| 31 | + ] |
| 32 | + |
| 33 | + |
| 34 | +def test_is_omocode(omocode_test_cases): |
| 35 | + """ |
| 36 | + Test the `is_omocode` function to verify if a fiscal code is an omocode. |
| 37 | + """ |
| 38 | + for fiscal_code, expected_result in omocode_test_cases: |
| 39 | + assert codicefiscale.is_omocode(fiscal_code) == expected_result |
| 40 | + |
| 41 | + |
| 42 | +def test_is_valid(valid_fiscal_code_test_cases): |
| 43 | + """ |
| 44 | + Test the `is_valid` function to verify if a fiscal code is valid. |
| 45 | + """ |
| 46 | + for fiscal_code, expected_result in valid_fiscal_code_test_cases: |
| 47 | + assert codicefiscale.is_valid(fiscal_code) == expected_result |
0 commit comments