Example #1
0
def test_basic():
    assert decide("test_returning_citizen.json", "watchlist.json",
                  "countries.json") == ["Accept", "Accept"]
    assert decide("test_watchlist.json", "watchlist.json",
                  "countries.json") == ["Secondary"]
    assert decide("test_quarantine.json", "watchlist.json",
                  "countries.json") == ["Quarantine"]
Example #2
0
def test_basic():
    assert decide("test_returning_citizen.json", "watchlist.json",
                  "countries.json") == ["Accept", "Accept"]
    assert decide("test_watchlist.json", "watchlist.json",
                  "countries.json") == ["Secondary"]
    assert decide("test_quarantine.json", "watchlist.json",
                  "countries.json") == ["Quarantine"]
def test_basic():
    """Test people whose home country is Kanadia to ensure correct prioritizing of results returned."""
    assert decide("test_returning_citizen.json", "watchlist.json", "countries.json") == ["Accept", "Accept"]
    assert decide("test_quarantine_over_accept.json", "watchlist.json", "countries.json") == \
                                                                                ["Quarantine", "Quarantine"]
    assert decide("test_reject_over_accept.json", "watchlist.json", "countries.json") == ["Reject"]
    assert decide("test_secondary_over_accept.json", "watchlist.json", "countries.json") == ["Secondary"]
def test_problematic():
    assert decide("test_added_entries.json", "watchlist.json", "countries.json")\
        == ["Accept", "Accept", "Accept", "Accept", "Accept"]
    assert decide("test_added_quarantine.json", "watchlist.json", "countries.json")\
        == ["Quarantine", "Quarantine", "Quarantine", "Quarantine", "Quarantine"]
    assert decide("test_added_missing_visa.json", "watchlist.json", "countries.json")\
        == ["Reject", "Reject", "Reject", "Reject", "Reject"]
def test_invalid():
    # test for invalid test cases
    # test for invalid passport number
    assert decide("test_passport.json", "watchlist.json", "countries.json") == ["Reject"]
    # test for invalid birthdate
    assert decide("test_birthdate.json", "watchlist.json", "countries.json") == ["Reject"]
    # test for invalid visa
    assert decide("test_visa.json", "watchlist.json", "countries.json") == ["Reject"]
    # test for invalid name
    assert decide("test_name.json", "watchlist.json", "countries.json") == ["Reject"]
Example #6
0
def test_input_file():
    """
    test for proper input type format
    """
    with pytest.raises(TypeError):
        # file does not contain a list of entries
        decide("test_input_file.json", "watchlist.json", "countries.json")
    with pytest.raises(TypeError):
        # entries in a list are not objects
        decide("test_input_file_2.json", "watchlist.json", "countries.json")
def test_files_not_modified():
    """
    Test that input files are not modified.
    """
    files = ["example_entries.json", "watchlist.json", "countries.json"]

    before = [os.path.getmtime(f) for f in files]
    decide("example_entries.json", "watchlist.json", "countries.json")
    after = [os.path.getmtime(f) for f in files]

    assert before == after
def test_basic():
    """
    Basic tests to tests provided to test for: accepting returning citizens,
    for traveller's who are on the watchlist and should be flagged to
    secondary, and for traveller's who should be flagged to quarantine.
    """
    assert decide("test_returning_citizen.json", "watchlist.json",
                  "countries.json") == ["Accept", "Accept"]
    assert decide("test_watchlist.json", "watchlist.json",
                  "countries.json") == ["Secondary"]
    assert decide("test_quarantine.json", "watchlist.json",
                  "countries.json") == ["Quarantine"]
