コード例 #1
0
def test_missing_entries():
    #tests for missing entries in traveller information
    assert decide("test_missing_entries.json", "countries.json") ==\
    ['Reject', 'Reject', 'Reject', 'Reject', 'Reject']

    assert decide("test_missing_entries.json", "countries_altered.json") ==\
    ['Quarantine', 'Reject', 'Quarantine', 'Reject', 'Reject']
コード例 #2
0
def test_reject_and_quarantine():
    #test reject and quarantine
    assert decide("test_reject_and_quarantine.json", "countries.json") ==\
        ['Reject', 'Reject', 'Reject', 'Reject', 'Quarantine', 'Quarantine']

    assert decide("test_reject_and_quarantine.json", "countries_altered.json") ==\
        ['Quarantine', 'Reject', 'Quarantine', 'Reject', 'Quarantine', 'Quarantine']
コード例 #3
0
def test_wronginput():

    assert decide("test_wrongpassport.json", "countries.json") == ["Reject"]

    assert decide("test_wrongformat.json", "countries.json") == ["Quarantine"]

    assert decide("test_nonexistent_country.json", "countries.json") == ["Reject"]
コード例 #4
0
def test_basic():

    assert decide("test_watchlist.json", "countries.json") == ["Quarantine"]

    assert decide("test_quarantine.json", "countries.json") == ["Quarantine"]

    assert decide("test_lowercase.json", "countries.json") == ["Accept"]

    assert decide("test_raises_all_flags.json", "countries.json") == ["Quarantine"]
コード例 #5
0
def test_traveling_via():
    """
    Test incoming foreigners & returning citizens traveling via somewher else

    """
    assert decide("test_traveling_via.json", "countries.json") ==\
        ['Reject', 'Accept', 'Quarantine', 'Accept', 'Reject']

    assert decide("test_traveling_via.json", "countries_altered.json") ==\
        ['Reject', 'Accept', 'Quarantine', 'Accept', 'Quarantine']
コード例 #6
0
def test_visa_validity():
    """
    Test validity & formatting of incoming travelers from countries that require visas

    """
    assert decide("test_check_visa.json", "countries.json") ==\
        ['Reject', 'Accept', 'Quarantine', 'Reject']

    assert decide("test_check_visa.json", "countries_altered.json") ==\
        ['Quarantine', 'Accept', 'Quarantine', 'Reject']
コード例 #7
0
def test_location_unknown():
    """
    Test that an unknown location returns Reject (or Quarantine) rather than crashing the program

    """
    assert decide("test_location_known.json", "countries.json") ==\
        ['Reject', 'Accept', 'Quarantine', 'Accept']

    assert decide("test_location_known.json", "countries_altered.json") ==\
        ['Reject', 'Accept', 'Quarantine', 'Quarantine']
コード例 #8
0
def test_incoming():
    """
    Foreigners entering KAN. Must check if their documents are in order and properly filled

    """

    assert decide("test_incoming_foreigner.json", "countries.json") ==\
        ['Accept', 'Reject', 'Quarantine', 'Accept']

    assert decide("test_incoming_foreigner.json", "countries_altered.json") ==\
        ['Quarantine', 'Quarantine', 'Quarantine', 'Accept']
コード例 #9
0
def test_decide_visitors_invalid_visa_via_country_with_medical_advisory():
    """
    Testing for visitors that do not have a valid visa and has travelled through or from a country with a medical
    advisory.
    """
    assert decide("test_decide_visitors_invalid_visa_via_country_with_medical_advisory.json", COUNTRIES_FILE) ==\
        ["Reject"] * 4
コード例 #10
0
def test_visitors():
    """
    Travellers are trying to visit KAN. Must check if their documents are in order and properly filled
    :return:
    """
    assert decide("test_visitors.json", "countries.json") ==\
        ["Reject","Accept","Quarantine","Accept"]
コード例 #11
0
def test_location_existence():
    """
    Traveller's home country and the country the traveller came from is checked to see if the country exists
    when they are returning or visiting a country.
    """
    assert decide("test_location_existence.json", "countries.json") ==\
        ["Accept", "Accept", "Reject"]
コード例 #12
0
def test_visa_existence():
    """
   When reason for entry is to visit and the visitor has a passport from a country from which a visitor
   visa is required, it is required to check if traveller has a visa or not.
    """
    assert decide("test_visa_existence.json", "countries.json") ==\
        ["Accept", "Reject", "Quarantine"]
