Example #1
0
    def test_empty_inputs(self):

        with pytest.raises(SystemExit):
            assert get_swapi_matches("", "")

        with pytest.raises(SystemExit):
            assert get_swapi_matches("", "leia")
Example #2
0
    def test_correct_inputs_addedword(self):

        # These inputs include the ranks.

        # Actual names on SWAPI: "Ackbar" and "Grievous".

        assert get_swapi_matches("general ackbar",
                                 "general grievous") == sorted(
                                     [["http://swapi.dev/api/films/3/"],
                                      ["http://swapi.dev/api/films/6/"]],
                                     key=len)

        # Actual names on SWAPI: "Dooku" and "Yoda".

        assert get_swapi_matches("count dooku", "master yoda") == sorted(
            [[
                "http://swapi.dev/api/films/5/",
                "http://swapi.dev/api/films/6/"
            ],
             [
                 "http://swapi.dev/api/films/2/",
                 "http://swapi.dev/api/films/3/",
                 "http://swapi.dev/api/films/4/",
                 "http://swapi.dev/api/films/5/",
                 "http://swapi.dev/api/films/6/"
             ]],
            key=len)
Example #3
0
    def test_nonexistent_inputs(self):

        # Some of the following inputs do not belong to Star Wars.

        assert get_swapi_matches("iron man", "captain america") == []

        assert get_swapi_matches("thor", "leia") == [[
            "http://swapi.dev/api/films/1/", "http://swapi.dev/api/films/2/",
            "http://swapi.dev/api/films/3/", "http://swapi.dev/api/films/6/"
        ]]
Example #4
0
    def test_correct_inputs_exactmatch(self):
        assert get_swapi_matches("yoda", "palpatine") == sorted(
            [[
                "http://swapi.dev/api/films/2/",
                "http://swapi.dev/api/films/3/",
                "http://swapi.dev/api/films/4/",
                "http://swapi.dev/api/films/5/",
                "http://swapi.dev/api/films/6/"
            ],
             [
                 "http://swapi.dev/api/films/2/",
                 "http://swapi.dev/api/films/3/",
                 "http://swapi.dev/api/films/4/",
                 "http://swapi.dev/api/films/5/",
                 "http://swapi.dev/api/films/6/"
             ]],
            key=len)

        assert get_swapi_matches("mace windu", "darth maul") == sorted([[
            "http://swapi.dev/api/films/4/", "http://swapi.dev/api/films/5/",
            "http://swapi.dev/api/films/6/"
        ], ["http://swapi.dev/api/films/4/"]],
                                                                       key=len)

        assert get_swapi_matches("han solo", "chewbacca") == sorted(
            [[
                "http://swapi.dev/api/films/1/",
                "http://swapi.dev/api/films/2/",
                "http://swapi.dev/api/films/3/"
            ],
             [
                 "http://swapi.dev/api/films/1/",
                 "http://swapi.dev/api/films/2/",
                 "http://swapi.dev/api/films/3/",
                 "http://swapi.dev/api/films/6/"
             ]],
            key=len)

        # Despite being the same character, there are still two entries for him. Probably
        # due to the "becoming another person" reference from Episode VI.

        assert get_swapi_matches("anakin skywalker", "darth vader") == sorted(
            [[
                "http://swapi.dev/api/films/4/",
                "http://swapi.dev/api/films/5/",
                "http://swapi.dev/api/films/6/"
            ],
             [
                 "http://swapi.dev/api/films/1/",
                 "http://swapi.dev/api/films/2/",
                 "http://swapi.dev/api/films/3/",
                 "http://swapi.dev/api/films/6/"
             ]],
            key=len)
