10
10
import redis .commands .search
11
11
import redis .commands .search .aggregation as aggregations
12
12
import redis .commands .search .reducers as reducers
13
- from redis import Redis
14
13
from redis .commands .json .path import Path
15
14
from redis .commands .search import Search
16
15
from redis .commands .search .field import GeoField , NumericField , TagField , TextField
19
18
from redis .commands .search .result import Result
20
19
from redis .commands .search .suggestion import Suggestion
21
20
22
- from .conftest import default_redismod_url , skip_ifmodversion_lt
23
-
24
- pytestmark = pytest .mark .onlynoncluster
25
-
21
+ from .conftest import skip_ifmodversion_lt
26
22
27
23
WILL_PLAY_TEXT = os .path .abspath (
28
24
os .path .join (os .path .dirname (__file__ ), "testdata" , "will_play_text.csv.bz2" )
36
32
def waitForIndex (env , idx , timeout = None ):
37
33
delay = 0.1
38
34
while True :
39
- res = env .execute_command ("ft.info " , idx )
35
+ res = env .execute_command ("FT.INFO " , idx )
40
36
try :
41
37
res .index ("indexing" )
42
38
except ValueError :
@@ -52,13 +48,12 @@ def waitForIndex(env, idx, timeout=None):
52
48
break
53
49
54
50
55
- def getClient ():
51
+ def getClient (client ):
56
52
"""
57
53
Gets a client client attached to an index name which is ready to be
58
54
created
59
55
"""
60
- rc = Redis .from_url (default_redismod_url , decode_responses = True )
61
- return rc
56
+ return client
62
57
63
58
64
59
def createIndex (client , num_docs = 100 , definition = None ):
@@ -96,12 +91,6 @@ def createIndex(client, num_docs=100, definition=None):
96
91
indexer .commit ()
97
92
98
93
99
- # override the default module client, search requires both db=0, and text
100
- @pytest .fixture
101
- def modclient ():
102
- return Redis .from_url (default_redismod_url , db = 0 , decode_responses = True )
103
-
104
-
105
94
@pytest .fixture
106
95
def client (modclient ):
107
96
modclient .flushdb ()
@@ -234,6 +223,7 @@ def test_payloads(client):
234
223
235
224
236
225
@pytest .mark .redismod
226
+ @pytest .mark .onlynoncluster
237
227
def test_scores (client ):
238
228
client .ft ().create_index ((TextField ("txt" ),))
239
229
@@ -356,14 +346,14 @@ def test_sort_by(client):
356
346
357
347
@pytest .mark .redismod
358
348
@skip_ifmodversion_lt ("2.0.0" , "search" )
359
- def test_drop_index ():
349
+ def test_drop_index (client ):
360
350
"""
361
351
Ensure the index gets dropped by data remains by default
362
352
"""
363
353
for x in range (20 ):
364
354
for keep_docs in [[True , {}], [False , {"name" : "haveit" }]]:
365
355
idx = "HaveIt"
366
- index = getClient ()
356
+ index = getClient (client )
367
357
index .hset ("index:haveit" , mapping = {"name" : "haveit" })
368
358
idef = IndexDefinition (prefix = ["index:" ])
369
359
index .ft (idx ).create_index ((TextField ("name" ),), definition = idef )
@@ -574,9 +564,9 @@ def test_summarize(client):
574
564
575
565
@pytest .mark .redismod
576
566
@skip_ifmodversion_lt ("2.0.0" , "search" )
577
- def test_alias ():
578
- index1 = getClient ()
579
- index2 = getClient ()
567
+ def test_alias (client ):
568
+ index1 = getClient (client )
569
+ index2 = getClient (client )
580
570
581
571
def1 = IndexDefinition (prefix = ["index1:" ])
582
572
def2 = IndexDefinition (prefix = ["index2:" ])
@@ -594,7 +584,7 @@ def test_alias():
594
584
595
585
# create alias and check for results
596
586
ftindex1 .aliasadd ("spaceballs" )
597
- alias_client = getClient ().ft ("spaceballs" )
587
+ alias_client = getClient (client ).ft ("spaceballs" )
598
588
res = alias_client .search ("*" ).docs [0 ]
599
589
assert "index1:lonestar" == res .id
600
590
@@ -604,7 +594,7 @@ def test_alias():
604
594
605
595
# update alias and ensure new results
606
596
ftindex2 .aliasupdate ("spaceballs" )
607
- alias_client2 = getClient ().ft ("spaceballs" )
597
+ alias_client2 = getClient (client ).ft ("spaceballs" )
608
598
609
599
res = alias_client2 .search ("*" ).docs [0 ]
610
600
assert "index2:yogurt" == res .id
@@ -615,21 +605,21 @@ def test_alias():
615
605
616
606
617
607
@pytest .mark .redismod
618
- def test_alias_basic ():
608
+ def test_alias_basic (client ):
619
609
# Creating a client with one index
620
- getClient ().flushdb ()
621
- index1 = getClient ().ft ("testAlias" )
610
+ getClient (client ).flushdb ()
611
+ index1 = getClient (client ).ft ("testAlias" )
622
612
623
613
index1 .create_index ((TextField ("txt" ),))
624
614
index1 .add_document ("doc1" , txt = "text goes here" )
625
615
626
- index2 = getClient ().ft ("testAlias2" )
616
+ index2 = getClient (client ).ft ("testAlias2" )
627
617
index2 .create_index ((TextField ("txt" ),))
628
618
index2 .add_document ("doc2" , txt = "text goes here" )
629
619
630
620
# add the actual alias and check
631
621
index1 .aliasadd ("myalias" )
632
- alias_client = getClient ().ft ("myalias" )
622
+ alias_client = getClient (client ).ft ("myalias" )
633
623
res = sorted (alias_client .search ("*" ).docs , key = lambda x : x .id )
634
624
assert "doc1" == res [0 ].id
635
625
@@ -639,7 +629,7 @@ def test_alias_basic():
639
629
640
630
# update the alias and ensure we get doc2
641
631
index2 .aliasupdate ("myalias" )
642
- alias_client2 = getClient ().ft ("myalias" )
632
+ alias_client2 = getClient (client ).ft ("myalias" )
643
633
res = sorted (alias_client2 .search ("*" ).docs , key = lambda x : x .id )
644
634
assert "doc1" == res [0 ].id
645
635
@@ -790,6 +780,7 @@ def test_phonetic_matcher(client):
790
780
791
781
792
782
@pytest .mark .redismod
783
+ @pytest .mark .onlynoncluster
793
784
def test_scorer (client ):
794
785
client .ft ().create_index ((TextField ("description" ),))
795
786
@@ -842,6 +833,7 @@ def test_get(client):
842
833
843
834
844
835
@pytest .mark .redismod
836
+ @pytest .mark .onlynoncluster
845
837
@skip_ifmodversion_lt ("2.2.0" , "search" )
846
838
def test_config (client ):
847
839
assert client .ft ().config_set ("TIMEOUT" , "100" )
@@ -854,6 +846,7 @@ def test_config(client):
854
846
855
847
856
848
@pytest .mark .redismod
849
+ @pytest .mark .onlynoncluster
857
850
def test_aggregations_groupby (client ):
858
851
# Creating the index definition and schema
859
852
client .ft ().create_index (
@@ -1085,8 +1078,8 @@ def test_aggregations_apply(client):
1085
1078
CreatedDateTimeUTC = "@CreatedDateTimeUTC * 10"
1086
1079
)
1087
1080
res = client .ft ().aggregate (req )
1088
- assert res .rows [0 ] == [ "CreatedDateTimeUTC" , "6373878785249699840" ]
1089
- assert res . rows [ 1 ] == [ "CreatedDateTimeUTC " , "6373878758592700416" ]
1081
+ res_set = set ([ res .rows [0 ][ 1 ], res . rows [ 1 ][ 1 ]])
1082
+ assert res_set == set ([ "6373878785249699840 " , "6373878758592700416" ])
1090
1083
1091
1084
1092
1085
@pytest .mark .redismod
@@ -1158,6 +1151,7 @@ def test_index_definition(client):
1158
1151
1159
1152
1160
1153
@pytest .mark .redismod
1154
+ @pytest .mark .onlynoncluster
1161
1155
def testExpire (client ):
1162
1156
client .ft ().create_index ((TextField ("txt" , sortable = True ),), temporary = 4 )
1163
1157
ttl = client .execute_command ("ft.debug" , "TTL" , "idx" )
@@ -1477,6 +1471,7 @@ def test_json_with_jsonpath(client):
1477
1471
1478
1472
1479
1473
@pytest .mark .redismod
1474
+ @pytest .mark .onlynoncluster
1480
1475
def test_profile (client ):
1481
1476
client .ft ().create_index ((TextField ("t" ),))
1482
1477
client .ft ().client .hset ("1" , "t" , "hello" )
@@ -1505,6 +1500,7 @@ def test_profile(client):
1505
1500
1506
1501
1507
1502
@pytest .mark .redismod
1503
+ @pytest .mark .onlynoncluster
1508
1504
def test_profile_limited (client ):
1509
1505
client .ft ().create_index ((TextField ("t" ),))
1510
1506
client .ft ().client .hset ("1" , "t" , "hello" )
0 commit comments