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))
def main(self,new_url,api_doc,check_commit):
redis_connection = RedisProxy()
redis_con = redis_connection.get_connection()
self.url = new_url
self.redis_graph = Graph("apidoc", redis_con)
print("loading... of graph")
self.get_endpoints(api_doc, redis_con)
if check_commit:
print("commiting")
self.redis_graph.commit()
# creating whole the graph in redis
print("done!!!!")
# uncomment below 2 lines for getting nodes for whole graph
elif classes then =>members(get))
"""
import redis
from redisgraph import Graph, Node, Edge
import urllib
import json
import re
from re import compile as regex
from httplib2 import Http
redis_con = redis.Redis(host='localhost', port=6379)
redis_graph = Graph("apidoc", redis_con)
"""
getting the apidoc
"""
class _MemCache(dict):
def __nonzero__(self):
# even if empty, a _MemCache is True
return True
def set(self, key, value):
self[key] = value
def delete(self, key):
if key in self:
def __init__(self, redis_proxy: RedisProxy, graph_name="apigraph") -> None:
"""Initialize Graph Utils module
:param redis_proxy: RedisProxy object created from redis_proxy module
:param graph_name: Graph Key name to be created in Redis
:return: None
"""
self.redis_proxy = redis_proxy
self.redis_connection = redis_proxy.get_connection()
self.graph_name = graph_name
self.redis_graph = Graph(graph_name, self.redis_connection)