def test_basic():
    assert decide("test_returning_citizen.json", "watchlist.json", "countries.json") == ["Accept", "Accept"]
    assert decide("test_watchlist.json", "watchlist.json", "countries.json") == ["Secondary"]
    assert decide("test_watchlist_name.json", "watchlist.json", "countries.json") == ["Secondary"]
    assert decide("test_quarantine.json", "watchlist.json", "countries.json") == ["Quarantine"]
    assert decide("test_good_noncanadian.json", "watchlist.json", "countries.json") == ["Accept"]
    assert decide("test_transit_visa_needed_but_not_present.json", "watchlist.json", "countries.json") == ["Reject"]
    assert decide("test_transit_visa_needed_but_too_old.json", "watchlist.json", "countries.json") == ["Reject"]
    assert decide("test_visitors_visa_needed_but_not_present.json", "watchlist.json", "countries.json") == ["Reject"]
    assert decide("test_visitors_visa_needed_but_too_old.json", "watchlist.json", "countries.json") == ["Reject"]
def test_files():
    # file not found test cases
    with pytest.raises(FileNotFoundError):
        decide("test_returning_citizen.json", "", "countries.json")
        decide("test_watchlist.json", "watchlist.json", "")
        decide("test_visitor_visa.json", "watchlist.json", "")
        decide("", "", "countries.json")
Example #11
0
def test_basic():
    """
    Some basic tests
    """
    # "Accept": returning citizens, no other conditions
    assert decide("json_test/test_returning_citizen.json", "watchlist.json",
                  "countries.json") == ["Accept", "Accept"]

    # "Secondary": name or passport on watchlist
    assert decide("json_test/test_watchlist.json", "watchlist.json",
                  "countries.json") == ["Secondary", "Secondary"]

    # "Quarantine": from/via a country that has medical advisory
    assert decide("json_test/test_quarantine.json", "watchlist.json",
                  "countries.json") == ["Quarantine", "Quarantine"]
Example #12
0
def test_valid_format():
    """
    Test if passport and date (visa date and birth date) formats are valid
    """
    # one entry with all valid format and three with each of the invalid
    assert decide("json_test/test_valid_format.json", "watchlist.json",
                  "countries.json") == ["Accept", "Reject", "Reject", "Reject"]
def test_invalid_passport():
    """Function to check if travellers with invalid passports get rejected"""
    assert decide("test_invalid_passport.json", "watchlist.json", "countries.json") == ["Reject", "Reject"]
    assert valid_passport_format('YD77Y-1MH6U-ASQWE-54ADS-HGASD')  # Valid passport entry
    assert not valid_passport_format('YD77Y-1MH6U')  # Too few letter groups in the passport
    assert not valid_passport_format('YD77Y-1MH6U-ASQWE-54ADS-HGASDQASDA')  # Checks for trailing characters in passport
    assert not valid_passport_format('YD@!Y-1MH6U-ASQWE-54ADS-HGAS@')  # Checks for special characters
def test_required_info_availability():
    assert decide("test_rejected_application.json", "watchlist.json", "countries.json") == ['Accept', 'Reject',
                                                                                            'Reject', 'Reject',
                                                                                            'Reject', 'Reject',
                                                                                            'Reject', 'Reject',
                                                                                            'Reject', 'Reject',
                                                                                            'Reject', 'Reject']
def test_files():
    with pytest.raises(FileNotFoundError):
        decide("test_returning_citizen.json", "", "countries.json")
    with pytest.raises(FileNotFoundError):
        decide("", "", "")
    with pytest.raises(FileNotFoundError):
        decide("test_returning_citizen.json", "test_watchlist.json", "")
    with pytest.raises(FileNotFoundError):
        decide("", "test_watchlist.json", "countries.json")
Example #16
0
def test_complete_info():
    """
    Test if required info is complete
    """
    # 8 entries: 1st is complete, and the rest 7 miss one of the required info
    assert decide("json_test/test_complete_info.json", "watchlist.json",
                  "countries.json") == ["Accept", "Reject", "Reject", "Reject",
                                        "Reject", "Reject", "Reject", "Reject"]
