Esempio n. 1
0
def test_database_persistence():
    teardown_db(db_path)
    with MemeDatabase('foo', db_path) as db:
        db.insert_question(123)
        assert db.question_is_known(123)
    with MemeDatabase('foo', db_path) as db:
        assert db.question_is_known(123)
    teardown_db(db_path)
Esempio n. 2
0
def test_database_multi_insert():
    teardown_db(db_path)
    ids = range(100, 200)
    with MemeDatabase('foo', db_path) as db:
        for id in ids:
            assert not db.question_is_known(id)
            db.insert_question(id)
            assert db.question_is_known(id)
Esempio n. 3
0
def test_database_init():
    teardown_db(db_path)
    with MemeDatabase('foo', db_path) as db:
        cursor = db.conn.cursor()
        cursor.execute(f"select count(*) from foo")
        result = cursor.fetchone()
        assert result[0] == 0
        cursor.close()
        assert not db.question_is_known(123)
    teardown_db(db_path)
Esempio n. 4
0
def test_database_insert():
    teardown_db(db_path)
    with MemeDatabase('foo', db_path) as db:
        db.insert_question(123)
        cursor = db.conn.cursor()
        cursor.execute(f'select count(*) from foo')
        result = cursor.fetchone()
        assert result[0] == 1
        cursor.execute(f'select question_id from foo')
        result = cursor.fetchone()
        assert result[0] == 123
        cursor.close()
        assert db.question_is_known(123)
    teardown_db(db_path)
Esempio n. 5
0
def test_database_bad_connect():
    teardown_db(db_path)
    with pytest.raises(TypeError):
        MemeDatabase()
    with pytest.raises(TypeError):
        MemeDatabase(None, 'foo')
    with pytest.raises(TypeError):
        MemeDatabase(123, 'foo')
    with pytest.raises(TypeError):
        MemeDatabase('', 'foo')
    with pytest.raises(TypeError):
        MemeDatabase('foo',)
    with pytest.raises(TypeError):
        MemeDatabase('foo', None)
    with pytest.raises(TypeError):
        MemeDatabase('foo', '')
    with pytest.raises(TypeError):
        MemeDatabase(db_path=db_path)
        teardown_db(db_path)
Esempio n. 6
0
def test_database_good_connect():
    teardown_db(db_path)
    with MemeDatabase('foo', db_path) as db:
        assert repr(db).startswith("<MemeDatabase")
        assert repr(db).endswith("site='foo'>")
    teardown_db(db_path)
Esempio n. 7
0
def test_database_bad_connect():
    teardown_db(db_path)
    with pytest.raises(TypeError):
        MemeDatabase()
Esempio n. 8
0
from memeoverflow import MemeDatabase
import sys

db = MemeDatabase('raspberrypi')

if len(sys.argv) > 1:
    arg = sys.argv[1]
    try:
        meme_id = int(arg)
        meme_name = db.select_meme(meme_id)
        db.blacklist_meme(meme_id)
        print(f'Blacklisted: {meme_name}')
    except ValueError:
        results = db.search_for_meme(arg)
        for id, name, blacklisted in results:
            print(f"{id}: {name} {'(blacklisted)' if blacklisted else ''}")
else:
    print('No argument provided')
Esempio n. 9
0
def test_database_good_connect():
    teardown_db(db_path)
    with MemeDatabase('foo', db_path) as db:
        assert repr(db).startswith('<MemeDatabase')
        assert repr(db).endswith('site foo>')
    teardown_db(db_path)