|
| 1 | +from idnumbers.nationalid import AUS, NGA, ZAF |
| 2 | + |
| 3 | + |
| 4 | +def validate_test(): |
| 5 | + # Verify AUS tax file number (with checksum code) |
| 6 | + taxfile_number = '32547689' |
| 7 | + is_valid = AUS.TaxFileNumber.validate(taxfile_number) |
| 8 | + assert is_valid |
| 9 | + if is_valid: |
| 10 | + print(f'{taxfile_number} is a valid AUS Tax File Number') |
| 11 | + else: |
| 12 | + print(f'{taxfile_number} is an invalid AUS Tax File Number') |
| 13 | + |
| 14 | + # Verify AUS driver license number |
| 15 | + driver_license = '12 345 678' |
| 16 | + is_valid = AUS.DriverLicenseNumber.validate(driver_license) |
| 17 | + assert is_valid |
| 18 | + if is_valid: |
| 19 | + print(f'{driver_license} is a valid AUS Driver License Number') |
| 20 | + else: |
| 21 | + print(f'{driver_license} is an invalid AUS Driver License Number') |
| 22 | + |
| 23 | + # Verify AUS Medicare number (with checksum code) |
| 24 | + medicare_number = '2123 45670 1' |
| 25 | + is_valid = AUS.MedicareNumber.validate(medicare_number) |
| 26 | + assert is_valid |
| 27 | + if is_valid: |
| 28 | + print(f'{medicare_number} is a valid AUS Medicare Number') |
| 29 | + else: |
| 30 | + print(f'{medicare_number} is an invalid AUS Medicare Number') |
| 31 | + |
| 32 | + # Verify NGA national id number |
| 33 | + nga_nationalid = '12345678901' |
| 34 | + is_valid = NGA.NationalID.validate(nga_nationalid) |
| 35 | + assert is_valid |
| 36 | + if is_valid: |
| 37 | + print(f'{nga_nationalid} is a valid Nigerian National ID Number') |
| 38 | + else: |
| 39 | + print(f'{nga_nationalid} is an invalid Nigerian National ID Number') |
| 40 | + |
| 41 | + # Verify ZAF nation id number |
| 42 | + zaf_nationalid = '7605300675088' |
| 43 | + is_valid = ZAF.NationalID.validate(zaf_nationalid) |
| 44 | + assert is_valid |
| 45 | + if is_valid: |
| 46 | + print(f'{zaf_nationalid} is a valid South African ID Number') |
| 47 | + else: |
| 48 | + print(f'{zaf_nationalid} is an invalid South African ID Number') |
| 49 | + |
| 50 | + |
| 51 | +def parse_test(): |
| 52 | + id_number = '7605300675088' |
| 53 | + id_data = ZAF.NationalID.parse(id_number) |
| 54 | + assert id_data is not None |
| 55 | + |
| 56 | + # Access the date of birth |
| 57 | + print(f'Date of birth: {id_data["yyyymmdd"]}') |
| 58 | + |
| 59 | + # Access the gender |
| 60 | + print(f'Gender: {id_data["gender"]}') |
| 61 | + |
| 62 | + # Access the citizenship |
| 63 | + print(f'Citizenship: {id_data["citizenship"]}') |
| 64 | + |
| 65 | + |
| 66 | +if __name__ == '__main__': |
| 67 | + print('run validate test') |
| 68 | + validate_test() |
| 69 | + print('run parse test') |
| 70 | + parse_test() |
0 commit comments