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_date_format(): """ Tests date format validation is being done properly """ assert valid_date_format("1958-08-22") is True assert valid_date_format("58-08-22") is False assert valid_date_format("1958-08-aa") is False
def test_correct_date_format(): """ Test to see if different dates are accepted. """ assert valid_date_format("2015-02-22") == True assert valid_date_format("2012-30-40") == False try: assert valid_date_format(2015 - 02 - 22) except TypeError: return True
def test_valid_date_format(): """ Testing if date format is valid or invalid. """ assert valid_date_format("2010-10-15") is True assert valid_date_format("2005-06-29") is True assert valid_date_format("2003-02-29") is True assert valid_date_format("18501312") is False assert valid_date_format("1800-12-5") is False assert valid_date_format("1800-2-05") is False
def test_valid_date_format(): assert valid_date_format("1952-12-25") is True assert valid_date_format("2002-01-05") is True assert valid_date_format("2002-01-31") is True assert valid_date_format("2000-02-28") is True assert valid_date_format("2002-02-30") is False assert valid_date_format("2002-04-31") is False assert valid_date_format("195-12-25") is False assert valid_date_format("1952-13-05") is False assert valid_date_format("1982-02-32") is False assert valid_date_format("1972-3-9") is False assert valid_date_format("03-09-2000") is False
def test_date_validity(): assert valid_date_format(test_traveler1["birth_date"]) == True assert valid_date_format(test_traveler2["birth_date"]) == False
def test_invalid_date_format_2(): """ Testing invalid date format due to inclusion of other characters other than numbers """ assert valid_date_format("2014-09-0h") == False
def test_invalid_date_format_1(): """ Testing invalid date format due to missing digit """ assert valid_date_format("2014-09-0") == False
def test_valid_date_format(): assert valid_date_format("2014-09-08") == True