@@ -98,6 +98,8 @@ def testForgetCommand(env):
98
98
99
99
def testSetAndGetCommands (env ):
100
100
"""Test REJSON.SET command"""
101
+ """Test REJSON.GET command"""
102
+
101
103
r = env
102
104
# Test set and get on large nested key
103
105
r .assertIsNone (r .execute_command ('JSON.SET' , 'doc1' , '$' , nested_large_key , 'XX' ))
@@ -154,6 +156,12 @@ def testSetAndGetCommands(env):
154
156
r .expect ('JSON.GET' , 'doc2' , '.a' , '.nested.b' , '.back_in_nov' , '.ttyl' ).raiseError ()
155
157
r .expect ('JSON.GET' , 'doc2' , '.back_in_nov' ).raiseError ()
156
158
159
+ # Test missing path (defaults to root)
160
+ r .assertOk (r .execute_command ('JSON.SET' , 'doc1' , '$' , '"inizio"' ))
161
+ res = r .execute_command ('JSON.GET' , 'doc1' )
162
+ r .assertEqual (res , '"inizio"' )
163
+
164
+
157
165
158
166
def testMGetCommand (env ):
159
167
"""Test REJSON.MGET command"""
@@ -310,8 +318,10 @@ def testStrAppendCommand(env):
310
318
res = r .execute_command ('JSON.GET' , 'doc1' , '$' )
311
319
r .assertEqual (res , '[{"a":"foo","nested1":{"a":"hellobar"},"nested2":{"a":31}}]' )
312
320
313
- # Test missing path
314
- r .expect ('JSON.STRAPPEND' , 'doc1' , '"piu"' ).raiseError ()
321
+ # Test missing path (defaults to root)
322
+ r .assertOk (r .execute_command ('JSON.SET' , 'doc1' , '$' , '"abcd"' ))
323
+ res = r .execute_command ('JSON.STRAPPEND' , 'doc1' , '"piu"' )
324
+ r .assertEqual (res , 7 )
315
325
316
326
317
327
def testStrLenCommand (env ):
@@ -342,6 +352,11 @@ def testStrLenCommand(env):
342
352
res1 = r .execute_command ('JSON.STRLEN' , 'doc1' , '..a' )
343
353
r .assertEqual (res1 , 6 )
344
354
355
+ # Test missing path
356
+ r .assertOk (r .execute_command ('JSON.SET' , 'doc1' , '$' , '"kantele"' ))
357
+ res = r .execute_command ('JSON.STRLEN' , 'doc1' )
358
+ r .assertEqual (res , 7 )
359
+
345
360
346
361
def testArrAppendCommand (env ):
347
362
"""
@@ -455,6 +470,11 @@ def testArrLenCommand(env):
455
470
# Test missing key
456
471
r .assertEqual (r .execute_command ('JSON.ARRLEN' , 'non_existing_doc' , '..a' ), None )
457
472
473
+ # Test missing path (defaults to root)
474
+ r .assertOk (r .execute_command ('JSON.SET' , 'doc1' , '$' , '[0, 1, 2, 3, 4]' ))
475
+ res = r .execute_command ('JSON.ARRLEN' , 'doc1' )
476
+ r .assertEqual (res , 5 )
477
+
458
478
def testArrPopCommand (env ):
459
479
"""
460
480
Test REJSON.ARRPOP command
@@ -489,14 +509,25 @@ def testArrPopCommand(env):
489
509
res = r .execute_command ('JSON.GET' , 'doc1' , '$' )
490
510
r .assertEqual (json .loads (res ), [{"a" : [], "nested1" : {"a" : ["hello" , "world" ]}, "nested2" : {"a" : 31 }}])
491
511
# Test single
492
- res = r .execute_command ('JSON.ARRPOP' , 'doc1' , '.nested1.a' , - 2 , '"baz"' )
512
+ res = r .execute_command ('JSON.ARRPOP' , 'doc1' , '.nested1.a' , - 2 )
493
513
r .assertEqual (res , '"hello"' )
494
514
res = r .execute_command ('JSON.GET' , 'doc1' , '$' )
495
515
r .assertEqual (json .loads (res ), [{"a" : [], "nested1" : {"a" : ["world" ]}, "nested2" : {"a" : 31 }}])
496
516
497
517
# Test missing key
498
518
r .expect ('JSON.ARRPOP' , 'non_existing_doc' , '..a' ).raiseError ()
499
519
520
+ # Test default path/index
521
+ r .assertOk (r .execute_command ('JSON.SET' , 'doc1' , '$' , '[0, 1, 2]' ))
522
+ res = r .execute_command ('JSON.ARRPOP' , 'doc1' )
523
+ r .assertEqual (res , '2' )
524
+ res = r .execute_command ('JSON.ARRPOP' , 'doc1' , '$' )
525
+ r .assertEqual (res , ['1' ])
526
+ res = r .execute_command ('JSON.ARRPOP' , 'doc1' , '.' )
527
+ r .assertEqual (res , '0' )
528
+
529
+
530
+
500
531
def testArrTrimCommand (env ):
501
532
"""
502
533
Test REJSON.ARRTRIM command
@@ -565,6 +596,10 @@ def testObjKeysCommand(env):
565
596
# Test missing key
566
597
r .expect ('JSON.OBJKEYS' , 'doc1' , '$.nowhere' ).raiseError ()
567
598
599
+ # Test default path
600
+ res = r .execute_command ('JSON.OBJKEYS' , 'doc1' )
601
+ r .assertEqual (res , ["nested1" , "a" , "nested2" ])
602
+
568
603
569
604
def testObjLenCommand (env ):
570
605
"""Test JSON.OBJLEN command"""
@@ -600,6 +635,10 @@ def testObjLenCommand(env):
600
635
# Test missing path
601
636
r .expect ('JSON.OBJLEN' , 'doc1' , '.nowhere' ).raiseError ()
602
637
638
+ # Test default path
639
+ res = r .execute_command ('JSON.OBJLEN' , 'doc1' )
640
+ r .assertEqual (res , 3 )
641
+
603
642
604
643
def load_types_data (nested_key_name ):
605
644
types_data = {
@@ -781,6 +820,11 @@ def testRespCommand(env):
781
820
res = r .execute_command ('JSON.RESP' , 'doc1' , '.L1.a' )
782
821
r .assertEqual ([res ], resSingle )
783
822
823
+ # Test default path
824
+ r .assertOk (r .execute_command ('JSON.SET' , 'doc1' , '$' , '[[1],[2]]' ))
825
+ res = r .execute_command ('JSON.RESP' , 'doc1' )
826
+ r .assertEqual (res , ['[' , ['[' , 1 ], ['[' , 2 ]])
827
+
784
828
def testArrIndexCommand (env ):
785
829
"""Test JSON.ARRINDEX command"""
786
830
r = env
0 commit comments