def test_parse_actors(self): actors = Film.parse_actors(self.soup) expected = {'Julian Arahanga': 'Apoc', 'Carrie-Anne Moss': 'Trinity', 'Gloria Foster': 'Wyrocznia', 'Marcus Chong': 'Tank', 'Hugo Weaving': 'Agent Smith', 'Keanu Reeves': 'Neo', 'Laurence Fishburne': 'Morfeusz', 'Joe Pantoliano': 'Cypher'} self.assertDictEqual(actors, expected)
def test_get_by_id(self): film = Film.get_by_id(868) self.assertIsInstance(film, Film) self.assertEqual(film.title, "Być jak John Malkovich") self.assertEqual(film.url, "http://www.filmweb.pl/film/By%C4%87+jak+John+Malkovich-1999-868") self.assertEqual(film.year, 1999) self.assertEqual(film.id_, 868)
def setUp(self): self.films = list(Film.search("john malkovich")) self.example = self.films[0] #several directors, screenwriters, genres, countries self.soup = make_request("http://www.filmweb.pl/Matrix") #no descrition; duration less than hour self.soup2 = make_request("http://www.filmweb.pl/film/Sipur+Ahava-1990-352246")
def test_search_multiple_pages(self): """ Walking through a series of pages """ results = list(Film.search("terminator", max_page=3)) single_film = results[0] self.assertEqual(len(results), 30) self.assertIsInstance(single_film, Film) self.assertEqual(single_film.title, "Terminator") self.assertEqual(single_film.url, "http://www.filmweb.pl/Terminator")
def test_search_multiple_pages(self): """ Walking through a series of pages """ results = list(Film.search("terminator", max_page=3)) single_film = results[0] self.assertEqual(len(results), 28) self.assertIsInstance(single_film, Film) self.assertEqual(single_film.title, "Terminator: Mroczne przeznaczenie") self.assertEqual(single_film.url, "http://www.filmweb.pl/film/Terminator%3A+Mroczne+przeznaczenie-2019-723372")
def test_parse_genre(self): genres = Film.parse_genre(self.soup) self.assertListEqual(genres, ["Akcja", "Sci-Fi"])
def test_parse_duration_lt_hour(self): """ Film is shorter than 1 hour """ dur = Film.parse_duration(self.soup2) self.assertEqual(dur, datetime.time(0, 30))
def test_parse_duration(self): dur = Film.parse_duration(self.soup) self.assertEqual(dur, datetime.time(2, 16))
def test_parse_director(self): directors = Film.parse_director(self.soup) self.assertListEqual(directors, ["Lilly Wachowski", "Lana Wachowski"])
def test_parse_no_description(self): """ Film has no description """ descr = Film.parse_description(self.soup2) self.assertEqual(descr, "")
def test_parse_description(self): descr = Film.parse_description(self.soup) expected = "Haker komputerowy Neo dowiaduje się od tajemniczych " \ "rebeliantów, że świat, w którym żyje, jest tylko " \ "obrazem przesyłanym do jego mózgu przez roboty." self.assertEqual(descr, expected)
def test_parse_country(self): countries = Film.parse_country(self.soup) self.assertListEqual(countries, ["Australia", "USA"])
def test_parse_original_title(self): o_title = Film.parse_original_title(self.soup) self.assertEqual(o_title, "The Matrix")
def test_get_by_id_not_found(self): film = Film.get_by_id(67825) self.assertIsNone(film)
def test_parse_screenwriter(self): screenwriters = Film.parse_screenwriter(self.soup) self.assertListEqual(screenwriters, ["Lilly Wachowski", "Lana Wachowski"])
def test_search_no_results(self): results = list(Film.search("sdfghjfghj")) self.assertListEqual(results, [])
def test_parse_topics(self): count = Film.parse_topics(self.soup) self.assertGreaterEqual(count, 0)
def test_parse_budget(self): budget = Film.parse_budget(self.soup) self.assertEqual(63000000, budget)
def test_parse_boxoffice(self): boxoffice = Film.parse_boxoffice(self.soup) self.assertEqual(463517383, boxoffice)