Example #5
0
    def test_correct_inputs_incomplete(self):

        # Actual names on SWAPI: "Luke Skywalker" and "Leia Organa".
        # These inputs are missing the surnames.

        assert get_swapi_matches("luke", "leia") == sorted(
            [[
                "http://swapi.dev/api/films/1/",
                "http://swapi.dev/api/films/2/",
                "http://swapi.dev/api/films/3/",
                "http://swapi.dev/api/films/6/"
            ],
             [
                 "http://swapi.dev/api/films/1/",
                 "http://swapi.dev/api/films/2/",
                 "http://swapi.dev/api/films/3/",
                 "http://swapi.dev/api/films/6/"
             ]],
            key=len)

        # Actual names on SWAPI: "Qui-Gon Jinn" and "Obi-Wan Kenobi".

        assert get_swapi_matches("qui gon", "obi wan") == sorted(
            [["http://swapi.dev/api/films/4/"],
             [
                 "http://swapi.dev/api/films/1/",
                 "http://swapi.dev/api/films/2/",
                 "http://swapi.dev/api/films/3/",
                 "http://swapi.dev/api/films/4/",
                 "http://swapi.dev/api/films/5/",
                 "http://swapi.dev/api/films/6/"
             ]],
            key=len)

        # Actual names on SWAPI: "Padmé Amidala" and "Darth Vader".

        assert get_swapi_matches("padme", "vader") == sorted(
            [[
                "http://swapi.dev/api/films/4/",
                "http://swapi.dev/api/films/5/",
                "http://swapi.dev/api/films/6/"
            ],
             [
                 "http://swapi.dev/api/films/1/",
                 "http://swapi.dev/api/films/2/",
                 "http://swapi.dev/api/films/3/",
                 "http://swapi.dev/api/films/6/"
             ]],
            key=len)
Example #6
0
    def test_correct_inputs_typo(self):

        # Actual names on SWAPI: "Boba Fett" and "Lando Calrissian".

        assert get_swapi_matches("boba feet", "lando calrisian") == sorted(
            [[
                "http://swapi.dev/api/films/2/",
                "http://swapi.dev/api/films/3/",
                "http://swapi.dev/api/films/5/"
            ],
             [
                 "http://swapi.dev/api/films/2/",
                 "http://swapi.dev/api/films/3/"
             ]],
            key=len)
def lambda_swapi_func(first_char: str, second_char: str) -> Union[str, List]:
    """
	Takes the inputted characters and returns a message indicating whether
	they were found on SWAPI, if there are movies where both characters 
	appear, and the movies titles if there were matches.
	"""

    link_list = get_swapi_matches(first_char, second_char)

    set_results = get_common_movies(link_list)

    if type(set_results) != list:
        return set_results
    else:
        cleaned_results = get_movie_from_url(set_results)
        print("\n|RESULT| -> The selected characters share these movies:")
        return cleaned_results
Example #8
0
    def test_correct_inputs_changedword(self):

        # Actual names on SWAPI: "Jabba Desilijic Tiure" and "Obi-Wan Kenobi".

        assert get_swapi_matches("jabba the hutt", "ben kenobi") == sorted(
            [[
                "http://swapi.dev/api/films/1/",
                "http://swapi.dev/api/films/3/",
                "http://swapi.dev/api/films/4/"
            ],
             [
                 "http://swapi.dev/api/films/1/",
                 "http://swapi.dev/api/films/2/",
                 "http://swapi.dev/api/films/3/",
                 "http://swapi.dev/api/films/4/",
                 "http://swapi.dev/api/films/5/",
                 "http://swapi.dev/api/films/6/"
             ]],
            key=len)
Example #9
0
    def test_correct_inputs_nohyphen(self):

        # Actual names on SWAPI: "C-3PO" and "R2-D2".

        assert get_swapi_matches("c3po", "r2d2") == sorted(
            [[
                "http://swapi.dev/api/films/1/",
                "http://swapi.dev/api/films/2/",
                "http://swapi.dev/api/films/3/",
                "http://swapi.dev/api/films/4/",
                "http://swapi.dev/api/films/5/",
                "http://swapi.dev/api/films/6/"
            ],
             [
                 "http://swapi.dev/api/films/1/",
                 "http://swapi.dev/api/films/2/",
                 "http://swapi.dev/api/films/3/",
                 "http://swapi.dev/api/films/4/",
                 "http://swapi.dev/api/films/5/",
                 "http://swapi.dev/api/films/6/"
             ]],
            key=len)
Example #10
0
    def test_incomplete_arguments(self):

        with pytest.raises(TypeError):
            get_swapi_matches("leia")