def test_sorting_by_awards(self): self.db_api.insert_many(query.update(), self.update_data) data = self.db_api.select_one(query.sort("awards")) data_int = data[:5] test_data_int = sorted( list( zip( map(itemgetter(0), data_int), map( lambda x: int(x) if x.isdigit() else None, map(itemgetter(1), data_int), ), )), key=itemgetter(1), reverse=True, ) test_data = list( zip( map(itemgetter(0), test_data_int), map( lambda x: "N/A" if x is None else str(x), map(itemgetter(1), test_data_int), ), )) self.assertEqual(test_data, data[:5])
def test_compare_by_imdb_rating(self): self.db_api.insert_many(query.update(), self.update_data) self.assertEqual( [("The Godfather", "9.2")], self.db_api.select_one(query.compare("imdb"), data=("The Godfather", "Gods")), )
def test_compare_by_runtime(self): self.db_api.insert_many(query.update(), self.update_data) self.assertEqual( [("The Godfather", "2h55min")], self.db_api.select_one(query.compare("runtime"), data=("The Godfather", "Gods")), )
def test_filter_by_movies_with_oscar_nomination(self): self.db_api.insert_many(query.update(), self.update_data) data = self.db_api.select_one(query.filter_("oscar_nom")) self.assertEqual( list(map(itemgetter(0), data)), ["The Shawshank Redemption", "Memento", "In Bruges"], )
def test_compare_by_awards_won(self): self.db_api.insert_many(query.update(), self.update_data) self.assertEqual( [("The Godfather", "24")], self.db_api.select_one(query.compare("awards"), data=("The Godfather", "Gods")), )
def test_compare_by_boxoffice_earnings(self): self.db_api.insert_many(query.update(), self.update_data) self.assertEqual( [("Memento", "$23,844,220")], self.db_api.select_one(query.compare("boxoffice"), data=("Memento", "In Bruges")), )
def test_compare_when_one_na(self): self.db_api.insert_many(query.update(), self.update_data) self.assertEqual( [("In Bruges", "$7,550,836")], self.db_api.select_one( query.compare("boxoffice"), data=("In Bruges", "Gods"), ), )
def test_highscore_in_earnings(self): self.db_api.insert_many( query.update(), self.update_data, ) self.assertEqual( [("Memento", "$23,844,220")], self.db_api.select_one(query.highscores()[1], ), )
def test_highscore_in_awards(self): self.db_api.insert_many( query.update(), self.update_data, ) self.assertEqual( [("Memento", "56")], self.db_api.select_one(query.highscores()[2], ), )
def test_compare_movie_not_in_db(self): self.db_api.insert_many(query.update(), self.update_data) self.assertRaises( ValueError, lambda: self.db_api.select_one( query.compare("imdb"), data=("The Dogfather", "The Godfather,"), check=True, ), )
def test_filter_by_actor(self): self.db_api.insert_many(query.update(), self.update_data) data = self.db_api.select_one(query.filter_("actor"), data=("Szymon Piotr Warszawski", )) self.assertEqual( data, [( "Gods", "Tomasz Kot, Piotr Glowacki, Szymon Piotr Warszawski, Magdalena Czerwinska", )], ),
def test_updating_multiple_rows(self): self.db_api.insert_many(query.update(), self.update_data) binding = [tuple([row[0]]) for row in self.test_data] params = list( zip_longest([query.select()], binding, fillvalue=query.select())) db_data = [self.db_api.select_one(selq, val) for selq, val in params] test_data = [[ tuple( format_runtime(v) if i == 2 else v for i, v in enumerate(data)) ] for data in self.test_data] self.assertEqual(test_data, db_data)
def test_updating_one_row(self): self.db_api.insert_one(query.update(), self.update_data[0]) db_data = self.db_api.select_one(query.select(), tuple([self.test_data[0][0]])) self.assertEqual( db_data, [ tuple( format_runtime(v) if i == 2 else v for i, v in enumerate(self.test_data[0])) ], )
def test_highscores_in_all_categories(self): self.db_api.insert_many(query.update(), self.update_data) self.assertEqual( [ [("The Godfather", "2h55min")], [("Memento", "$23,844,220")], [("Memento", "56")], [("Memento", "55")], [("The Godfather", "3")], [("The Shawshank Redemption", "9.3")], ], self.db_api.select_many(query.highscores()), )
def test_sorting_by_multiple_columns(self): self.db_api.insert_many(query.update(), self.update_data) data = self.db_api.select_one(query.sort("year", "title")) titles_year = [v[:2] for v in data[:5]] years = list( zip( map(itemgetter(0), titles_year), map( lambda x: int(x) if x.isdigit() else None, map(itemgetter(1), titles_year), ), )) years = sorted(years, key=itemgetter(1, 0), reverse=True) years = list( zip( map(itemgetter(0), titles_year), map( lambda x: "N/A" if x is None else str(x), map(itemgetter(1), titles_year), ), )) self.assertEqual(years, titles_year)
def _dl_upload(self): titles = dbm.get_titles() movie_data = self.downloader.download_many(titles, process=True, rotated=True) self.db_api.insert_many(query.update(), movie_data)
def test_highscore_in_imdb_rating(self): self.db_api.insert_many(query.update(), self.update_data) self.assertEqual( [("The Shawshank Redemption", "9.3")], self.db_api.select_one(query.highscores()[5]), )
def test_highscore_in_oscars(self): self.db_api.insert_many(query.update(), self.update_data) self.assertEqual( [("The Godfather", "3")], self.db_api.select_one(query.highscores()[4]), )
def test_highscore_in_nominations(self): self.db_api.insert_many(query.update(), self.update_data) self.assertEqual( [("Memento", "55")], self.db_api.select_one(query.highscores()[3]), )
def test_filter_by_director(self): self.db_api.insert_many(query.update(), self.update_data) data = self.db_api.select_one(query.filter_("director"), data=("Lukasz Palkowski", )) self.assertEqual(data[0][1], "Lukasz Palkowski")
def test_highscore_in_runtime(self): self.db_api.insert_many(query.update(), self.update_data) self.assertEqual( [("The Godfather", "2h55min")], self.db_api.select_one(query.highscores()[0], ), )
def test_filter_by_movies_over_80_ratio(self): self.db_api.insert_many(query.update(), self.update_data) data = self.db_api.select_one(query.filter_("eighty")) self.assertEqual(list(map(itemgetter(0), data)), ["Memento", "The Godfather"])
def test_filter_by_language(self): self.db_api.insert_many(query.update(), self.update_data) data = self.db_api.select_one(query.filter_("language"), data=("polish", )) self.assertEqual(list(map(itemgetter(0), data)), ["Gods"])