コード例 #1
0
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
コード例 #2
0
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
コード例 #3
0
def test_decide_unknown_locations_file():
    """
    Ensure that the file contains travellers that have locations listed that are unknown, and that they have no
    missing information that is required.
    """
    with open("test_decide_unknown_locations.json", "r") as citizen_file:
        citizen_content = citizen_file.read()
    citizen_json = json.loads(citizen_content)

    for person in citizen_json:
        for item in REQUIRED_FIELDS:
            assert item in person
        required_location_fields = LOCATION_FIELDS[:2]
        for item in required_location_fields:
            assert item in person
        assert unknown_location_exists(person, COUNTRIES)
コード例 #4
0
def test_decide_unknown_locations_file():
    """
    Ensure that the file contains travellers that have locations listed that are unknown, and that they have no
    missing information that is required.
    """
    with open("test_decide_unknown_locations.json", "r") as citizen_file:
        citizen_content = citizen_file.read()
    citizen_json = json.loads(citizen_content)

    for person in citizen_json:
        for item in REQUIRED_FIELDS:
            assert item in person
        required_location_fields = LOCATION_FIELDS[:2]
        for item in required_location_fields:
            assert item in person
        assert unknown_location_exists(person, COUNTRIES)
コード例 #5
0
def test_unknown_location_exists():
    countries = {"JIK": {"code": "JIK",
                         "name": "Jikland",
                         "visitor_visa_required": "0",
                         "transit_visa_required": "0",
                         "medical_advisory": ""},
                 "LUG": {"code": "LUG",
                         "name": "Democratic Republic of Lungary",
                         "visitor_visa_required": "1",
                         "transit_visa_required": "1",
                         "medical_advisory": "MUMPS"}}
    p1 = {"passport": "6P294-42HR2-95PSF-93NFF-2T5WF",
          "first_name": "JACK",
          "last_name": "DOE",
          "birth_date": "1938-12-21",
          "home": {"city": "Bala",
                   "region": "ON",
                   "country": "KAN"},
          "entry_reason": "returning",
          "from": {"city": "Wumpus",
                   "region": "Headdeskia",
                   "country": "JIK"}}
    assert unknown_location_exists(p1, countries) is False
    p2 = {"passport": "6P294-42HR2-95PSF-93NFF-2T5WF",
          "first_name": "JACK",
          "last_name": "DOE",
          "birth_date": "1938-12-21",
          "home": {"city": "Bala",
                   "region": "ON",
                   "country": "LUG"},
          "via": {"city": "Gruil",
                  "region": "LU",
                  "country": "JIK"},
          "entry_reason": "returning",
          "from": {"city": "Wumpus",
                   "region": "Headdeskia",
                   "country": "LUG"}}
    assert unknown_location_exists(p2, countries) is False
    p3 = {"passport": "6P294-42HR2-95PSF-93NFF-2T5WF",
          "first_name": "JACK",
          "last_name": "DOE",
          "birth_date": "1938-12-21",
          "home": {"city": "Bala",
                   "region": "ON",
                   "country": "ABC"},
          "entry_reason": "returning",
          "from": {"city": "Wumpus",
                   "region": "Headdeskia",
                   "country": "LUG"}}
    assert unknown_location_exists(p3, countries) is True
    p4 = {"passport": "6P294-42HR2-95PSF-93NFF-2T5WF",
          "first_name": "JACK",
          "last_name": "DOE",
          "birth_date": "1938-12-21",
          "home": {"city": "Bala",
                   "region": "ON",
                   "country": "ABC"},
          "entry_reason": "returning",
          "from": {"city": "Wumpus",
                   "region": "Headdeskia",
                   "country": "DEF"}}
    assert unknown_location_exists(p4, countries) is True
    p5 = {"passport": "6P294-42HR2-95PSF-93NFF-2T5WF",
          "first_name": "JACK",
          "last_name": "DOE",
          "birth_date": "1938-12-21",
          "home": {"city": "Bala",
                   "region": "ON",
                   "country": "KAN"},
          "via": {"city": "Alpha",
                  "region": "BET",
                  "country": "XYZ"},
          "entry_reason": "returning",
          "from": {"city": "Wumpus",
                   "region": "Headdeskia",
                   "country": "LUG"}}
    assert unknown_location_exists(p5, countries) is True
コード例 #6
0
def test_unknown_location_exists():
    countries = {
        "JIK": {
            "code": "JIK",
            "name": "Jikland",
            "visitor_visa_required": "0",
            "transit_visa_required": "0",
            "medical_advisory": ""
        },
        "LUG": {
            "code": "LUG",
            "name": "Democratic Republic of Lungary",
            "visitor_visa_required": "1",
            "transit_visa_required": "1",
            "medical_advisory": "MUMPS"
        }
    }
    p1 = {
        "passport": "6P294-42HR2-95PSF-93NFF-2T5WF",
        "first_name": "JACK",
        "last_name": "DOE",
        "birth_date": "1938-12-21",
        "home": {
            "city": "Bala",
            "region": "ON",
            "country": "KAN"
        },
        "entry_reason": "returning",
        "from": {
            "city": "Wumpus",
            "region": "Headdeskia",
            "country": "JIK"
        }
    }
    assert unknown_location_exists(p1, countries) is False
    p2 = {
        "passport": "6P294-42HR2-95PSF-93NFF-2T5WF",
        "first_name": "JACK",
        "last_name": "DOE",
        "birth_date": "1938-12-21",
        "home": {
            "city": "Bala",
            "region": "ON",
            "country": "LUG"
        },
        "via": {
            "city": "Gruil",
            "region": "LU",
            "country": "JIK"
        },
        "entry_reason": "returning",
        "from": {
            "city": "Wumpus",
            "region": "Headdeskia",
            "country": "LUG"
        }
    }
    assert unknown_location_exists(p2, countries) is False
    p3 = {
        "passport": "6P294-42HR2-95PSF-93NFF-2T5WF",
        "first_name": "JACK",
        "last_name": "DOE",
        "birth_date": "1938-12-21",
        "home": {
            "city": "Bala",
            "region": "ON",
            "country": "ABC"
        },
        "entry_reason": "returning",
        "from": {
            "city": "Wumpus",
            "region": "Headdeskia",
            "country": "LUG"
        }
    }
    assert unknown_location_exists(p3, countries) is True
    p4 = {
        "passport": "6P294-42HR2-95PSF-93NFF-2T5WF",
        "first_name": "JACK",
        "last_name": "DOE",
        "birth_date": "1938-12-21",
        "home": {
            "city": "Bala",
            "region": "ON",
            "country": "ABC"
        },
        "entry_reason": "returning",
        "from": {
            "city": "Wumpus",
            "region": "Headdeskia",
            "country": "DEF"
        }
    }
    assert unknown_location_exists(p4, countries) is True
    p5 = {
        "passport": "6P294-42HR2-95PSF-93NFF-2T5WF",
        "first_name": "JACK",
        "last_name": "DOE",
        "birth_date": "1938-12-21",
        "home": {
            "city": "Bala",
            "region": "ON",
            "country": "KAN"
        },
        "via": {
            "city": "Alpha",
            "region": "BET",
            "country": "XYZ"
        },
        "entry_reason": "returning",
        "from": {
            "city": "Wumpus",
            "region": "Headdeskia",
            "country": "LUG"
        }
    }
    assert unknown_location_exists(p5, countries) is True