def test_watchlist1():
    """
    Travellers should have a secondary screening.
    """
    # If the traveller has a name or passport on the watch list,
    # she or he must be sent to secondary processing.
    assert decide("test_watchlist1.json", "watchlist.json", "countries.json") ==\
        ["Secondary", "Secondary"]
Example #18
0
def test_accept():
    """
    Inputs a watchlist JSON file, a countries JSON file, and a JSON file
    with entry records of travellers who should all be accepted.

    Included cases: whether the traveller is in transit, or visiting with
    visa required and visa is valid, in transit or visiting with no visa
    required, or traveller is from KAN.

    Also includes tests of fields with both upper and lower case values.
    """
    assert decide("test_JSON_files/test_28.json",
                  "watchlist.json", "countries.json") == ["Accept"]
    assert decide("test_JSON_files/test_32.json",
                  "watchlist.json", "countries.json") == ["Accept"]
    assert decide("test_JSON_files/test_34.json",
                  "watchlist.json", "countries.json") == ["Accept"]

    assert decide("test_JSON_files/test_38.json",
                  "watchlist.json", "countries.json") == ["Accept"]
    assert decide("test_JSON_files/test_39.json",
                  "watchlist.json", "countries.json") == ["Accept"]

    assert decide("test_JSON_files/test_lower_case.json",
                  "watchlist.json", "countries.json") == ["Accept"]
    assert decide("test_JSON_files/test_upper_case.json",
                  "watchlist.json", "countries.json") == ["Accept"]
def test_conflicts2():
    """
    """

    # Conflicts should be resolved according the order of priority:
    # quarantine, reject, secondary, and accept.

    assert decide("test_conflicts2.json", "watchlist.json", "countries.json") == \
        ["Reject"]
Example #20
0
def test_transit():
    """
    Some tests on transit visa
    """
    # 1. "Accept": transit but visa not required
    # 2. "Accept": transit and visa required, visa valid
    # 3. "Reject": transit and visa required, visa invalid
    assert decide("json_test/test_transit.json", "watchlist.json",
                  "countries.json") == ["Accept", "Accept", "Reject"]
def test_empty_entry():
    assert decide("test_empty_fname.json", "watchlist.json", "countries.json") == ["Reject"]
    assert decide("test_empty_lname.json", "watchlist.json", "countries.json") == ["Reject"]
    assert decide("test_empty_bdate.json", "watchlist.json", "countries.json") == ["Reject"]
    assert decide("test_empty_homec.json", "watchlist.json", "countries.json") == ["Reject"]
    assert decide("test_empty_fromc.json", "watchlist.json", "countries.json") == ["Reject"]
    assert decide("test_empty_passport.json", "watchlist.json", "countries.json") == ["Reject"]
    assert decide("test_empty_entry_reason.json", "watchlist.json", "countries.json") == ["Reject"]
Example #22
0
def test_case():
    """
    Case mismatch tests
    Index 0: Passport, first name, last name, and country codes in uppercase
    Index 1: Passport in lowercase
    Index 2: First name and last name in lowercase
    Index 3: Country codes in lowercase
    """
    assert decide("test_case.json", "watchlist.json", "countries.json") ==\
        ["Secondary", "Secondary", "Secondary", "Secondary"]
Example #23
0
def test_secondary():
    """
    Inputs a watchlist JSON file, a countries JSON file, and a JSON file
    with entry records of travellers who should all be "Secondary";
    (i.e., who are on the watchlist).

    Included cases: whether traveller is in transit or visiting with valid or
    invalid visa, or in transit or visiting from a country with no visa needed.
    """
    assert decide("test_JSON_files/test_27.json",
                  "watchlist.json", "countries.json") == ["Secondary"]
    assert decide("test_JSON_files/test_31.json",
                  "watchlist.json", "countries.json") == ["Reject"]

    assert decide("test_JSON_files/test_33.json",
                  "watchlist.json", "countries.json") == ["Secondary"]
    assert decide("test_JSON_files/test_35.json",
                  "watchlist.json", "countries.json") == ["Secondary"]
    assert decide("test_JSON_files/test_37.json",
                  "watchlist.json", "countries.json") == ["Secondary"]
