Skip to content

Commit

Permalink
Add UpdateByQueryResponse.success()
Browse files Browse the repository at this point in the history
  • Loading branch information
sethmlarson committed Dec 3, 2020
1 parent f856f5d commit 3e5703f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions elasticsearch_dsl/response/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,6 @@ def __init__(self, search, response, doc_class=None):
super(AttrDict, self).__setattr__("_search", search)
super(AttrDict, self).__setattr__("_doc_class", doc_class)
super(UpdateByQueryResponse, self).__init__(response)

def success(self):
return not self.timed_out and not self.failures
2 changes: 2 additions & 0 deletions tests/test_integration/test_update_by_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def test_update_by_query_no_script(write_client, setup_ubq_tests):
assert response.updated == 52
assert response.deleted == 0
assert response.took > 0
assert response.success()


def test_update_by_query_with_script(write_client, setup_ubq_tests):
Expand Down Expand Up @@ -69,3 +70,4 @@ def test_delete_by_query_with_script(write_client, setup_ubq_tests):

assert response.total == 1
assert response.deleted == 1
assert response.success()
12 changes: 12 additions & 0 deletions tests/test_update_by_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from copy import deepcopy

from elasticsearch_dsl import Q, UpdateByQuery
from elasticsearch_dsl.response import UpdateByQueryResponse


def test_ubq_starts_with_no_query():
Expand Down Expand Up @@ -159,3 +160,14 @@ def test_overwrite_script():
} == ubq.to_dict()
ubq = ubq.script(source="ctx._source.likes++")
assert {"script": {"source": "ctx._source.likes++"}} == ubq.to_dict()


def test_update_by_query_response_success():
ubqr = UpdateByQueryResponse({}, {"timed_out": False, "failures": []})
assert ubqr.success()

ubqr = UpdateByQueryResponse({}, {"timed_out": True, "failures": []})
assert not ubqr.success()

ubqr = UpdateByQueryResponse({}, {"timed_out": False, "failures": [{}]})
assert not ubqr.success()

0 comments on commit 3e5703f

Please sign in to comment.