def test_last_known_migration(): with closing(sqlite3.connect(":memory:")) as conn: with closing(conn.cursor()) as cur: run_migrations(conn) cur.execute("select version from migrations") version = cur.fetchone()[0] assert version == 8
def test_initial_migration_on_empty_db(): with closing(sqlite3.connect(":memory:")) as conn: with closing(conn.cursor()) as cur: run_migrations(conn, MIGRATIONS[:1]) cur.execute("select version from migrations") version = cur.fetchone()[0] assert version == 0
def test_do_not_load_from_broken_data(): file_name = NamedTemporaryFile().name with sqlite3.connect(file_name) as conn: run_migrations(conn) setup_sample_db(conn) with closing(conn.cursor()) as cur: cur.execute("delete from goals where goal_id = 2") with pytest.raises(AssertionError): load(file_name)
def test_all_goal_names_must_be_saved_correctly(name): g = Goals('renamed') g.rename(name) with closing(sqlite3.connect(':memory:')) as conn: note(g.events) run_migrations(conn) save_updates(g, conn) ng = build_goals(conn) assert g.all('name,open,edge,select') == ng.all( 'name,open,edge,select')
def test_full_export_and_streaming_export_must_be_the_same(actions, ch): g = build_from(actions, ch) with closing(sqlite3.connect(':memory:')) as conn: run_migrations(conn) note(g.events) save_updates(g, conn) assert not g.events ng = build_goals(conn) assert g.all('name,open,edge,select') == ng.all( 'name,open,edge,select')
def test_restore_goals_from_db(): file_name = NamedTemporaryFile().name with sqlite3.connect(file_name) as conn: run_migrations(conn) setup_sample_db(conn) actual_goals = load(file_name) actual_goals.accept(ToggleOpenView()) expected_goals = Goals("Root") expected_goals.accept_all( Add("A"), Add("B"), Select(2), HoldSelect(), Select(3), ToggleLink(), Select(3), ToggleClose(), Select(1), HoldSelect(), Select(2), ) keys = "name,edge,open,select" assert expected_goals.q(keys=keys) == actual_goals.q(keys=keys) assert not actual_goals.events()