Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_unique_path_not_unique_raises_cypher_transaction_error_in_transaction(self):
tx = self.graph.begin()
cursor = tx.run("CREATE (a), (b) RETURN a, b")
tx.process()
record = next(cursor)
parameters = {"A": record["a"].identity, "B": record["b"].identity}
statement = ("MATCH (a) WHERE id(a)={A} MATCH (b) WHERE id(b)={B}" +
"CREATE (a)-[:KNOWS]->(b)")
tx.run(statement, parameters)
tx.run(statement, parameters)
statement = ("MATCH (a) WHERE id(a)={A} MATCH (b) WHERE id(b)={B}" +
"CREATE UNIQUE (a)-[:KNOWS]->(b)")
with self.assertRaises(ConstraintError):
tx.run(statement, parameters)
tx.commit()
def test_unique_path_not_unique_raises_cypher_transaction_error_in_transaction(self):
tx = self.graph.begin()
cursor = tx.run("CREATE (a), (b) RETURN a, b")
tx.process()
record = cursor.next()
parameters = {"A": record["a"].identity, "B": record["b"].identity}
statement = ("MATCH (a) WHERE id(a)={A} MATCH (b) WHERE id(b)={B}" +
"CREATE (a)-[:KNOWS]->(b)")
tx.run(statement, parameters)
tx.run(statement, parameters)
statement = ("MATCH (a) WHERE id(a)={A} MATCH (b) WHERE id(b)={B}" +
"CREATE UNIQUE (a)-[:KNOWS]->(b)")
with self.assertRaises(ConstraintError):
tx.run(statement, parameters)
tx.commit()
def test_error(self):
with self.assertRaises(CypherSyntaxError):
tx = Transaction(self.http_graph)
tx.run("X")
tx.commit()
def test_can_generate_transaction_error(self):
tx = self.graph.begin()
with self.assertRaises(CypherSyntaxError):
tx.run("X")
tx.commit()
def test_can_generate_transaction_error(self):
tx = self.graph.begin()
with self.assertRaises(CypherSyntaxError):
tx.run("X")
tx.commit()
def getDb(dbName='db.tests/demo1'):
if (os.path.isdir(dbName)):
logging.info('GraphDb found, loading...')
return GraphDatabase(dbName)
else:
logging.info('GraphDb not found, generating...')
db = GraphDatabase(dbName)
setUpDB(db)
return db
def getDb(dbName='db.tests/demo1'):
if (os.path.isdir(dbName)):
logging.info('GraphDb found, loading...')
return GraphDatabase(dbName)
else:
logging.info('GraphDb not found, generating...')
db = GraphDatabase(dbName)
setUpDB(db)
return db
:return:
"""
# Neo4j versions lower than 3.4.0 do not support Point. In that case, skip the test.
check_and_skip_neo4j_least_version(340, 'This version does not support spatial data types.')
# The test is repeatable enough to try and standardise it. The same test is repeated with the assertions in
# `basic_type_assertions` and different messages to be able to localise the exception.
#
# Array of points to inflate and messages when things go wrong
values_from_db = [(neo4j.v1.spatial.CartesianPoint((0.0, 0.0)),
'Expected Neomodel 2d cartesian point when inflating 2d cartesian neo4j point'),
(neo4j.v1.spatial.CartesianPoint((0.0, 0.0, 0.0)),
'Expected Neomodel 3d cartesian point when inflating 3d cartesian neo4j point'),
(neo4j.v1.spatial.WGS84Point((0.0, 0.0)),
'Expected Neomodel 2d geographical point when inflating 2d geographical neo4j point'),
(neo4j.v1.spatial.WGS84Point((0.0, 0.0, 0.0)),
'Expected Neomodel 3d geographical point inflating 3d geographical neo4j point')]
# Run the above tests
for a_value in values_from_db:
expected_point = neomodel.contrib.spatial_properties.NeomodelPoint(tuple(a_value[0]),
crs=neomodel.contrib.spatial_properties.SRID_TO_CRS[a_value[0].srid])
inflated_point = neomodel.contrib.spatial_properties.PointProperty(
crs=neomodel.contrib.spatial_properties.SRID_TO_CRS[a_value[0].srid]).inflate(a_value[0])
basic_type_assertions(expected_point, inflated_point, '{}, received {}'.format(a_value[1], inflated_point))
def test_inflate():
"""
Tests that the marshalling from neo4j to neomodel data types works as expected.
:return:
"""
# Neo4j versions lower than 3.4.0 do not support Point. In that case, skip the test.
check_and_skip_neo4j_least_version(340, 'This version does not support spatial data types.')
# The test is repeatable enough to try and standardise it. The same test is repeated with the assertions in
# `basic_type_assertions` and different messages to be able to localise the exception.
#
# Array of points to inflate and messages when things go wrong
values_from_db = [(neo4j.v1.spatial.CartesianPoint((0.0, 0.0)),
'Expected Neomodel 2d cartesian point when inflating 2d cartesian neo4j point'),
(neo4j.v1.spatial.CartesianPoint((0.0, 0.0, 0.0)),
'Expected Neomodel 3d cartesian point when inflating 3d cartesian neo4j point'),
(neo4j.v1.spatial.WGS84Point((0.0, 0.0)),
'Expected Neomodel 2d geographical point when inflating 2d geographical neo4j point'),
(neo4j.v1.spatial.WGS84Point((0.0, 0.0, 0.0)),
'Expected Neomodel 3d geographical point inflating 3d geographical neo4j point')]
# Run the above tests
for a_value in values_from_db:
expected_point = neomodel.contrib.spatial_properties.NeomodelPoint(tuple(a_value[0]),
crs=neomodel.contrib.spatial_properties.SRID_TO_CRS[a_value[0].srid])
inflated_point = neomodel.contrib.spatial_properties.PointProperty(
crs=neomodel.contrib.spatial_properties.SRID_TO_CRS[a_value[0].srid]).inflate(a_value[0])
basic_type_assertions(expected_point, inflated_point, '{}, received {}'.format(a_value[1], inflated_point))
def test_inflate():
"""
Tests that the marshalling from neo4j to neomodel data types works as expected.
:return:
"""
# Neo4j versions lower than 3.4.0 do not support Point. In that case, skip the test.
check_and_skip_neo4j_least_version(340, 'This version does not support spatial data types.')
# The test is repeatable enough to try and standardise it. The same test is repeated with the assertions in
# `basic_type_assertions` and different messages to be able to localise the exception.
#
# Array of points to inflate and messages when things go wrong
values_from_db = [(neo4j.v1.spatial.CartesianPoint((0.0, 0.0)),
'Expected Neomodel 2d cartesian point when inflating 2d cartesian neo4j point'),
(neo4j.v1.spatial.CartesianPoint((0.0, 0.0, 0.0)),
'Expected Neomodel 3d cartesian point when inflating 3d cartesian neo4j point'),
(neo4j.v1.spatial.WGS84Point((0.0, 0.0)),
'Expected Neomodel 2d geographical point when inflating 2d geographical neo4j point'),
(neo4j.v1.spatial.WGS84Point((0.0, 0.0, 0.0)),
'Expected Neomodel 3d geographical point inflating 3d geographical neo4j point')]
# Run the above tests
for a_value in values_from_db:
expected_point = neomodel.contrib.spatial_properties.NeomodelPoint(tuple(a_value[0]),
crs=neomodel.contrib.spatial_properties.SRID_TO_CRS[a_value[0].srid])
inflated_point = neomodel.contrib.spatial_properties.PointProperty(
crs=neomodel.contrib.spatial_properties.SRID_TO_CRS[a_value[0].srid]).inflate(a_value[0])
basic_type_assertions(expected_point, inflated_point, '{}, received {}'.format(a_value[1], inflated_point))