Merge: curl: basic Unix domain socket support
[nit.git] / tests / test_neo4j_batch.nit
index 7455557..464eb2f 100644 (file)
@@ -17,7 +17,8 @@ import neo4j
 var srv = new Neo4jServer
 srv.start_quiet
 
-var key = get_time
+# key used to loosely assume unicity and prevent conflicting db accesses
+var key = "NIT_TESTING_ID".environ.to_i
 
 var andres = new NeoNode
 andres.labels.add_all(["PERSON", "MALE"])
@@ -39,6 +40,13 @@ loves["since"] = 1999
 var client = new Neo4jClient("http://localhost:7474")
 assert client.is_ok
 
+# Clear the previous objects, if any
+client.cypher(
+       new CypherQuery.from_string(
+               "MATCH (n) WHERE n.key = \{key\} OPTIONAL MATCH n-[r]-() DELETE r, n"
+       ).set("key", key)
+)
+
 print "# Save batch\n"
 
 var batch = new NeoBatch(client)
@@ -92,8 +100,9 @@ print "{res5["name"].to_s} IS LOVED BY {res5.in_nodes("LOVES").first["name"].to_
 var query = (new CypherQuery).
        nmatch("(n: MALE)-[r: LOVES]->(m)").
        nwhere("n.name = 'Andres'").
-       nand("n.key = {key}").
-       nreturn("n, r, m")
+       nand("n.key = \{key\}").
+       nreturn("n, r, m").
+       set("key", key)
 var res7 = client.cypher(query)
 assert res7.as(JsonObject)["data"].as(JsonArray).length == 1