コード例 #13
0
def test_visa_validation():
    """
    When reason for entry is to visit, the visitor has a passport from a country from which a visitor visa is required,
    and visitor has a visa, it is required to check if the visa is valid or not.
    """
    assert decide("test_visa_validation.json", "countries.json") ==\
        ["Reject", "Accept", "Reject"]
コード例 #14
0
def test_visa_check():
    # Test for issues with a travellers visa code
    # 1) Traveler has their visa code missing, 2) Traveler has their visa date missing
    # 3) Traveler has their visa code and date missing, 4) Visa code has too many letters
    # 5) Visa code has too few letters

    assert decide("JSONtest VISA.json", "countries.json") == ["Reject", "Reject", "Reject", "Reject", "Reject"]
コード例 #15
0
def test_medical_check():

    # Test for instances where a person may need to be Quarantined
    # 1) Traveler has come from a quarantined country, 2) Traveler has traveled via a quarantined country
    # 3) Kanadian traveler has come via a quarantined country, 4) Home country is a quarantined country

    assert decide("JSONtestMEDICAL.json", "countries.json") == ["Quarantine", "Quarantine", "Quarantine", "Accept"]
コード例 #16
0
def test_decide_visitors_via_country_with_medical_advisory():
    """
    Testing for visitors that are approved thus far (no required information missing, everything is valid, visa is
    present if required), but travelled from or via a country with a medical advisory.
    """
    assert decide("test_decide_visitors_via_country_with_medical_advisory.json", COUNTRIES_FILE) ==\
        ["Quarantine"] * 4
コード例 #17
0
def test_decide_kan_citizens_via_country_with_medical_advisory():
    """
    Testing for KAN citizens that travelled from or via a country with a medical advisory. All required information
    is present.
    """
    assert decide("test_decide_KAN_citizens_via_country_with_medical_advisory.json", COUNTRIES_FILE) ==\
        ["Quarantine"] * 4
コード例 #18
0
def test_decide_visitors_visas_not_needed():
    """
    Visitors that have their home location other than KAN (but still a valid location), but because of their home
    countries, they do not require a visa to enter. These travellers did not travel from or through a country with
    a medical advisory and all required information is present.
    """
    assert decide("test_decide_visitors_visas_not_needed.json", COUNTRIES_FILE) == ["Accept"] * 5
コード例 #19
0
def test_returning():
    """
    Travellers are returning to KAN.
        1)traveller is from KAN and returning from medically safe country
        2)traveller is from KAN and returning from medically safe country
        3)traveller is from KAN and returning from medically unsafe country
    """
    assert decide("test_returning_citizen.json", "countries.json") ==\
        ["Accept", "Accept", "Quarantine"]
コード例 #20
0
def test_returning():
    """
    Travellers are returning to KAN.
    """

    # Visitor 1 is from KAN (no visa required) and has no visa - "Accept"
    # Visitor 2 is from KAN (no visa required) and has no visa - "Accept"
    # Visitor 3 is from KAN (no visa required) but coming from LUG with medical advisory - "Quarantine"
    assert decide("test_returning_citizen.json", "countries.json") == ["Accept", "Accept", "Quarantine"]
コード例 #21
0
def test_decide_visitors_require_visas_invalid_visas():
    """
    Visitors that have their home location other than KAN (but still a valid location), and because of their home
    countries, they require a visa to enter. Their visas are invalid/expired because they are older than 2 years or
    that their visa information is missing.
    These travellers did not travel from or through a country with a medical advisory and all required information
    is present.
    """
    assert decide("test_decide_visitors_require_visas_invalid_visas.json", COUNTRIES_FILE) == ["Reject"] * 5
コード例 #22
0
def test_improper_passports():
    """
    Travellers with passports with more or less characters or "_" and mixed letter cases
        1)Passport number is missing letter/digit
        2)Passport number has extra letter/ digit
        3)Passport number contains an underscore

    """
    assert decide("test_improper_passports.json", "countries.json") ==\
        ["Reject", "Reject", "Reject"]
コード例 #23
0
def test_unknown_location():
    """
    Travellers with unknown location
    #1 Both the locations are unknown - home & from
    #2 Only one location is unknown
    :return:
    """

    assert decide("unknown_location.json", "countries.json") ==\
        ["Reject", "Reject"]
コード例 #24
0
def test_visa_validity():
    """
    Travellers requiring Visa will need a validity check
    #1 Traveller requires valid visa
    #2 Invalid date format
    #3 Invalid visa code format
    #4 Traveler requires a visa but his validity is over
    """
    assert decide("visa_validity.json", "countries.json") ==\
        ["Accept", "Reject", "Reject", "Reject"]
