Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
graphname = "tmpgraph7"
with open('/tmp/nodes.tmp', mode='w') as csv_file:
out = csv.writer(csv_file)
out.writerow(['str_col:STRING', 'num_col:INT'])
out.writerow([0, 0])
out.writerow([1, 1])
runner = CliRunner()
res = runner.invoke(bulk_insert, ['--nodes', '/tmp/nodes.tmp',
'--enforce-schema',
graphname], catch_exceptions=False)
self.assertEqual(res.exit_code, 0)
self.assertIn('2 nodes created', res.output)
graph = Graph(graphname, self.redis_con)
query_result = graph.query('MATCH (a) RETURN a.str_col, a.num_col ORDER BY a.num_col')
expected_result = [['0', 0],
['1', 1]]
# The graph should have the correct types for all properties
self.assertEqual(query_result.result_set, expected_result)
'--relations', visited_file,
'--max-token-count', 1,
graphname], catch_exceptions=False)
# The script should report 27 overall node creations and 48 edge creations.
self.assertEqual(res.exit_code, 0)
self.assertIn("27 nodes created", res.output)
self.assertIn("48 relations created", res.output)
# Validate creation count by label/type
self.assertIn(person_count + " nodes created with label 'Person'", res.output)
self.assertIn(country_count + " nodes created with label 'Country'", res.output)
self.assertIn(knows_count + " relations created for type 'KNOWS'", res.output)
self.assertIn(visited_count + " relations created for type 'VISITED'", res.output)
original_graph = Graph('social', self.redis_con)
new_graph = Graph(graphname, self.redis_con)
# Newly-created graph should be identical to graph created in single bulk command
original_result = original_graph.query('MATCH (p:Person) RETURN p, ID(p) ORDER BY p.name')
new_result = new_graph.query('MATCH (p:Person) RETURN p, ID(p) ORDER BY p.name')
self.assertEqual(original_result.result_set, new_result.result_set)
original_result = original_graph.query('MATCH (a)-[e:KNOWS]->(b) RETURN a.name, e, b.name ORDER BY e.relation, a.name')
new_result = new_graph.query('MATCH (a)-[e:KNOWS]->(b) RETURN a.name, e, b.name ORDER BY e.relation, a.name')
self.assertEqual(original_result.result_set, new_result.result_set)
graphname = "null_graph"
with open('/tmp/nodes.tmp', mode='w') as csv_file:
out = csv.writer(csv_file)
out.writerow(['str_col', 'mixed_col'])
out.writerow(['str1', True])
out.writerow(['str2', None])
runner = CliRunner()
res = runner.invoke(bulk_insert, ['--nodes', '/tmp/nodes.tmp',
graphname], catch_exceptions=False)
self.assertEqual(res.exit_code, 0)
self.assertIn('2 nodes created', res.output)
graph = Graph(graphname, self.redis_con)
query_result = graph.query('MATCH (a) RETURN a ORDER BY a.str_col')
# Only the first node should only have the 'mixed_col' property
node_1 = {'str_col': 'str1', 'mixed_col': True}
node_2 = {'str_col': 'str2'}
self.assertEqual(query_result.result_set[0][0].properties, node_1)
self.assertEqual(query_result.result_set[1][0].properties, node_2)
'--max-token-count', 1,
graphname], catch_exceptions=False)
# The script should report 27 overall node creations and 48 edge creations.
self.assertEqual(res.exit_code, 0)
self.assertIn("27 nodes created", res.output)
self.assertIn("48 relations created", res.output)
# Validate creation count by label/type
self.assertIn(person_count + " nodes created with label 'Person'", res.output)
self.assertIn(country_count + " nodes created with label 'Country'", res.output)
self.assertIn(knows_count + " relations created for type 'KNOWS'", res.output)
self.assertIn(visited_count + " relations created for type 'VISITED'", res.output)
original_graph = Graph('social', self.redis_con)
new_graph = Graph(graphname, self.redis_con)
# Newly-created graph should be identical to graph created in single bulk command
original_result = original_graph.query('MATCH (p:Person) RETURN p, ID(p) ORDER BY p.name')
new_result = new_graph.query('MATCH (p:Person) RETURN p, ID(p) ORDER BY p.name')
self.assertEqual(original_result.result_set, new_result.result_set)
original_result = original_graph.query('MATCH (a)-[e:KNOWS]->(b) RETURN a.name, e, b.name ORDER BY e.relation, a.name')
new_result = new_graph.query('MATCH (a)-[e:KNOWS]->(b) RETURN a.name, e, b.name ORDER BY e.relation, a.name')
self.assertEqual(original_result.result_set, new_result.result_set)
out = csv.writer(csv_file)
out.writerow(["src", "dest", "prop"])
out.writerow([0.2, 5, True])
out.writerow([5, 7, 3.5])
out.writerow([7, 0.2, 'edge_prop'])
runner = CliRunner()
res = runner.invoke(bulk_insert, ['--nodes', '/tmp/nodes.tmp',
'--relations', '/tmp/relations.tmp',
graphname], catch_exceptions=False)
self.assertEqual(res.exit_code, 0)
self.assertIn('3 nodes created', res.output)
self.assertIn('3 relations created', res.output)
graph = Graph(graphname, self.redis_con)
query_result = graph.query('MATCH (a)-[e]->() RETURN a.numeric, a.mixed, a.bool, e.prop ORDER BY a.numeric, e.prop')
expected_result = [[0.2, 'string_prop_1', True, True],
[5, 'notnull', False, 3.5],
[7, 100, False, 'edge_prop']]
# The graph should have the correct types for all properties
self.assertEqual(query_result.result_set, expected_result)
'--relations', visited_file,
graphname])
# The script should report 27 overall node creations and 48 edge creations.
self.assertEqual(res.exit_code, 0)
self.assertIn("27 nodes created", res.output)
self.assertIn("48 relations created", res.output)
# Validate creation count by label/type
self.assertIn(person_count + " nodes created with label 'Person'", res.output)
self.assertIn(country_count + " nodes created with label 'Country'", res.output)
self.assertIn(knows_count + " relations created for type 'KNOWS'", res.output)
self.assertIn(visited_count + " relations created for type 'VISITED'", res.output)
# Open the constructed graph.
graph = Graph('social', self.redis_con)
query_result = graph.query("MATCH (p:Person) RETURN p.name, p.age, p.gender, p.status ORDER BY p.name")
# Verify that the Person label exists, has the correct attributes, and is properly populated.
expected_result = [['Ailon Velger', 32, 'male', 'married'],
['Alon Fital', 32, 'male', 'married'],
['Boaz Arad', 31, 'male', 'married'],
['Gal Derriere', 26, 'male', 'single'],
['Jane Chernomorin', 31, 'female', 'married'],
['Lucy Yanfital', 30, 'female', 'married'],
['Mor Yesharim', 31, 'female', 'married'],
['Noam Nativ', 34, 'male', 'single'],
['Omri Traub', 33, 'male', 'single'],
['Ori Laslo', 32, 'male', 'married'],
['Roi Lipman', 32, 'male', 'married'],
['Shelly Laslo Rooz', 31, 'female', 'married'],
['Tal Doron', 32, 'male', 'single'],
['Valerie Abigail Arad', 31, 'female', 'married']]
out.writerow([2, 'zerstören'])
out.writerow([3, 'français'])
out.writerow([4, 'américaine'])
out.writerow([5, 'épais'])
out.writerow([6, '中國的'])
out.writerow([7, '英語'])
out.writerow([8, '美國人'])
runner = CliRunner()
res = runner.invoke(bulk_insert, ['--nodes', '/tmp/nodes.tmp',
graphname], catch_exceptions=False)
assert res.exit_code == 0
assert '9 nodes created' in res.output
graph = Graph(graphname, self.redis_con)
# The non-ASCII property string must be escaped backticks to parse correctly
query_result = graph.query("""MATCH (a) RETURN a.`utf8_str_ß` ORDER BY a.id""")
expected_strs = [['Straße'],
['auslösen'],
['zerstören'],
['français'],
['américaine'],
['épais'],
['中國的'],
['英語'],
['美國人']]
for i, j in zip(query_result.result_set, expected_strs):
self.assertEqual(repr(i), repr(j))
objects_properties["property"] = str(properties)
obj_properties_classlist = get_property(
obj1["supportedProperty"])
objects_properties["class_property"] = str(
obj_properties_classlist)
print(objects_node.alias + remove_vocab(obj))
obj_alias = str(objects_node.alias + remove_vocab(obj)).lower()
obj_node = Node(
label="id",
alias=obj_alias,
properties=objects_properties)
redis_graph.add_node(obj_node)
print("commiting objects_property", obj_node)
redis_graph.commit()
print("property node", obj_node)
edge = Edge(objects_node, "has" + remove_vocab(obj), obj_node)
redis_graph.add_edge(edge)
print("commiting objects_property edge", obj_node)
redis_graph.commit()
print("property node", obj_node)
connect_nodes(url_node, "has" +
str(objects_node.alias +
remove_vocab(obj)), obj_node)
if obj_properties_classlist:
return objects_property(
obj_node, obj_properties_classlist, url_node)
else:
return None
# print (obj_node,new_list)
def connect_nodes(source_node, predicate, dest_node):
edge = Edge(source_node, predicate, dest_node)
redis_graph.add_edge(edge)
print("add edge commit", predicate)
redis_graph.commit()
print("edge", edge)
alias="collection_endpoint",
properties=collection_endpoint)
redis_graph.add_node(collection_node)
edge = Edge(url_node, "has_collection_endpoint", collection_node)
redis_graph.add_edge(edge)
# redis_graph.commit()
print("collection endpoint node ", collection_node)
endpointCollection(collection_node, url_node)
# redis_graph.commit()
if classes == 1:
classes_node = Node(
label="id",
alias="classes_endpoint",
properties=classes_endpoint)
redis_graph.add_node(classes_node)
edge = Edge(url_node, "has_classes_endpoint", classes_node)
redis_graph.add_edge(edge)
print("classes endpoint node", classes_node)
endpointclasses(classes_node, url_node)
# redis_graph.commit()