def test_set_netflix_genres(): create_test_tables() db = MySQLDatabase(schema='qmdb_test', env='test') db.netflix_genres = { 1: { 'genre_names': ['All Action', 'Belgian Movies'], 'movies_updated': arrow.get('2018-02-05 23:01:58+01:00') }, 3: { 'genre_names': ['Japanese Anime'], 'movies_updated': None } } db.set_netflix_genres() db.connect() db.load_netflix_genres() db.close() assert db.netflix_genres == { 1: { 'genre_names': ['All Action', 'Belgian Movies'], 'movies_updated': arrow.get('2018-02-05 23:01:58+01:00') }, 3: { 'genre_names': ['Japanese Anime'], 'movies_updated': None } }
def test_load_languages(mocker): create_test_tables() db = MySQLDatabase(schema='qmdb_test', env='test') mocker.patch.object(db, 'load_or_initialize', lambda x: None) movies = {1234: dict(), 49141: dict()} db.connect() db.load_languages(movies) db.close() assert movies[1234]['languages'] == ['English', 'French'] assert movies[49141]['languages'] == ['English'] remove_test_tables(db)
def test_load_persons(mocker): create_test_tables() db = MySQLDatabase(schema='qmdb_test', env='test') mocker.patch.object(db, 'load_or_initialize', lambda x: None) movies = {1234: dict(), 49141: dict()} db.connect() db.load_persons(movies) db.close() assert [e['name'] for e in movies[1234]['director'] ] == ['Lana Wachowski', 'J.J. Abrams'] assert [e['name'] for e in movies[1234]['cast'] ] == ['Anthony Hopkins', 'Tom Cruise'] assert [e['name'] for e in movies[49141]['director']] == ['Steven Spielberg'] assert [e['name'] for e in movies[49141]['cast']] == ['Natalie Portman'] remove_test_tables(db)
def test_add_column(): create_test_tables() db = MySQLDatabase(schema='qmdb_test', env='test') db.connect() db.add_column('test_column', 'mediumint', table_name='movies', after='crit_id') db.c.execute(""" SELECT column_name, column_type FROM information_schema.columns WHERE table_name='movies' and table_schema='qmdb_test' """) columns = db.c.fetchall() assert columns[1]['column_name'] == 'test_column' assert columns[1]['column_type'] == 'mediumint(9)' db.add_column('imdbid', 'integer', table_name='movies') db.close() remove_test_tables(db)
def test_update_existing_movie(): create_test_tables() db = MySQLDatabase(schema='qmdb_test', env='test') existing_movie = { 'crit_id': 1234, 'title': 'The Matrix 2', 'genres': ['Action', 'Sci-Fi'] } movie = db.movies[existing_movie['crit_id']] movie.update_from_dict(existing_movie) db.set_movie(movie) db.connect() db.c.execute("select * from genres where crit_id = %s", [existing_movie['crit_id']]) results = db.c.fetchall() db.close() assert set([result['genre'] for result in results]) == {'Action', 'Sci-Fi'} assert db.movies[1234].year == 1999 db = MySQLDatabase(schema='qmdb_test', env='test') assert 1234 in list(db.movies.keys()) assert db.movies[1234].title == 'The Matrix 2' assert db.movies[1234].year == 1999 assert db.movies[1234].genres == ['Action', 'Sci-Fi'] remove_test_tables(db)
def create_copy_of_table(src, tgt, schema='qmdb_test'): db = MySQLDatabase(schema=schema) db.remove_table(tgt) db.connect() db.c.execute("create table {} as select * from {}".format(tgt, src)) db.close()