@@ -19,7 +19,7 @@ class testResp3():
19
19
def __init__ (self ):
20
20
self .env = Env (protocol = 3 )
21
21
22
- def test_resp3_set_get (self ):
22
+ def test_resp3_set_get_json_format (self ):
23
23
r = self .env
24
24
r .skipOnVersionSmaller ('7.0' )
25
25
@@ -29,19 +29,19 @@ def test_resp3_set_get(self):
29
29
r .assertOk (r .execute_command ('JSON.SET' , 'test_resp3' , '$' , '{"a1":{"b":{"c":true,"d":null}},"a2":{"b":{"c":2}}}' ))
30
30
31
31
# Test JSON.GET RESP3
32
- r .assertEqual (r .execute_command ('JSON.GET' , 'test_resp3' , '$' ), [['{"a1":{"b":{"c":true,"d":null}},"a2":{"b":{"c":2}}}' ]])
33
- r .assertEqual (r .execute_command ('JSON.GET' , 'test_resp3' , '$..b' ), [['{"c":true,"d":null}' , '{"c":2}' ]])
34
- r .assertEqual (r .execute_command ('JSON.GET' , 'test_resp3' , '$.a1' , '$.a2' ), [['{"b":{"c":true,"d":null}}' ], ['{"b":{"c":2}}' ]])
35
- r .assertEqual (r .execute_command ('JSON.GET' , 'test_resp3' , '$.a1' , '$.a3' , '$.a2' ), [['{"b":{"c":true,"d":null}}' ], [], ['{"b":{"c":2}}' ]])
36
- r .assertEqual (r .execute_command ('JSON.GET' , 'test_resp3' , '$.a3' ), [[]])
32
+ r .assertEqual (r .execute_command ('JSON.GET' , 'test_resp3' , 'FORMAT' , 'JSON' , ' $' ), [['{"a1":{"b":{"c":true,"d":null}},"a2":{"b":{"c":2}}}' ]])
33
+ r .assertEqual (r .execute_command ('JSON.GET' , 'test_resp3' , 'FORMAT' , 'JSON' , ' $..b' ), [['{"c":true,"d":null}' , '{"c":2}' ]])
34
+ r .assertEqual (r .execute_command ('JSON.GET' , 'test_resp3' , 'FORMAT' , 'JSON' , ' $.a1' , '$.a2' ), [['{"b":{"c":true,"d":null}}' ], ['{"b":{"c":2}}' ]])
35
+ r .assertEqual (r .execute_command ('JSON.GET' , 'test_resp3' , 'FORMAT' , 'JSON' , ' $.a1' , '$.a3' , '$.a2' ), [['{"b":{"c":true,"d":null}}' ], [], ['{"b":{"c":2}}' ]])
36
+ r .assertEqual (r .execute_command ('JSON.GET' , 'test_resp3' , 'FORMAT' , 'JSON' , ' $.a3' ), [[]])
37
37
38
38
# TEST JSON.GET with none existent key
39
39
r .assertEqual (r .execute_command ('JSON.GET' , 'test_no_such_key' , '$.a3' ), None )
40
40
41
41
# TEST JSON.GET with not a JSON key
42
42
r .expect ('JSON.GET' , 'test_not_JSON' , '$.a3' ).raiseError ()
43
43
44
- def test_resp3_set_get_expand (self ):
44
+ def test_resp3_set_get_expand_format (self ):
45
45
r = self .env
46
46
r .skipOnVersionSmaller ('7.0' )
47
47
@@ -57,13 +57,44 @@ def test_resp3_set_get_expand(self):
57
57
r .assertEqual (r .execute_command ('JSON.GET' , 'test_resp3' , 'FORMAT' , 'EXPAND' ,'$.a1' , '$.a3' , '$.a2' ), [[{'b' : {'c' : True , 'd' : None }}], [], [{'b' : {'c' : 2 , 'e' : [1 , True , {'f' : None }]}}]])
58
58
r .assertEqual (r .execute_command ('JSON.GET' , 'test_resp3' , 'FORMAT' , 'EXPAND' ,'$.a3' ), [[]])
59
59
60
+ # Test JSON.GET RESP3 with default format (EXPAND)
61
+ r .assertEqual (r .execute_command ('JSON.GET' , 'test_resp3' , '$' ), [[{'a1' : {'b' : {'c' : True , 'd' : None }}, 'a2' : {'b' : {'e' : [1 , True , {'f' : None }], 'c' : 2 }}}]])
62
+ r .assertEqual (r .execute_command ('JSON.GET' , 'test_resp3' ,'$..b' ), [[{'d' : None , 'c' : True }, {'c' : 2 , 'e' : [1 , True , {'f' : None }]}]])
63
+ r .assertEqual (r .execute_command ('JSON.GET' , 'test_resp3' ,'$.a1' , '$.a2' ), [[{'b' : {'d' : None , 'c' : True }}], [{'b' : {'e' : [1 , True , {'f' : None }], 'c' : 2 }}]])
64
+ r .assertEqual (r .execute_command ('JSON.GET' , 'test_resp3' ,'$.a1' , '$.a3' , '$.a2' ), [[{'b' : {'c' : True , 'd' : None }}], [], [{'b' : {'c' : 2 , 'e' : [1 , True , {'f' : None }]}}]])
65
+ r .assertEqual (r .execute_command ('JSON.GET' , 'test_resp3' ,'$.a3' ), [[]])
66
+
60
67
# TEST JSON.GET with none existent key
61
68
r .assertEqual (r .execute_command ('JSON.GET' , 'test_no_such_key' , 'FORMAT' , 'EXPAND' ,'$.a3' ), None )
62
69
63
70
# TEST JSON.GET with not a JSON key
64
71
r .expect ('JSON.GET' , 'test_not_JSON' , 'FORMAT' , 'EXPAND' ,'$.a3' ).raiseError ()
65
72
66
73
74
+ def test_resp3_set_get_string_format (self ):
75
+ r = self .env
76
+ r .skipOnVersionSmaller ('7.0' )
77
+
78
+ r .assertTrue (r .execute_command ('SET' , 'test_not_JSON' , 'test_not_JSON' ))
79
+
80
+ # Test JSON.SET RESP3
81
+ r .assertOk (r .execute_command ('JSON.SET' , 'test_resp3' , '$' , '{"a1":{"b":{"c":true,"d":null}},"a2":{"b":{"c":2}}}' ))
82
+
83
+ # Test JSON.GET RESP3
84
+ r .assertEqual (r .execute_command ('JSON.GET' , 'test_resp3' , 'FORMAT' , 'STRING' , '$' ), '[{"a1":{"b":{"c":true,"d":null}},"a2":{"b":{"c":2}}}]' )
85
+ r .assertEqual (r .execute_command ('JSON.GET' , 'test_resp3' , 'FORMAT' , 'STRING' , '$..b' ), '[{"c":true,"d":null},{"c":2}]' )
86
+ r .assertEqual (json .loads (r .execute_command ('JSON.GET' , 'test_resp3' , 'FORMAT' , 'STRING' , '$.a1' , '$.a2' )), {"$.a2" :[{"b" :{"c" :2 }}],"$.a1" :[{"b" :{"c" :True ,"d" :None }}]})
87
+ r .assertEqual (json .loads (r .execute_command ('JSON.GET' , 'test_resp3' , 'FORMAT' , 'STRING' , '.a1' , '$.a2' )), {"$.a2" :[{"b" :{"c" :2 }}],".a1" :[{"b" :{"c" :True ,"d" :None }}]})
88
+ r .assertEqual (json .loads (r .execute_command ('JSON.GET' , 'test_resp3' , 'FORMAT' , 'STRING' , '$.a1' , '$.a3' , '$.a2' )), {"$.a3" :[],"$.a2" :[{"b" :{"c" :2 }}],"$.a1" :[{"b" :{"c" :True ,"d" :None }}]})
89
+ r .assertEqual (r .execute_command ('JSON.GET' , 'test_resp3' , 'FORMAT' , 'STRING' , '$.a3' ), '[]' )
90
+
91
+ # TEST JSON.GET with none existent key
92
+ r .assertEqual (r .execute_command ('JSON.GET' , 'test_no_such_key' , '$.a3' ), None )
93
+
94
+ # TEST JSON.GET with not a JSON key
95
+ r .expect ('JSON.GET' , 'test_not_JSON' , '$.a3' ).raiseError ()
96
+
97
+
67
98
# Test JSON.DEL RESP3
68
99
def test_resp_json_del (self ):
69
100
r = self .env
0 commit comments