def test_add_rem_assoc(monkeypatch, setup_mdb_dir):
    tmpdir = setup_mdb_dir
    os.chdir(tmpdir)
    mdb_file = os.path.join(TESTS_DIR, 'all_test_files', 'manga_db.sqlite.sql')
    memdb = load_db_from_sql_file(mdb_file, ':memory:', True)
    monkeypatch.setattr('manga_db.manga_db.MangaDB._load_or_create_sql_db', (lambda x, y, z: (memdb, None)))
    mdb = MangaDB(tmpdir, mdb_file)
    db_con = memdb
    b = mdb.get_book(5)
    tag_before = b.tag.copy()
    tag_change = ['Test1', 'Test2', 'Blabla']
    with mdb.db_con:
        b._add_associated_column_values('tag', tag_change)
    tag = db_con.execute("\n        SELECT group_concat(Tag.name, ';')\n        FROM Books, BookTag bt, Tag\n        WHERE  Books.id = bt.book_id\n        AND Tag.id = bt.tag_id\n        AND Books.id = 5").fetchone()
    assert (tag[0].split(';')[(- 3):] == tag_change)
    with mdb.db_con:
        b._remove_associated_column_values('tag', tag_change)
    tag = db_con.execute("\n        SELECT group_concat(Tag.name, ';')\n        FROM Books, BookTag bt, Tag\n        WHERE  Books.id = bt.book_id\n        AND Tag.id = bt.tag_id\n        AND Books.id = 5").fetchone()
    assert (tag[0].split(';') == tag_before)
def test_add_rem_assoc(monkeypatch, setup_mdb_dir):
    tmpdir = setup_mdb_dir
    os.chdir(tmpdir)
    mdb_file = os.path.join(TESTS_DIR, 'all_test_files', 'manga_db.sqlite.sql')
    memdb = load_db_from_sql_file(mdb_file, ':memory:', True)
    monkeypatch.setattr('manga_db.manga_db.MangaDB._load_or_create_sql_db', (lambda x, y, z: (memdb, None)))
    mdb = MangaDB(tmpdir, mdb_file)
    db_con = memdb
    b = mdb.get_book(5)
    tag_before = b.tag.copy()
    tag_change = ['Test1', 'Test2', 'Blabla']
    with mdb.db_con:
        b._add_associated_column_values('tag', tag_change)
    tag = db_con.execute("\n        SELECT group_concat(Tag.name, ';')\n        FROM Books, BookTag bt, Tag\n        WHERE  Books.id = bt.book_id\n        AND Tag.id = bt.tag_id\n        AND Books.id = 5").fetchone()
    assert (tag[0].split(';')[(- 3):] == tag_change)
    with mdb.db_con:
        b._remove_associated_column_values('tag', tag_change)
    tag = db_con.execute("\n        SELECT group_concat(Tag.name, ';')\n        FROM Books, BookTag bt, Tag\n        WHERE  Books.id = bt.book_id\n        AND Tag.id = bt.tag_id\n        AND Books.id = 5").fetchone()
    assert (tag[0].split(';') == tag_before)