コード例 #25
0
def test_improper_visas():
    """
    Travellers with visas with more or less characters or "_" and mixed letter cases
        1)Visa number is missing letter/digit
        2)Visa number has extra letter/ digit
        3)Visa number contains an underscore

    """
    assert decide("test_improper_passports.json", "countries.json") ==\
        ["Reject", "Reject", "Reject"]
コード例 #26
0
def test_further_cases():
    """
    1. Traveller 1 = Reject because Rule 1. traveller's record is incomplete or malformed
    2. Traveller 2 = Reject because Rule 1. traveller's birth date record is invalid 1936-13-25
    3. Traveller 3 = Reject because Rule 1. traveller's passport information is not included
    4. Traveller 4 = Reject because Rule 2. traveller is from an unknown country
    5. Traveller 5 = Reject because Rule 4. traveller visa is out of date
    6. Traveller 6 = Reject because Rule 4. traveller has an invalid Visa number
    """
    assert decide("exercise2_further_tests.json", "countries.json") == \
           ["Reject", "Reject", "Reject", "Reject", "Reject", "Reject"]
コード例 #27
0
def test_visitors_with_visas():
    """
    Visitors to KAN
        1)traveller from a foreign country that requires a visitor visa
          and visa is valid
        2)traveller from a foreign country that requires a visa
          and visa is expired
        3)traveller from a foreign country that requires a visa
          and visa is improperly formatted
    """
    assert decide("test_visitors_with_visas.json", "countries.json") ==\
        ["Accept", "Reject", 'Reject']
コード例 #28
0
def test_mixed_capitalization():
    """
    Traveller with valid country codes, passport numbers, and entry reasons
    but with mixed letter cases
        1)Passport is valid format but some capitals some lower case letters
        2)Home country code is in lowercase
        3)From country code is in lowercase
        4)Entry reason is mixed capitalization

    """
    assert decide("test_mixed_capitalization.json", "countries.json") ==\
        ["Accept", "Accept", "Accept", "Accept"]
コード例 #29
0
def test_medical_advisory():
    """
    Test for travelers traveling from
    countries having medical advisories
    #1 Traveler belonging to Kanadia but
    traveling from a country having medical advisory
    #2 Traveler from some other country,
    traveling from a country having medical advisory
    """

    assert decide("medical_advisory.json", "countries.json") ==\
        ["Quarantine", "Quarantine"]
コード例 #30
0
def test_miscellaneous():
    """
    Tests for some minor details in traveler's data
    #1 Whether all the required fields are provided or nor (last name missing)
    #2 Lowercase passport numbers
    #3 Lowercase country code
    #4 Whether the passport number is in correct format
    #5 If the traveler is traveling via a country having medical advisory
    """

    assert decide("miscellaneous.json", "countries.json") ==\
        ["Reject", "Accept", "Accept", "Reject", "Quarantine"]
コード例 #31
0
def test_medical_advisory():
    """
    Test for travelers traveling from
    countries having medical advisories
    #1 Traveler belonging to Kanadia but
    traveling from a country having medical advisory
    #2 Traveler from some other country,
    traveling from a country having medical advisory
    """

    assert decide("medical_advisory.json", "countries.json") ==\
        ["Quarantine", "Quarantine"]
コード例 #32
0
def test_visitors_with_visas():
    """
    Visitors to KAN
        1)traveller from a foreign country that requires a visitor visa
          and visa is valid
        2)traveller from a foreign country that requires a visa
          and visa is expired
        3)traveller from a foreign country that requires a visa
          and visa is improperly formatted
    """
    assert decide("test_visitors_with_visas.json", "countries.json") ==\
        ["Accept", "Reject", 'Reject']
コード例 #33
0
def test_mixed_capitalization():
    """
    Traveller with valid country codes, passport numbers, and entry reasons
    but with mixed letter cases
        1)Passport is valid format but some capitals some lower case letters
        2)Home country code is in lowercase
        3)From country code is in lowercase
        4)Entry reason is mixed capitalization

    """
    assert decide("test_mixed_capitalization.json", "countries.json") ==\
        ["Accept", "Accept", "Accept", "Accept"]
