def db(tmpdir): file = os.path.join(tmpdir.strpath, "test.db") conn = sqlite3.connect(file) conn.execute(''' CREATE TABLE movies(title, year, runtime, genre, director, cast, writer, language, country, awards, IMDb_rating, IMDb_votes,box_office) ''') commands_manager = CommandsManager(conn) commands_manager.add_to_database("Memento") commands_manager.add_to_database("The Shawshank Redemption") commands_manager.add_to_database("Interstellar") commands_manager.add_to_database("Coco") commands_manager.add_to_database("Inception") yield conn conn.close()
def main(): conn = create_connection() if conn is None: exit(0) if not os.path.isfile('./databaseIsFilled.txt'): fill_database(conn) commands_manager = CommandsManager(conn) for arg in sys.argv: if "--sort_by" in arg: commands_manager.print_sorted_data() elif "--filter_by" in arg: commands_manager.print_filtered_data() elif "--compare" in arg: commands_manager.print_comparision() elif "--add" in arg: commands_manager.add_to_database() elif "--highscores" in arg: commands_manager.print_high_scores()
def test_if_comparing_print_proper_values(db, capsys): commands_manager = CommandsManager(db) commands_manager.print_comparision("runtime", "Memento", "Interstellar") captured = capsys.readouterr() assert captured.out == """Interstellar 169 min\n"""
def test_if_filtering_by_director_print_values_properly(db, capsys): commands_manager = CommandsManager(db) commands_manager.print_filtered_data("director", "Christopher Nolan") captured = capsys.readouterr() assert captured.out == """Memento - Christopher Nolan
def test_if_sorting_prints_proper_values(db, capsys): commands_manager = CommandsManager(db) commands_manager.add_to_database("it") commands_manager.print_sorted_data(["year", "runtime"]) captured = capsys.readouterr() assert captured.out == """It - 2017 - 135 min
def test_if_highscores_have_proper_values(db, capsys): commands_manager = CommandsManager(db) commands_manager.print_high_scores() captured = capsys.readouterr() assert captured.out == """Runtime: Interstellar - 169 min
def test_if_all_adds_were_executed_properly(db, capsys): commands_manager = CommandsManager(db) commands_manager.print_all_data() captured = capsys.readouterr() assert captured.out == """('Memento', 2000, '113 min', 'Mystery, Thriller', 'Christopher Nolan', 'Guy Pearce, Carrie-Anne Moss, Joe Pantoliano, Mark Boone Junior', 'Christopher Nolan (screenplay), Jonathan Nolan (short story "Memento Mori")', 'English', 'USA', 'Nominated for 2 Oscars. Another 56 wins & 55 nominations.', 8.4, 1045443, 23844220)