def test_unindex_fails_when_raising(self, db_request, monkeypatch): task = pretend.stub() class TestException(Exception): pass es_client = FakeESClient() es_client.delete = pretend.raiser(TestException) monkeypatch.setattr(redis.StrictRedis, "from_url", lambda *a, **kw: pretend.stub(lock=NotLock)) db_request.registry.update({ "elasticsearch.client": es_client, "elasticsearch.index": "warehouse" }) with pytest.raises(TestException): unindex_project(task, db_request, "foo")
def test_unindex_retry_on_lock(self, db_request, monkeypatch): task = pretend.stub( retry=pretend.call_recorder(pretend.raiser(celery.exceptions.Retry)) ) db_request.registry.settings = {"celery.scheduler_url": "redis://redis:6379/0"} le = redis.exceptions.LockError() monkeypatch.setattr( redis.StrictRedis, "from_url", lambda *a, **kw: pretend.stub(lock=pretend.raiser(le)), ) with pytest.raises(celery.exceptions.Retry): unindex_project(task, db_request, "foo") assert task.retry.calls == [pretend.call(countdown=60, exc=le)]
def test_unindex_fails_when_raising(self, db_request, monkeypatch): task = pretend.stub() class TestException(Exception): pass es_client = FakeESClient() es_client.delete = pretend.raiser(TestException) monkeypatch.setattr( redis.StrictRedis, "from_url", lambda *a, **kw: pretend.stub(lock=NotLock) ) db_request.registry.update( {"elasticsearch.client": es_client, "elasticsearch.index": "warehouse"} ) with pytest.raises(TestException): unindex_project(task, db_request, "foo")
def test_unindex_accepts_defeat(self, db_request, monkeypatch): task = pretend.stub() es_client = FakeESClient() es_client.delete = pretend.call_recorder( pretend.raiser(elasticsearch.exceptions.NotFoundError)) monkeypatch.setattr(redis.StrictRedis, "from_url", lambda *a, **kw: pretend.stub(lock=NotLock)) db_request.registry.update({ "elasticsearch.client": es_client, "elasticsearch.index": "warehouse" }) unindex_project(task, db_request, "foo") assert es_client.delete.calls == [ pretend.call(index="warehouse", doc_type="doc", id="foo") ]
def test_unindex_accepts_defeat(self, db_request, monkeypatch): task = pretend.stub() es_client = FakeESClient() es_client.delete = pretend.call_recorder( pretend.raiser(elasticsearch.exceptions.NotFoundError) ) monkeypatch.setattr( redis.StrictRedis, "from_url", lambda *a, **kw: pretend.stub(lock=NotLock) ) db_request.registry.update( {"elasticsearch.client": es_client, "elasticsearch.index": "warehouse"} ) unindex_project(task, db_request, "foo") assert es_client.delete.calls == [ pretend.call(index="warehouse", doc_type="doc", id="foo") ]