5
5
from typing import (Any , Dict , List , Tuple , )
6
6
7
7
import pytest
8
- import redis
9
- from redis .commands .json .path import Path
10
8
11
9
json_tests = pytest .importorskip ("jsonpath_ng" )
12
10
@@ -62,30 +60,6 @@ def json_data() -> Dict[str, Any]:
62
60
}
63
61
64
62
65
- @pytest .mark .xfail
66
- def test_debug (r : redis .Redis ):
67
- r .json ().set ("str" , Path .root_path (), "foo" )
68
- assert 24 == r .json ().debug ("MEMORY" , "str" , Path .root_path ())
69
- assert 24 == r .json ().debug ("MEMORY" , "str" )
70
-
71
- # technically help is valid
72
- assert isinstance (r .json ().debug ("HELP" ), list )
73
-
74
-
75
- @pytest .mark .xfail
76
- def test_resp (r : redis .Redis ):
77
- obj = {"foo" : "bar" , "baz" : 1 , "qaz" : True , }
78
- r .json ().set ("obj" , Path .root_path (), obj , )
79
-
80
- assert "bar" == r .json ().resp ("obj" , Path ("foo" ), )
81
- assert 1 == r .json ().resp ("obj" , Path ("baz" ), )
82
- assert r .json ().resp (
83
- "obj" ,
84
- Path ("qaz" ),
85
- )
86
- assert isinstance (r .json ().resp ("obj" ), list )
87
-
88
-
89
63
def load_types_data (nested_key_name : str ) -> Tuple [Dict [str , Any ], List [bytes ]]:
90
64
"""Generate a structure with sample of all types
91
65
"""
@@ -104,129 +78,3 @@ def load_types_data(nested_key_name: str) -> Tuple[Dict[str, Any], List[bytes]]:
104
78
jdata [f"nested_{ k } " ] = {nested_key_name : v }
105
79
106
80
return jdata , [k .encode () for k in type_samples .keys ()]
107
-
108
-
109
- @pytest .mark .xfail
110
- def test_debug_dollar (r : redis .Redis ):
111
- jdata , jtypes = load_types_data ("a" )
112
-
113
- r .json ().set ("doc1" , "$" , jdata )
114
-
115
- # Test multi
116
- assert r .json ().debug ("MEMORY" , "doc1" , "$..a" ) == [72 , 24 , 24 , 16 , 16 , 1 , 0 ]
117
-
118
- # Test single
119
- assert r .json ().debug ("MEMORY" , "doc1" , "$.nested2.a" ) == [24 ]
120
-
121
- # Test legacy
122
- assert r .json ().debug ("MEMORY" , "doc1" , "..a" ) == 72
123
-
124
- # Test missing path (defaults to root)
125
- assert r .json ().debug ("MEMORY" , "doc1" ) == 72
126
-
127
- # Test missing key
128
- assert r .json ().debug ("MEMORY" , "non_existing_doc" , "$..a" ) == []
129
-
130
-
131
- @pytest .mark .xfail
132
- def test_resp_dollar (r : redis .Redis , json_data : Dict [str , Any ]):
133
- r .json ().set ("doc1" , "$" , json_data )
134
-
135
- # Test multi
136
- res = r .json ().resp ("doc1" , "$..a" )
137
-
138
- assert res == [
139
- [
140
- "{" ,
141
- "A1_B1" ,
142
- 10 ,
143
- "A1_B2" ,
144
- "false" ,
145
- "A1_B3" ,
146
- [
147
- "{" ,
148
- "A1_B3_C1" ,
149
- None ,
150
- "A1_B3_C2" ,
151
- [
152
- "[" ,
153
- "A1_B3_C2_D1_1" ,
154
- "A1_B3_C2_D1_2" ,
155
- "-19.5" ,
156
- "A1_B3_C2_D1_4" ,
157
- "A1_B3_C2_D1_5" ,
158
- ["{" , "A1_B3_C2_D1_6_E1" , "true" ],
159
- ],
160
- "A1_B3_C3" ,
161
- ["[" , 1 ],
162
- ],
163
- "A1_B4" ,
164
- ["{" , "A1_B4_C1" , "foo" ],
165
- ],
166
- [
167
- "{" ,
168
- "A2_B1" ,
169
- 20 ,
170
- "A2_B2" ,
171
- "false" ,
172
- "A2_B3" ,
173
- [
174
- "{" ,
175
- "A2_B3_C1" ,
176
- None ,
177
- "A2_B3_C2" ,
178
- [
179
- "[" ,
180
- "A2_B3_C2_D1_1" ,
181
- "A2_B3_C2_D1_2" ,
182
- "-37.5" ,
183
- "A2_B3_C2_D1_4" ,
184
- "A2_B3_C2_D1_5" ,
185
- ["{" , "A2_B3_C2_D1_6_E1" , "false" ],
186
- ],
187
- "A2_B3_C3" ,
188
- ["[" , 2 ],
189
- ],
190
- "A2_B4" ,
191
- ["{" , "A2_B4_C1" , "bar" ],
192
- ],
193
- ]
194
-
195
- # Test single
196
- res_single = r .json ().resp ("doc1" , "$.L1.a" )
197
- assert res_single == [
198
- [
199
- "{" ,
200
- "A1_B1" ,
201
- 10 ,
202
- "A1_B2" ,
203
- "false" ,
204
- "A1_B3" ,
205
- [
206
- "{" ,
207
- "A1_B3_C1" ,
208
- None ,
209
- "A1_B3_C2" ,
210
- [
211
- "[" ,
212
- "A1_B3_C2_D1_1" ,
213
- "A1_B3_C2_D1_2" ,
214
- "-19.5" ,
215
- "A1_B3_C2_D1_4" ,
216
- "A1_B3_C2_D1_5" ,
217
- ["{" , "A1_B3_C2_D1_6_E1" , "true" ],
218
- ],
219
- "A1_B3_C3" ,
220
- ["[" , 1 ],
221
- ],
222
- "A1_B4" ,
223
- ["{" , "A1_B4_C1" , "foo" ],
224
- ]
225
- ]
226
-
227
- # Test missing path
228
- r .json ().resp ("doc1" , "$.nowhere" )
229
-
230
- # Test missing key
231
- # with pytest.raises(exceptions.ResponseError):
232
- r .json ().resp ("non_existing_doc" , "$..a" )
0 commit comments