diff --git a/redisgraph/graph.py b/redisgraph/graph.py index 7653645..0be1cc4 100644 --- a/redisgraph/graph.py +++ b/redisgraph/graph.py @@ -10,12 +10,16 @@ class Graph: Graph, collection of nodes and edges. """ - def __init__(self, name, redis_con): + def __init__(self, name, redis_con=None, host='localhost', port=6379, password=None): """ Create a new graph. """ self.name = name # Graph key - self.redis_con = redis_con + if redis_con is not None: + self.redis_con = redis_con + else: + self.redis_con = redis.Redis(host, port, password=password) + self.nodes = {} self.edges = [] self._labels = [] # List of node labels. diff --git a/tests/functional/test_all.py b/tests/functional/test_all.py index 865ea9c..13655c6 100644 --- a/tests/functional/test_all.py +++ b/tests/functional/test_all.py @@ -46,6 +46,19 @@ def test_graph_creation(self): # All done, remove graph. redis_graph.delete() + def test_graph_connection(self): + connections = len(self.r.client_list()) + redis_graph = Graph('social', self.r) + del redis_graph + self.assertTrue(self.r.ping()) + self.assertTrue(len(self.r.client_list()) == connections) + + new_graph = Graph('social-new') + self.assertTrue(new_graph.redis_con.ping()) + self.assertTrue(len(self.r.client_list()) == connections + 1) + del new_graph + self.assertTrue(len(self.r.client_list()) == connections) + def test_array_functions(self): redis_graph = Graph('social', self.r)