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 test_get_list_from_path(init_interpreter, doc_type): if doc_type == "file": return interpreter = init_interpreter items = items_in_file(doc_type)[2] parser = interpreter[doc_type].parser names = get_names(parser) # SQL query instance for query memoization sql = SQLQuery() fails = [] for item in items: submitter_id = item["submitter_id"] results = ESValue(parser, submitter_id, doc_type, names) result_length = results.length if result_length != 1: if result_length < 1: fails.append( "Not exist expected {doc_type} with submitter_id {item} in ES" .format(doc_type=doc_type, item=submitter_id)) else: fails.append( "Duplicated {doc_type} with submitter_id {item} in ES". format(doc_type=doc_type, item=submitter_id)) value = AggregatorValue(sql, parser, submitter_id, doc_type, names) equal, diff = value_diff(results, value) if not equal: fails.append(diff) assert fails == []
@pytest.mark.parametrize("filename", test_files) 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 @pytest.mark.parametrize( "filename,total,entries", [items_in_file(f) for f in test_files] ) 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())
@pytest.mark.parametrize("filename", test_files) 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 @pytest.mark.parametrize("filename,total,entries", [items_in_file(f) for f in test_files]) 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 = map(lambda item: item["_props"], 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)