From fb37f289f12493e4e79ded04faa2b457b4c75ed1 Mon Sep 17 00:00:00 2001 From: Charles Perier Date: Thu, 9 Nov 2023 16:56:32 +0100 Subject: [PATCH] add test for loading and dumping scripts --- backend/sample/dump.py | 1 - backend/tests/test_api.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/backend/sample/dump.py b/backend/sample/dump.py index 96717512..f4b0fc61 100644 --- a/backend/sample/dump.py +++ b/backend/sample/dump.py @@ -20,7 +20,6 @@ def dump_nodes(session, file): node_count = session.run("MATCH (n) RETURN count(n)").single()[0] for i, node in enumerate(session.run("MATCH (n) RETURN n")): node_dict = dict(node["n"]) - print(node_dict) labels_list = list(node["n"].labels) node_dict["labels"] = labels_list if i < node_count - 1: diff --git a/backend/tests/test_api.py b/backend/tests/test_api.py index 915b68c8..ad3c8de3 100644 --- a/backend/tests/test_api.py +++ b/backend/tests/test_api.py @@ -1,3 +1,6 @@ +import os +import json +import subprocess import pytest @@ -107,3 +110,30 @@ def test_delete_project(client, github_mock): assert response.status_code == 200 assert response.json() == {"message": "Deleted 1 projects"} + + +def test_load_and_dump(): + # Path to the test data JSON file + test_data_path = "sample/test-neo4j.json" + + # Run load.py to import data into Neo4j database + subprocess.run(["sample/load.py", test_data_path]) + + # Run dump.py to dump the Neo4j database into a JSON file + dumped_file_path = "sample/dumped_test-neo4j.json" + subprocess.run(["sample/dump.py", dumped_file_path]) + + try: + # Read the original and dumped JSON files + with open(test_data_path, "r") as original_file: + original_data = json.load(original_file) + + with open(dumped_file_path, "r") as dumped_file: + dumped_data = json.load(dumped_file) + + # Perform assertions to compare the JSON contents (order-insensitive) + assert original_data == dumped_data + + finally: + # Clean up: remove the dumped file + os.remove(dumped_file_path)