cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Is there a library to unit test graphdb cypher queries using python

npatel
Node Clone

Hi,

I have some CYPHER queries that are executed using neo4j-driver. Things works fine in real, but I want to also write unit tests for this class so all possible scenarios are verified. With mysql etc we can use use sqllite and let the queries run on it. Is there a lite version of neo4j db that we can spawn up for test and kill after use?
I don't want to mock all db and session objs, as those tests are pretty dummy and not really useful in case things change.

Thanks,

1 ACCEPTED SOLUTION

You can also put your queries into .cypher files and use a linter like libcypher-parser to check that your queries are valid.

View solution in original post

4 REPLIES 4

wesm
Node Link

Do you want to test that they work as expected (i.e. return the proper items) or just that they execute? If the latter, I would say a docker container running neo4j with a small seed script would do the trick as it spins up relatively quickly, is lightweight, and will let you test that the responses are as expected.

yea the later "just that they execute" as the queries will almost be hardcoded with parameter that change. so they would be verified.

wesm
Node Link

Yeah, a simple docker container would be the easiest way to go then - you wouldn't even need to seed the DB, just check that there is not an exception.

With python, this can be as simple as using a try...catch and failing the test on any exception.

for QUERY in QUERIES:
  try:
    GRAPH.run(QUERY)
  except:
    print(f"{QUERY} failed")

You can also put your queries into .cypher files and use a linter like libcypher-parser to check that your queries are valid.