Skip to content

Commit

Permalink
add test for loading and dumping scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
perierc committed Nov 9, 2023
1 parent 9bf6c44 commit fb37f28
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
1 change: 0 additions & 1 deletion backend/sample/dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
30 changes: 30 additions & 0 deletions backend/tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import os
import json
import subprocess
import pytest


Expand Down Expand Up @@ -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)

0 comments on commit fb37f28

Please sign in to comment.