Test neo4j cypher in python project


(Michael Weston) #1

Greetings,
my team and I are working on a project in python which uses py2neo to access our neo4j graph.

We are currently trying to find an answer to the question:
'What is the correct approach to test our code?'

What we have now:
We understood that there are 3 main guide lines of what we want to test:

  1. that the expected nodes and relationships were created and the labels and properties correctly set
  2. that no other nodes or relationships were created, and that no additional properties or labels were set
  3. that existing parts of the graph remained untouched
    (taken from https://graphaware.com/neo4j/2014/05/29/graph-unit-neo4j-unit-testing.html)
    We have implemented a function that returns the diff between the initial state of the graph (the state of the graph before we run our queries)
    and the final state.
    We then compare that diff to our 'expected diff' which is a list of nodes and relationships that we expect to be created.

We are not so happy with that solution because:

  1. We need to set the initial state of the database
  2. We need to declare the 'expected diff', and it can get pretty big
  3. We have implemented that solution without researching the web for solutions

What we want:
The project is written in python, we found test frameworks in Java but that does not help us.
We would like to know if:

  1. Is there a way to dynamically load a pre-made graph (neo4j graph dump) using python code?
  2. Are there any APOC functions that compare two neo4j graphs and indicate the difference between them,
    to the level of values of properties?
  3. Any other way to test our python code?