1
1
import redis
2
2
from unittest import TestCase
3
- from rejson import Client , Path
3
+ from rejson import ReJSONClient , Path
4
4
5
5
class ReJSONTestCase (TestCase ):
6
-
7
6
def testJSONSetGetDelShouldSucceed (self ):
8
7
"Test basic JSONSet/Get/Del"
9
- rj = Client ()
8
+ rj = ReJSONClient ()
10
9
rj .flushdb ()
11
10
12
11
self .assertTrue (rj .JSONSet ('foo' , Path .rootPath (), 'bar' ))
@@ -16,7 +15,7 @@ def testJSONSetGetDelShouldSucceed(self):
16
15
17
16
def testMGetShouldSucceed (self ):
18
17
"Test JSONMGet"
19
- rj = Client ()
18
+ rj = ReJSONClient ()
20
19
rj .flushdb ()
21
20
22
21
rj .JSONSet ('1' , Path .rootPath (), 1 )
@@ -27,15 +26,15 @@ def testMGetShouldSucceed(self):
27
26
28
27
def testTypeShouldSucceed (self ):
29
28
"Test JSONType"
30
- rj = Client ()
29
+ rj = ReJSONClient ()
31
30
rj .flushdb ()
32
31
33
32
rj .JSONSet ('1' , Path .rootPath (), 1 )
34
33
self .assertEqual ('integer' , rj .JSONType ('1' ))
35
34
36
35
def testNumIncrByShouldSucceed (self ):
37
36
"Test JSONNumIncrBy"
38
- rj = Client ()
37
+ rj = ReJSONClient ()
39
38
rj .flushdb ()
40
39
41
40
rj .JSONSet ('num' , Path .rootPath (), 1 )
@@ -45,7 +44,7 @@ def testNumIncrByShouldSucceed(self):
45
44
46
45
def testNumMultByShouldSucceed (self ):
47
46
"Test JSONNumIncrBy"
48
- rj = Client ()
47
+ rj = ReJSONClient ()
49
48
rj .flushdb ()
50
49
51
50
rj .JSONSet ('num' , Path .rootPath (), 1 )
@@ -55,7 +54,7 @@ def testNumMultByShouldSucceed(self):
55
54
56
55
def testStrAppendShouldSucceed (self ):
57
56
"Test JSONStrAppend"
58
- rj = Client ()
57
+ rj = ReJSONClient ()
59
58
rj .flushdb ()
60
59
61
60
rj .JSONSet ('str' , Path .rootPath (), 'foo' )
@@ -64,7 +63,7 @@ def testStrAppendShouldSucceed(self):
64
63
65
64
def testStrLenShouldSucceed (self ):
66
65
"Test JSONStrLen"
67
- rj = Client ()
66
+ rj = ReJSONClient ()
68
67
rj .flushdb ()
69
68
70
69
rj .JSONSet ('str' , Path .rootPath (), 'foo' )
@@ -74,15 +73,15 @@ def testStrLenShouldSucceed(self):
74
73
75
74
def testArrAppendShouldSucceed (self ):
76
75
"Test JSONSArrAppend"
77
- rj = Client ()
76
+ rj = ReJSONClient ()
78
77
rj .flushdb ()
79
78
80
79
rj .JSONSet ('arr' , Path .rootPath (), [1 ])
81
80
self .assertEqual (2 , rj .JSONArrAppend ('arr' , Path .rootPath (), 2 ))
82
81
83
82
def testArrIndexShouldSucceed (self ):
84
83
"Test JSONSArrIndex"
85
- rj = Client ()
84
+ rj = ReJSONClient ()
86
85
rj .flushdb ()
87
86
88
87
rj .JSONSet ('arr' , Path .rootPath (), [0 , 1 , 2 , 3 , 4 ])
@@ -91,7 +90,7 @@ def testArrIndexShouldSucceed(self):
91
90
92
91
def testArrInsertShouldSucceed (self ):
93
92
"Test JSONSArrInsert"
94
- rj = Client ()
93
+ rj = ReJSONClient ()
95
94
rj .flushdb ()
96
95
97
96
rj .JSONSet ('arr' , Path .rootPath (), [0 , 4 ])
@@ -100,15 +99,15 @@ def testArrInsertShouldSucceed(self):
100
99
101
100
def testArrLenShouldSucceed (self ):
102
101
"Test JSONSArrLen"
103
- rj = Client ()
102
+ rj = ReJSONClient ()
104
103
rj .flushdb ()
105
104
106
105
rj .JSONSet ('arr' , Path .rootPath (), [0 , 1 , 2 , 3 , 4 ])
107
106
self .assertEqual (5 , rj .JSONArrLen ('arr' , Path .rootPath ()))
108
107
109
108
def testArrPopShouldSucceed (self ):
110
109
"Test JSONSArrPop"
111
- rj = Client ()
110
+ rj = ReJSONClient ()
112
111
rj .flushdb ()
113
112
114
113
rj .JSONSet ('arr' , Path .rootPath (), [0 , 1 , 2 , 3 , 4 ])
@@ -120,7 +119,7 @@ def testArrPopShouldSucceed(self):
120
119
121
120
def testArrTrimShouldSucceed (self ):
122
121
"Test JSONSArrPop"
123
- rj = Client ()
122
+ rj = ReJSONClient ()
124
123
rj .flushdb ()
125
124
126
125
rj .JSONSet ('arr' , Path .rootPath (), [0 , 1 , 2 , 3 , 4 ])
@@ -129,7 +128,7 @@ def testArrTrimShouldSucceed(self):
129
128
130
129
def testObjKeysShouldSucceed (self ):
131
130
"Test JSONSObjKeys"
132
- rj = Client ()
131
+ rj = ReJSONClient ()
133
132
rj .flushdb ()
134
133
135
134
obj = { 'foo' : 'bar' , 'baz' : 'qaz' }
@@ -142,37 +141,40 @@ def testObjKeysShouldSucceed(self):
142
141
143
142
def testObjLenShouldSucceed (self ):
144
143
"Test JSONSObjLen"
145
- rj = Client ()
144
+ rj = ReJSONClient ()
146
145
rj .flushdb ()
147
146
148
147
obj = { 'foo' : 'bar' , 'baz' : 'qaz' }
149
148
rj .JSONSet ('obj' , Path .rootPath (), obj )
150
149
self .assertEqual (len (obj ), rj .JSONObjLen ('obj' , Path .rootPath ()))
151
-
150
+
152
151
def testUsageExampleShouldSucceed (self ):
153
152
"Test the usage example"
154
153
155
154
# Create a new rejson-py client
156
- rj = Client (host = 'localhost' , port = 6379 )
155
+ rj = ReJSONClient (host = 'localhost' , port = 6379 )
157
156
158
157
# Set the key `obj` to some object
159
- rj . JSONSet ( ' obj' , Path . rootPath (), {
158
+ obj = {
160
159
'answer' : 42 ,
161
160
'arr' : [None , True , 3.14 ],
162
161
'truth' : {
163
162
'coord' : 'out there'
164
163
}
165
- })
164
+ }
165
+ rj .JSONSet ('obj' , Path .rootPath (), obj )
166
166
167
167
# Get something
168
- question = 'Is there anybody... {}?' .format (
168
+ print 'Is there anybody... {}?' .format (
169
169
rj .JSONGet ('obj' , Path ('.truth.coord' ))
170
170
)
171
171
172
- # Delete something (or perhaps nothing)
172
+ # Delete something (or perhaps nothing), append something and pop it
173
173
rj .JSONDel ('obj' , Path ('.arr[0]' ))
174
+ rj .JSONArrAppend ('obj' , Path ('.arr' ), 'something' )
175
+ print '{} popped!' .format (rj .JSONArrPop ('obj' , Path ('.arr' )))
174
176
175
- # Update something
177
+ # Update something else
176
178
rj .JSONSet ('obj' , Path ('.answer' ), 2.17 )
177
179
178
180
if __name__ == '__main__' :
0 commit comments