Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 149 lines (120 sloc) 4.911 kb
650e03d1 » espeed
2011-07-15 initial github push
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright 2011 James Thornton (http://jamesthornton.com)
4 # BSD License (see LICENSE for details)
5 #
6 import unittest
7
8 from bulbs.graph import Graph
9 from bulbs.element import Vertex
10 from bulbs import config
11
12 class VertexProxyTestCase(unittest.TestCase):
13
14 def setUp(self):
15 self.graph = Graph()
16
17 def test_init(self):
18 assert self.graph.resource.db_url == config.DATABASE_URL
19
20 def test_create(self):
21 james = self.graph.vertices.create({'name':'James'})
22 assert isinstance(james,Vertex)
23 assert type(james._id) == int
24 assert james._type == "vertex"
25 assert james.name == "James"
26
27 def test_update(self):
28 james = self.graph.vertices.create({'name':'James'})
29 james = self.graph.vertices.update(james._id, {'name':'James','age':'34'})
30 assert type(james._id) == int
31 assert james._type == "vertex"
32 assert james.name == "James"
33 assert james.age == '34'
34
35 def test_get(self):
36 james = self.graph.vertices.create({'name':'James'})
37 j2 = self.graph.vertices.get(james._id)
38 assert james == j2
39
40 def test_get_all(self):
41 vertices = self.graph.vertices.get_all()
42 vertices = list(vertices)
43 assert len(vertices) > 0
44
45 #def test_remove_property(self):
46 # query_time = self.graph.vertices.remove(self.james._id,'age')
47 # assert type(query_time) == float
48 # assert self.james.age is None
49
50 def test_delete_vertex(self):
51 james = self.graph.vertices.create({'name':'James'})
52 resp = self.graph.vertices.delete(james)
53 assert type(resp.query_time) == float
54 j2 = self.graph.vertices.get(james._id)
55 assert j2 == None
56
57
58 class VertexTestCase(unittest.TestCase):
59
60 def setUp(self):
61 self.graph = Graph()
62 self.james = self.graph.vertices.create({'name':'James'})
63 self.julie = self.graph.vertices.create({'name':'Julie'})
64 assert isinstance(self.james,Vertex)
65 self.graph.edges.create(self.james,"test",self.julie)
66 self.graph.edges.create(self.julie,"test",self.james)
67
68 def test_init(self):
69 assert type(self.james._id) == int
70 assert self.james._type == "vertex"
71 assert self.james.name == "James"
72
73 def test_get_out_edges(self):
74 edges = self.james.outE()
75 edges = list(edges)
76 assert len(edges) == 1
77
78 def test_get_in_edges(self):
79 edges = self.james.inE()
80 edges = list(edges)
81 assert len(edges) == 1
82
83 def test_get_both_edges(self):
84 edges = self.james.bothE()
85 edges = list(edges)
86 assert len(edges) == 2
87
88 def test_get_both_labeled_edges(self):
89 edges = self.james.bothE("test")
90 edges = list(edges)
91 assert len(edges) == 2
92
93 class EdgeProxyTestCase(unittest.TestCase):
94
95 def setUp(self):
96 self.graph = Graph()
97 self.james = self.graph.vertices.create({'name':'James'})
98 self.julie = self.graph.vertices.create({'name':'Julie'})
99
100 def test_create(self):
101 edge = self.graph.edges.create(self.james,"test",self.julie)
102 assert edge._outV == self.james._id
103 assert edge._label == "test"
104 assert edge._inV == self.julie._id
105
106 def test_update(self):
107 e1 = self.graph.edges.create(self.james,"test",self.julie,{'time':'today'})
108 assert e1.time == 'today'
109 e2 = self.graph.edges.update(e1._id,{'time':'tomorrow'})
110 assert e1._id == e2._id
111 assert e1._inV == e2._inV
112 assert e1._label == e2._label
113 assert e1._outV == e2._outV
114 assert e2.time == 'tomorrow'
115
116 def test_get(self):
117 e1 = self.graph.edges.create(self.james,"test",self.julie,{'time':'today'})
118 e2 = self.graph.edges.get(e1._id)
119 assert e1 == e2
120
121 def test_get_all(self):
122 edges = self.graph.edges.get_all()
123 edges = list(edges)
124 assert type(edges) == list
125
126 #def test_remove_property(self):
127 # e1 = self.graph.edges.create(self.james,"test",self.julie,{'time':'today'})
128 # query_time = self.graph.edges.remove(e1._id,{'time'})
129 # assert type(query_time) == float
130 # assert e1.time is None
131
132 def test_delete_edge(self):
133 e1 = self.graph.edges.create(self.james,"test",self.julie)
134 resp = self.graph.edges.delete(e1)
135 assert type(resp.query_time) == float
136 e2 = self.graph.edges.get(e1._id)
137 assert e2 == None
138
139 def suite():
140 suite = unittest.TestSuite()
141 suite.addTest(unittest.makeSuite(VertexProxyTestCase))
142 suite.addTest(unittest.makeSuite(VertexTestCase))
143 suite.addTest(unittest.makeSuite(EdgeProxyTestCase))
144 # NOTE: there are no tests for the Edge because it doesn't have methods.
145
146 return suite
147
148 if __name__ == '__main__':
149 unittest.main(defaultTest='suite')
150
Something went wrong with that request. Please try again.