Skip to content

Add UpdateByQueryResponse.success() #1463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()