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