def test_basic():
    assert decide("test_returning_citizen.json", "watchlist.json", "countries.json") == ["Accept", "Accept"]
    assert decide("test_watchlist.json", "watchlist.json", "countries.json") == ["Secondary"]
    assert decide("test_quarantine.json", "watchlist.json", "countries.json") == ["Quarantine"]
    # Incomplete information
    assert decide("test_1.json", "watchlist.json", "countries.json") == ["Reject"]
    # Invalid passport number
    assert decide("test_2.json", "watchlist.json", "countries.json") == ["Reject"]
    # Needs medical advisory
    assert decide("test_3.json", "watchlist.json", "countries.json") == ["Quarantine"]
    # On the watchlist
    assert decide("test_5.json", "watchlist.json", "countries.json") == ["Secondary"]
Example #25
0
def test_files():
    """
    Test for files
    """
    # all files are found
    assert decide("example_entries.json", "watchlist.json", "countries.json")

    # one or more files not found
    with pytest.raises(FileNotFoundError):
        decide("", "watchlist.json", "countries.json")
        decide("", "", "countries.json")
        decide("", "", "")
def test_basic():
    assert decide("test_returning_citizen.json", "watchlist.json", "countries.json") == ["Accept", "Accept"]
    assert decide("test_watchlist.json", "watchlist.json", "countries.json") == ["Secondary"]

    #assert decide("test_watchlist2.json", "watchlist.json", "countries.json") == ["Secondary"]
    assert decide("test_quarantine.json", "watchlist.json", "countries.json") == ["Quarantine"]


    #Tested 4 cases just containing all 3 conditions to test whether priority is set.
    assert decide("test_Priority_Quarantine.json", "watchlist.json", "countries.json") == ["Quarantine"]
    #Via Country ELE = Quarantine
    assert decide("test_Priority_Reject.json", "watchlist.json", "countries.json") == ["Reject"]
    #Doesn't have Visa field
    assert decide("test_Priority_Secondary.json", "watchlist.json", "countries.json") == ["Secondary"]
    #In the Watchlist for Passport Number
    assert decide("test_Priority_Accept.json", "watchlist.json", "countries.json") == ["Accept"]

    assert decide("test_reject0.json", "watchlist.json", "countries.json") == ["Reject"]
    #Doesn't have Last name, should be rejected
    assert decide("test_invalid_visa.json", "watchlist.json", "countries.json") == ["Accept"]
def test_examples():
    assert decide("example_entries.json", "watchlist.json", "countries.json") == ['Accept', 'Secondary', \
                    'Secondary', 'Quarantine', 'Quarantine', 'Accept', 'Accept', 'Accept', 'Accept', \
                    'Accept', 'Quarantine', 'Quarantine', 'Quarantine', 'Quarantine', 'Accept', 'Accept', \
                    'Quarantine', 'Accept', 'Quarantine', 'Accept', 'Accept', 'Accept', 'Accept', 'Accept', \
                    'Accept', 'Reject', 'Reject', 'Quarantine', 'Quarantine', 'Secondary', 'Quarantine', \
                    'Quarantine', 'Quarantine', 'Quarantine', 'Accept', 'Reject', 'Reject', 'Quarantine', \
                    'Accept', 'Quarantine', 'Accept', 'Accept', 'Reject', 'Accept', 'Accept', 'Accept', \
                    'Quarantine', 'Accept', 'Accept', 'Accept', 'Quarantine', 'Accept', 'Accept', 'Accept', \
                    'Accept', 'Accept', 'Quarantine', 'Accept', 'Accept', 'Accept', 'Accept',  'Accept', \
                    'Quarantine', 'Quarantine', 'Accept', 'Reject', 'Accept', 'Reject', 'Accept', 'Accept', \
                    'Accept', 'Accept', 'Accept', 'Quarantine', 'Reject', 'Accept', 'Accept', 'Reject', \
                    'Quarantine', 'Accept', 'Reject', 'Quarantine', 'Quarantine', 'Accept', 'Reject', \
                    'Accept', 'Accept', 'Accept', 'Accept', 'Accept', 'Accept', 'Accept', 'Accept', \
                    'Quarantine', 'Reject', 'Reject']
