-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_rexster.py
More file actions
159 lines (135 loc) · 5.92 KB
/
test_rexster.py
File metadata and controls
159 lines (135 loc) · 5.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/env python
#-*- coding:utf-8 -*-
##########################################################################
# This test has been performed with a default rexster-0.4.1 distribution #
##########################################################################
import unittest
from rexster import *
HOST = 'http://localhost:8182'
GRAPH = 'tinkergraph'
class RequestServerTestSuite(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
def testServerInvalidConnection(self):
self.assertRaises(RexsterException,
RexsterServer,
'http://invalidurl')
def testServerValidConnection(self):
server = RexsterServer(HOST)
self.assertIsInstance(server, RexsterServer)
def testGetServerName(self):
server = RexsterServer(HOST)
self.assertEqual(server.name(), u'Rexster: A RESTful Graph Shell')
def testGetServerGraphs(self):
server = RexsterServer(HOST)
sampleGraphs = [u'tinkergraph', u'gratefulgraph',
u'tinkergraph-readonly',
u'sailgraph', u'emptygraph']
self.assertEqual(server.graphs(), sampleGraphs)
def testAddRemoveVertex(self):
server = RexsterServer(HOST)
graph = RexsterGraph(server, GRAPH)
vertex = graph.addVertex()
self.assertIsInstance(vertex, Vertex)
_id = vertex.getId()
graph.removeVertex(vertex)
self.assertIsNone(graph.getVertex(_id))
def testVertexMethods(self):
server = RexsterServer('http://localhost:8182')
graph = RexsterGraph(server, GRAPH)
vertex = graph.getVertex(1)
self.assertIsInstance(vertex, Vertex)
self.assertEqual(vertex.getId(), '1')
edge = list(vertex.getBothEdges())[0]
self.assertIsInstance(edge, Edge)
edge = list(vertex.getOutEdges())[0]
self.assertIsInstance(edge, Edge)
edges = list(vertex.getInEdges())
self.assertEqual(edges, [])
def testElementProperties(self):
server = RexsterServer('http://localhost:8182')
graph = RexsterGraph(server, GRAPH)
vertex = graph.getVertex(1)
defaultProperties = ['age', '_type', '_id', 'name']
self.assertEqual(vertex.getPropertyKeys(), defaultProperties)
self.assertEqual(vertex.getProperty('name'), 'marko')
vertex.setProperty('name', 'pablito')
self.assertEqual(vertex.getProperty('name'), 'pablito')
vertex.removeProperty('name')
self.assertNotIn('name', vertex.getPropertyKeys())
vertex.setProperty('name', 'marko')
self.assertEqual(vertex.getProperty('name'), 'marko')
def testEdgeMethods(self):
server = RexsterServer('http://localhost:8182')
graph = RexsterGraph(server, GRAPH)
edge = graph.getEdge(7)
outVertex = edge.getOutVertex()
self.assertIsInstance(outVertex, Vertex)
self.assertEqual(outVertex.getId(), '1')
inVertex = edge.getInVertex()
self.assertIsInstance(inVertex, Vertex)
self.assertEqual(inVertex.getId(), '2')
self.assertEqual(edge.getLabel(), 'knows')
def testAddRemoveEdges(self):
server = RexsterServer('http://localhost:8182')
graph = RexsterGraph(server, GRAPH)
v1 = graph.getVertex(1)
v2 = graph.getVertex(2)
newEdge = graph.addEdge(v1, v2, 'myLabel')
self.assertIsInstance(newEdge, Edge)
_id = newEdge.getId()
graph.removeEdge(newEdge)
self.assertIsNone(graph.getEdge(_id))
def testGetVertices(self):
server = RexsterServer('http://localhost:8182')
graph = RexsterGraph(server, GRAPH)
vertices = list(graph.getVertices())
vertex = vertices[0]
self.assertIsInstance(vertex, Vertex)
def testGetEdges(self):
server = RexsterServer('http://localhost:8182')
graph = RexsterGraph(server, GRAPH)
edges = list(graph.getEdges())
edge = edges[0]
self.assertIsInstance(edge, Edge)
def testAddRemoveManualIndex(self):
server = RexsterServer('http://localhost:8182')
graph = RexsterIndexableGraph(server, GRAPH)
index = graph.createManualIndex('myManualIndex', 'vertex')
self.assertIsInstance(index, Index)
index = graph.getIndex('myManualIndex', 'vertex')
self.assertIsInstance(index, Index)
graph.dropIndex('myManualIndex')
self.assertIsNone(graph.getIndex('myManualIndex', 'vertex'))
def testAddRemoveAutomaticIndex(self):
server = RexsterServer('http://localhost:8182')
graph = RexsterIndexableGraph(server, GRAPH)
keys = ['key1', 'key2']
index = graph.createAutomaticIndex('myAutoIndex', 'vertex', keys)
self.assertIsInstance(index, Index)
index = graph.getIndex('myAutoIndex', 'vertex')
self.assertIsInstance(index, Index)
autoKeys = index.getAutoIndexKeys()
#TODO self.assertIn('key1', autoKeys)
#TODO self.assertIn('key2', autoKeys)
graph.dropIndex('myAutoIndex')
self.assertIsNone(graph.getIndex('myAutoIndex', 'vertex'))
def testIndexing(self):
server = RexsterServer('http://localhost:8182')
graph = RexsterIndexableGraph(server, GRAPH)
index = graph.createManualIndex('myManualIndex', 'vertex')
vertex = graph.getVertex(1)
index.put('key1', 'value1', vertex)
self.assertEqual(index.count('key1', 'value1'), 1)
self.assertEqual(index.getIndexName(), 'myManualIndex')
self.assertEqual(index.getIndexClass(), 'vertex')
self.assertEqual(index.getIndexType(), 'manual')
vertex2 = list(index.get('key1', 'value1'))[0]
self.assertEqual(vertex.getId(), vertex2.getId())
index.remove('key1', 'value1', vertex)
self.assertEqual(index.count('key1', 'value1'), 0)
graph.dropIndex('myManualIndex')
if __name__ == "__main__":
unittest.main()