コード例 #34
0
def test_miscellaneous():
    """
    Tests for some minor details in traveler's data
    #1 Whether all the required fields are provided or nor (last name missing)
    #2 Lowercase passport numbers
    #3 Lowercase country code
    #4 Whether the passport number is in correct format
    #5 If the traveler is traveling via a country having medical advisory
    """

    assert decide("miscellaneous.json", "countries.json") ==\
        ["Reject", "Accept", "Accept", "Reject", "Quarantine"]
コード例 #35
0
def test_transiting():
    """
    Travellers are transiting through KAN
    """

    # Visitor 1 is from III (transit visa required) and has valid visa - "Accept"
    # Visitor 1 is from III (transit visa required) and has invalid visa - "Reject"
    # Visitor 3 is from III (transit visa required) but coming from LUG with medical advisory - "Quarantine"
    # Visitor 4 is from KRA (no transit visa required) with no visa - "Accept"
    # Visitor 5 is from GOR (transit visa required) with no visa - "Reject"
    assert decide("test_transit_visitor.json", "countries.json") == \
        ["Accept", "Reject", "Quarantine", "Accept", "Reject"]
コード例 #36
0
def test_date_formats():
    """
    Travellers with various date formats
        1)Traveller with correct data format
        2)Traveller with incorrect date format (YYY-MM-DD)
        3)Traveller with date format out of order
        4)Traveller with date month and day out of possible range
        5)Traveller with incorrect date and coming from medical advisory
          country so quarantine should take priority over reject
    :return:
    """
    assert decide("test_improper_birthday_format.json", "countries.json") ==\
        ["Accept", "Reject", "Reject", 'Reject', "Quarantine"]
コード例 #37
0
def test_visiting():
    """
    Travellers are visiting KAN
    """

    # Visitor 1 is from KRA (visa required) with a valid visa - "Accept"
    # Visitor 2 is from LUG (visa required) with a valid visa but has a "Mumps" medical advisory - "Quarantine"
    # Visitor 3 is from HRJ (no visa required) with no visa - "Accept"
    # Visitor 4 is from HRJ (no visa required) but is coming via LUG which as medical advisory - "Quarantine"
    # Visitor 5 is from GOR (no visitor visa, but transit visa required) with no visa - "Accept"
    # Visitor 6 is from FRY (visa required) with no visa - "Reject"
    # Visitor 7 is from BRD (visa required) with visa
    assert decide("test_visitor.json", "countries.json") ==\
        ["Accept", "Quarantine", "Accept", "Quarantine", "Accept", "Reject", "Reject"]
コード例 #38
0
def test_invalid_inputs():
    """
    All entries in the json file should trigger various invalid inputs
    """

    # Visitor 1 has incomplete records (passport field missing)
    # Visitor 2 has invalid passport number
    # Visitor 3 has invalid birth date
    # Visitor 4 has invalid home location
    # Visitor 5 has invalid from location
    # Visitor 6 has invalid entry reason
    # Visitor 7 has invalid visa date
    # Visitor 8 has invalid visa code
    # Visitor 9 has invalid via location
    assert decide("test_invalid_visitor.json", "countries.json") == \
        ["Reject", "Reject", "Reject", "Reject", "Reject", "Reject", "Reject", "Reject", "Reject"]
コード例 #39
0
def test_incomplete_entries():
    """
    Travellers with one entry missing from all possible fields
        1)Missing passport number
        2)Missing first name
        3)Missing last name
        4)Missing birth date
        5)Missing home: city
        6)Missing home: region
        7)Missing home: country
        8)Missing entry reason
        9)Missing from: city
        10)Missing from: region
        11)Missing from: country
        12)Missing passport number but quarantine takes priority over reject
        13)Missing visa date
        14)Missing visa code
    """
    assert decide("test_incomplete_entries.json", "countries.json") ==\
        ["Reject", "Reject", "Reject", "Reject", "Reject", "Reject",
         "Reject", "Reject", "Reject", "Reject", "Reject", "Quarantine",
         "Reject", "Reject"]
コード例 #40
0
def test_decide_missing_required_information():
    """
    Travellers have required information that is missing, including incomplete location information.
    """
    assert decide("test_decide_missing_required_information.json",
                  COUNTRIES_FILE) == ["Reject"] * 17
コード例 #41
0
def test_decide_no_citizens():
    """
    No travellers are returning.
    """
    assert decide("test_decide_no_citizens.json", COUNTRIES_FILE) == []
コード例 #42
0
def test_returning():
    """
    Travellers are returning to KAN.
    """
    assert decide("test_returning_citizen.json", "countries.json") ==\
        ["Accept", "Accept", "Quarantine"]