Example #28
0
def test_incomplete():
    """
    Test blank entries
    Index 0: Blank passport
    Index 1: Blank first name
    Index 2: Blank last name
    Index 3: Blank birth date
    Index 4: Blank home country
    Index 5: Blank from country
    Index 6: Blank entry reason
    """
    assert decide("test_blank.json", "watchlist.json", "countries.json")\
        == ["Reject", "Reject", "Reject", "Reject",
            "Reject", "Reject", "Reject"]

    '''
    Test invalid entries
    Index 0: Invalid passport
    Index 1: Invalid birth date
    Index 2: Invalid visa date
    Index 3: Invalid visa code
    '''
    assert decide("test_invalid.json", "watchlist.json", "countries.json") == \
        ["Reject", "Reject", "Reject", "Reject"]
Example #29
0
def test_visa():
    """
    Visa tests
    Index 0: Valid visa and entry is to visit
    Index 1: Expired visa and entry is to visit
    Index 2: Valid visa and entry is transit
    Index 3: Expired visa and entry is transit
    Index 4: Valid visa and entry is visit -
                from and via country both require visa
    Index 5: Valid visa and entry is visit - from country
                requires visa and via country does not
    Index 6: Valid visa and entry is visit - via country
                requires visa and from country does not
    """
    assert decide("test_visa.json", "watchlist.json", "countries.json") ==\
        ["Accept", "Reject", "Accept", "Reject", "Accept", "Accept", "Accept"]
Example #30
0
def test_precedence():
    """
    Precedence tests
    Index 0: Quarantine over Reject - reject due to expired passport,
                but quarantine due to medical advisory
    Index 1: Quarantine over Secondary -secondary due to passport on watchlist,
                but quarantine due to medical advisory
    Index 2: Quarantine over Accept - accept due to returning to KAN,
                but quarantine due to medical advisory
    Index 3: Reject over Secondary - secondary due to passport on watchlist,
                but reject due to blank name
    Index 4: Reject over Accept - accept due to returning to KAN, but reject
                due to invalid passport
    Index 5: Secondary over Accept - accept due to returning to KAN,
                but secondary due to passport on watchlist
    """
    assert decide("test_precedence.json", "watchlist.json", "countries.json")\
        == ["Quarantine", "Quarantine", "Quarantine", "Reject",
            "Reject", "Secondary"]
def test_basic():
    # test for valid test cases
    # test for returning citizen
    assert decide("test_returning_citizen.json", "watchlist.json", "countries.json") == ["Accept", "Accept"]
    # test for traveller in watchlist
    assert decide("test_watchlist.json", "watchlist.json", "countries.json") == ["Secondary"]
    # test for medical advisory
    assert decide("test_quarantine.json", "watchlist.json", "countries.json") == ["Quarantine"]
    # test for visitor visa
    assert decide("test_visitor_visa.json", "watchlist.json", "countries.json") == ["Accept"]
    # test for transit visa
    assert decide("test_transit_visa.json", "watchlist.json", "countries.json") == ["Accept", "Quarantine"]
    # test for lowercase
    assert decide("test_lowercase.json", "watchlist.json", "countries.json") == ["Accept"]
Example #32
0
def test_files():
    with pytest.raises(FileNotFoundError):
        decide("test_returning_citizen.json", "", "countries.json")