def test_valid_passport_format(): """ Tests passport format validation is being done properly """ assert valid_passport_format("JMZ0S-89IA9-OTCLY-MQILJ-P7CTY") is True assert valid_passport_format("JMZ-89I-OTC-MQI-P7C") is False assert valid_passport_format("") is False assert valid_passport_format("jmz0s-89ia9-otcly-moilj-p7cty") is True
def test_valid_passport(): s1 = "6P294-42HR2-95PSF-93NFF-2TEWF" assert valid_passport_format(s1) is True s2 = "TJq2R-25stx-Fyc52-02rm0-420DS" assert valid_passport_format(s2) is True s3 = "33T0R-8T3T2-W_C77-243GE-42O_D" assert valid_passport_format(s3) is False s4 = "T2EW5-WT255-019RW-2RWS4-42FFX-TNX2R" assert valid_passport_format(s4) is False
def test_valid_passport_format(): """ Tests to see if Invalid formats are accepted """ assert valid_passport_format("FWO9A-B8MDF-TGXW5-H49SO-HI5VE") == True try: assert valid_passport_format(9083 - 9876 - 4659 - 3845 - 9345 - 3845) except TypeError: return True try: assert valid_passport_format("asdfadsf") except AssertionError: return True
def valid_file_contents(file_contents): """ This function checks to see that the file contents are valid: no required fields are missing, location information is complete, birth_date and passport/visa number is valid. :param file_contents: a list of dictionaries denoting returning citizens :return: True if the file contents are valid, False otherwise """ valid_file = True for person in file_contents: for item in REQUIRED_FIELDS: if item not in person: valid_file = False for item in person: if item in LOCATION_FIELDS: if not valid_location_field(person[item]): valid_file = False elif item is "passport": if not valid_passport_format(person[item]): valid_file = False elif item is "visa": if not valid_date_format(person["visa"]["date"]): valid_file = False if not valid_visa_format(person["visa"]["code"]): valid_file = False elif item is "entry_reason": if person[item] not in REASON_FOR_ENTRY: valid_file = False elif item is "birth_date": if not valid_date_format(person[item]): valid_file = False if unknown_location_exists(person, COUNTRIES): valid_file = False return valid_file
def test_valid_passport_format(): """ Passport is valid. """ assert(valid_passport_format("12A34-56B78-98C76-54D32-12E34")) is True assert(valid_passport_format("12345-67890-09876-54321-13579")) is True assert(valid_passport_format("1BCDE-2GHIJ-3LMNO-4QRST-5VWXY")) is True assert(valid_passport_format("12a34-56b78-98c76-54d32-12e34")) is True assert(valid_passport_format("ABCDE-FGHIJ-KLMNO-PQRST-UVWXY")) is True assert(valid_passport_format("JAHDL-JKW-KJDJK")) is False assert(valid_passport_format("12A-98C7")) is False
def test_decide_missing_required_information_file(): """ Ensure that the file contains citizens with missing information fields. """ with open("test_decide_missing_required_information.json", "r") as citizen_file: citizen_content = citizen_file.read() citizen_json = json.loads(citizen_content) assert valid_file_contents(citizen_json) is False for person in citizen_json: required_fields_included = True for item in REQUIRED_FIELDS: if item not in person: required_fields_included = False if item is "passport" and "passport" in person: assert valid_passport_format(person[item]) is True for item in LOCATION_FIELDS: if item in person: if not valid_location_field(person[item]): required_fields_included = False assert required_fields_included is False
def test_passport_validity(): assert valid_passport_format(test_traveler1["passport"]) == True assert valid_passport_format(test_traveler2["passport"]) == False
def test_invalid_passport_format_2(): """ Testing invalid passport format due to the inclusion of symbols rather than numbers or letters """ assert valid_passport_format("gdg7w-w8djw-wjskd-837ed-!!!!!") == False
def test_invalid_passport_format_1(): """ Testing invalid passport format due to missing characters """ assert valid_passport_format("gdg7w-w8djw-wjskd-837ed-") == False
def test_valid_passport_format(): assert valid_passport_format("gdg7w-w8djw-wjskd-837ed-9wj9d") == True