def test_total_number_equal_db(filename): _, total_in_files, _ = items_in_file(filename) with get_db_cursor("db") as cur: table = AsIs("node_{table}".format(table=filename.replace("_", ""))) cur.execute("SELECT COUNT(*) FROM %s;", (table,)) total_subjects_in_db = cur.fetchall()[0]["count"] assert total_in_files == total_subjects_in_db
def get_all_edge_tables_in_db(self): with get_db_cursor("db") as cur: db_name = cur.connection.info.dbname query_all_tb_names = ( "select table_name from information_schema.tables " "where table_schema='public' and table_catalog='{dbname}' and table_name like 'edge_%';" .format(dbname=db_name)) cur.execute(query_all_tb_names) edge_tbs_in_db = cur.fetchall() return edge_tbs_in_db
def test_items_equal_db(filename, total, entries): with get_db_cursor("db") as cur: table = AsIs("node_{table}".format(table=filename.replace("_", ""))) cur.execute("SELECT _props FROM %s;", (table,)) prop_json = cur.fetchall() prop_json = [item["_props"] for item in prop_json] prop_json = sorted(prop_json, key=itemgetter("submitter_id")) for x, y in zip(entries, prop_json): keys_x = set(x.keys()) keys_y = set(y.keys()) keys_xy = keys_x.intersection(keys_y) assert len(keys_xy) != 0 for key in keys_xy: assert x[key] == y[key]
def get_edges_having_data(self): list_tb_names_from_dict = get_all_edges_table(self.model) tb_names = list( set(list_tb_names_from_dict) & set([ i.get("table_name") for i in self.get_all_edge_tables_in_db() ])) query = ", ".join( "(select count(*) from {tb_name}) as {tb_name}".format( tb_name=tb_name) for tb_name in tb_names) query_statement = "select {query};".format(query=query) with get_db_cursor("db") as cur: cur.execute(query_statement) count_values = cur.fetchone() tb_names_with_data = [] for i in range(len(tb_names)): if count_values[i] > 0: tb_names_with_data.append(tb_names[i]) return tb_names_with_data