12
12
13
13
import os
14
14
15
+ from contextlib import contextmanager
16
+
15
17
import celery
16
18
import elasticsearch
17
19
import packaging .version
@@ -132,6 +134,11 @@ def __init__(self):
132
134
self .indices = FakeESIndices ()
133
135
134
136
137
+ @contextmanager
138
+ def _not_lock (* a , ** kw ):
139
+ yield True
140
+
141
+
135
142
class TestReindex :
136
143
137
144
def test_fails_when_raising (self , db_request , monkeypatch ):
@@ -168,6 +175,10 @@ def parallel_bulk(client, iterable):
168
175
assert iterable is docs
169
176
raise TestException
170
177
178
+ monkeypatch .setattr (
179
+ redis .StrictRedis , "from_url" ,
180
+ lambda * a , ** kw : pretend .stub (lock = _not_lock ))
181
+
171
182
monkeypatch .setattr (
172
183
warehouse .search .tasks , "parallel_bulk" , parallel_bulk )
173
184
@@ -233,6 +244,10 @@ def project_docs(db):
233
244
"celery.scheduler_url" : "redis://redis:6379/0" ,
234
245
}
235
246
247
+ monkeypatch .setattr (
248
+ redis .StrictRedis , "from_url" ,
249
+ lambda * a , ** kw : pretend .stub (lock = _not_lock ))
250
+
236
251
parallel_bulk = pretend .call_recorder (lambda client , iterable : [None ])
237
252
monkeypatch .setattr (
238
253
warehouse .search .tasks , "parallel_bulk" , parallel_bulk )
@@ -305,6 +320,10 @@ def project_docs(db):
305
320
"celery.scheduler_url" : "redis://redis:6379/0" ,
306
321
}
307
322
323
+ monkeypatch .setattr (
324
+ redis .StrictRedis , "from_url" ,
325
+ lambda * a , ** kw : pretend .stub (lock = _not_lock ))
326
+
308
327
parallel_bulk = pretend .call_recorder (lambda client , iterable : [None ])
309
328
monkeypatch .setattr (
310
329
warehouse .search .tasks , "parallel_bulk" , parallel_bulk )
@@ -385,6 +404,10 @@ def parallel_bulk(client, iterable):
385
404
assert iterable is docs
386
405
raise TestException
387
406
407
+ monkeypatch .setattr (
408
+ redis .StrictRedis , "from_url" ,
409
+ lambda * a , ** kw : pretend .stub (lock = _not_lock ))
410
+
388
411
monkeypatch .setattr (
389
412
warehouse .search .tasks , "parallel_bulk" , parallel_bulk )
390
413
@@ -394,7 +417,7 @@ def parallel_bulk(client, iterable):
394
417
assert es_client .indices .put_settings .calls == []
395
418
assert es_client .indices .forcemerge .calls == []
396
419
397
- def test_unindex_fails_when_raising (self , db_request ):
420
+ def test_unindex_fails_when_raising (self , db_request , monkeypatch ):
398
421
class TestException (Exception ):
399
422
pass
400
423
@@ -413,6 +436,10 @@ class TestException(Exception):
413
436
"celery.scheduler_url" : "redis://redis:6379/0" ,
414
437
}
415
438
439
+ monkeypatch .setattr (
440
+ redis .StrictRedis , "from_url" ,
441
+ lambda * a , ** kw : pretend .stub (lock = _not_lock ))
442
+
416
443
with pytest .raises (TestException ):
417
444
unindex_project (task , db_request , 'foo' )
418
445
@@ -462,7 +489,7 @@ def test_reindex_retry_on_lock(self, db_request, monkeypatch):
462
489
pretend .call (countdown = 60 , exc = le )
463
490
]
464
491
465
- def test_unindex_accepts_defeat (self , db_request ):
492
+ def test_unindex_accepts_defeat (self , db_request , monkeypatch ):
466
493
task = pretend .stub ()
467
494
es_client = FakeESClient ()
468
495
es_client .delete = pretend .call_recorder (
@@ -479,6 +506,10 @@ def test_unindex_accepts_defeat(self, db_request):
479
506
"celery.scheduler_url" : "redis://redis:6379/0" ,
480
507
}
481
508
509
+ monkeypatch .setattr (
510
+ redis .StrictRedis , "from_url" ,
511
+ lambda * a , ** kw : pretend .stub (lock = _not_lock ))
512
+
482
513
unindex_project (task , db_request , 'foo' )
483
514
484
515
assert es_client .delete .calls == [
@@ -516,6 +547,10 @@ def project_docs(db, project_name=None):
516
547
"celery.scheduler_url" : "redis://redis:6379/0" ,
517
548
}
518
549
550
+ monkeypatch .setattr (
551
+ redis .StrictRedis , "from_url" ,
552
+ lambda * a , ** kw : pretend .stub (lock = _not_lock ))
553
+
519
554
parallel_bulk = pretend .call_recorder (lambda client , iterable : [None ])
520
555
monkeypatch .setattr (
521
556
warehouse .search .tasks , "parallel_bulk" , parallel_bulk )
0 commit comments