Пример #1
0
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
        }
    }
Пример #2
0
def test_add_missing_columns():
    create_test_tables()
    db = MySQLDatabase(schema='qmdb_test', env='test')
    db.columns_netflix_genres = {
        'genreid': 'int(10) unsigned',
        'genre_name': 'varchar(128)',
        'test_column': 'int(10) unsigned',
        'movies_updated': 'varchar(32)'
    }
    db.connect()
    db.add_missing_columns('netflix_genres')
    db.c.execute("""
        SELECT
            column_name,
            column_type
        FROM information_schema.columns 
        WHERE table_name='netflix_genres'
          AND table_schema='qmdb_test'
        """)
    actual_cols = db.c.fetchall()
    actual_cols_dict = {
        d['column_name']: d['column_type']
        for d in actual_cols
    }
    assert actual_cols_dict == db.columns_netflix_genres
    assert list(actual_cols_dict.keys()) == list(db.columns_netflix_genres)
Пример #3
0
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)
Пример #4
0
def test_load_netflix_genres():
    create_test_tables()
    db = MySQLDatabase(schema='qmdb_test', env='test')
    db.connect()
    db.load_netflix_genres()
    assert db.netflix_genres == {
        1: {
            'genre_names': ['All Action', 'All Anime'],
            'movies_updated': arrow.get('2018-02-04 23:01:58+01:00')
        },
        2: {
            'genre_names': ['All Anime'],
            'movies_updated': None
        }
    }
Пример #5
0
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)
Пример #6
0
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)
Пример #7
0
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)
Пример #8
0
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()