11import redis
22from unittest import TestCase
3- from rejson import Client , Path
3+ from rejson import ReJSONClient , Path
44
55class ReJSONTestCase (TestCase ):
6-
76 def testJSONSetGetDelShouldSucceed (self ):
87 "Test basic JSONSet/Get/Del"
9- rj = Client ()
8+ rj = ReJSONClient ()
109 rj .flushdb ()
1110
1211 self .assertTrue (rj .JSONSet ('foo' , Path .rootPath (), 'bar' ))
@@ -16,7 +15,7 @@ def testJSONSetGetDelShouldSucceed(self):
1615
1716 def testMGetShouldSucceed (self ):
1817 "Test JSONMGet"
19- rj = Client ()
18+ rj = ReJSONClient ()
2019 rj .flushdb ()
2120
2221 rj .JSONSet ('1' , Path .rootPath (), 1 )
@@ -27,15 +26,15 @@ def testMGetShouldSucceed(self):
2726
2827 def testTypeShouldSucceed (self ):
2928 "Test JSONType"
30- rj = Client ()
29+ rj = ReJSONClient ()
3130 rj .flushdb ()
3231
3332 rj .JSONSet ('1' , Path .rootPath (), 1 )
3433 self .assertEqual ('integer' , rj .JSONType ('1' ))
3534
3635 def testNumIncrByShouldSucceed (self ):
3736 "Test JSONNumIncrBy"
38- rj = Client ()
37+ rj = ReJSONClient ()
3938 rj .flushdb ()
4039
4140 rj .JSONSet ('num' , Path .rootPath (), 1 )
@@ -45,7 +44,7 @@ def testNumIncrByShouldSucceed(self):
4544
4645 def testNumMultByShouldSucceed (self ):
4746 "Test JSONNumIncrBy"
48- rj = Client ()
47+ rj = ReJSONClient ()
4948 rj .flushdb ()
5049
5150 rj .JSONSet ('num' , Path .rootPath (), 1 )
@@ -55,7 +54,7 @@ def testNumMultByShouldSucceed(self):
5554
5655 def testStrAppendShouldSucceed (self ):
5756 "Test JSONStrAppend"
58- rj = Client ()
57+ rj = ReJSONClient ()
5958 rj .flushdb ()
6059
6160 rj .JSONSet ('str' , Path .rootPath (), 'foo' )
@@ -64,7 +63,7 @@ def testStrAppendShouldSucceed(self):
6463
6564 def testStrLenShouldSucceed (self ):
6665 "Test JSONStrLen"
67- rj = Client ()
66+ rj = ReJSONClient ()
6867 rj .flushdb ()
6968
7069 rj .JSONSet ('str' , Path .rootPath (), 'foo' )
@@ -74,15 +73,15 @@ def testStrLenShouldSucceed(self):
7473
7574 def testArrAppendShouldSucceed (self ):
7675 "Test JSONSArrAppend"
77- rj = Client ()
76+ rj = ReJSONClient ()
7877 rj .flushdb ()
7978
8079 rj .JSONSet ('arr' , Path .rootPath (), [1 ])
8180 self .assertEqual (2 , rj .JSONArrAppend ('arr' , Path .rootPath (), 2 ))
8281
8382 def testArrIndexShouldSucceed (self ):
8483 "Test JSONSArrIndex"
85- rj = Client ()
84+ rj = ReJSONClient ()
8685 rj .flushdb ()
8786
8887 rj .JSONSet ('arr' , Path .rootPath (), [0 , 1 , 2 , 3 , 4 ])
@@ -91,7 +90,7 @@ def testArrIndexShouldSucceed(self):
9190
9291 def testArrInsertShouldSucceed (self ):
9392 "Test JSONSArrInsert"
94- rj = Client ()
93+ rj = ReJSONClient ()
9594 rj .flushdb ()
9695
9796 rj .JSONSet ('arr' , Path .rootPath (), [0 , 4 ])
@@ -100,15 +99,15 @@ def testArrInsertShouldSucceed(self):
10099
101100 def testArrLenShouldSucceed (self ):
102101 "Test JSONSArrLen"
103- rj = Client ()
102+ rj = ReJSONClient ()
104103 rj .flushdb ()
105104
106105 rj .JSONSet ('arr' , Path .rootPath (), [0 , 1 , 2 , 3 , 4 ])
107106 self .assertEqual (5 , rj .JSONArrLen ('arr' , Path .rootPath ()))
108107
109108 def testArrPopShouldSucceed (self ):
110109 "Test JSONSArrPop"
111- rj = Client ()
110+ rj = ReJSONClient ()
112111 rj .flushdb ()
113112
114113 rj .JSONSet ('arr' , Path .rootPath (), [0 , 1 , 2 , 3 , 4 ])
@@ -120,7 +119,7 @@ def testArrPopShouldSucceed(self):
120119
121120 def testArrTrimShouldSucceed (self ):
122121 "Test JSONSArrPop"
123- rj = Client ()
122+ rj = ReJSONClient ()
124123 rj .flushdb ()
125124
126125 rj .JSONSet ('arr' , Path .rootPath (), [0 , 1 , 2 , 3 , 4 ])
@@ -129,7 +128,7 @@ def testArrTrimShouldSucceed(self):
129128
130129 def testObjKeysShouldSucceed (self ):
131130 "Test JSONSObjKeys"
132- rj = Client ()
131+ rj = ReJSONClient ()
133132 rj .flushdb ()
134133
135134 obj = { 'foo' : 'bar' , 'baz' : 'qaz' }
@@ -142,37 +141,40 @@ def testObjKeysShouldSucceed(self):
142141
143142 def testObjLenShouldSucceed (self ):
144143 "Test JSONSObjLen"
145- rj = Client ()
144+ rj = ReJSONClient ()
146145 rj .flushdb ()
147146
148147 obj = { 'foo' : 'bar' , 'baz' : 'qaz' }
149148 rj .JSONSet ('obj' , Path .rootPath (), obj )
150149 self .assertEqual (len (obj ), rj .JSONObjLen ('obj' , Path .rootPath ()))
151-
150+
152151 def testUsageExampleShouldSucceed (self ):
153152 "Test the usage example"
154153
155154 # Create a new rejson-py client
156- rj = Client (host = 'localhost' , port = 6379 )
155+ rj = ReJSONClient (host = 'localhost' , port = 6379 )
157156
158157 # Set the key `obj` to some object
159- rj . JSONSet ( ' obj' , Path . rootPath (), {
158+ obj = {
160159 'answer' : 42 ,
161160 'arr' : [None , True , 3.14 ],
162161 'truth' : {
163162 'coord' : 'out there'
164163 }
165- })
164+ }
165+ rj .JSONSet ('obj' , Path .rootPath (), obj )
166166
167167 # Get something
168- question = 'Is there anybody... {}?' .format (
168+ print 'Is there anybody... {}?' .format (
169169 rj .JSONGet ('obj' , Path ('.truth.coord' ))
170170 )
171171
172- # Delete something (or perhaps nothing)
172+ # Delete something (or perhaps nothing), append something and pop it
173173 rj .JSONDel ('obj' , Path ('.arr[0]' ))
174+ rj .JSONArrAppend ('obj' , Path ('.arr' ), 'something' )
175+ print '{} popped!' .format (rj .JSONArrPop ('obj' , Path ('.arr' )))
174176
175- # Update something
177+ # Update something else
176178 rj .JSONSet ('obj' , Path ('.answer' ), 2.17 )
177179
178180if __name__ == '__main__' :
0 commit comments