Skip to content
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

Fix a response of documents/batch #19

Merged
merged 3 commits into from
Dec 9, 2023
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
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ command line.

# Add a document using the batch upload SDF:
curl -X POST -H "Content-Type: application/json" http://localhost:15808/2013-08-22/documents/batch -d '[{"lang": "en", "fields": {"name": "bob"}, "version": 1376497963, "type": "add", "id": 1246}]'
{"status": "ok", "adds": 1, "deletes": 0, "error": "", "warning": ""}
{"status": "success", "adds": 1, "deletes": 0, "errors": [], "warnings": []}

# Check the document is there:
curl http://localhost:15808/dev/documents
Expand All @@ -120,7 +120,7 @@ command line.

# Remove the document in another batch update:
curl -X POST -H "Content-Type: application/json" http://localhost:15808/2013-08-22/documents/batch -d '[{"version": 1376497963, "type": "delete", "id": 1246}]'
{"status": "ok", "adds": 0, "deletes": 1, "error": "", "warning": ""}
{"status": "success", "adds": 0, "deletes": 1, "errors": [], "warnings": []}

# Check what was removed:
curl http://localhost:15808/dev/documents
Expand Down
16 changes: 8 additions & 8 deletions nozama/cloudsearch/data/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,16 @@ def load(docs_to_load):
.. code-block:: python

rc = dict(
status='ok',
status='success',
adds=len(to_load),
deletes=len(to_remove),
error='',
warning='',
errors=[],
warnings=[],
)

Reference:
* http://docs.aws.amazon.com/cloudsearch/latest/developerguide/\
DocumentsBatch.JSON.html#DocumentsBatch.JSON.ResponseProperties
* https://docs.aws.amazon.com/cloudsearch/latest/developerguide/\
documents-batch-resource.html#documents-batch-json-response-properties

"""
log = get_log('load')
Expand Down Expand Up @@ -244,11 +244,11 @@ def load(docs_to_load):
remove_from_elasticsearch(doc)

rc = dict(
status='ok',
status='success',
adds=len(to_load),
deletes=len(to_remove),
error='',
warning='',
errors=[],
warnings=[],
)

return rc
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pymongo
elasticsearch
pymongo~=3.0
elasticsearch~=7.0
decorator
paste
formencode
Expand Down
2 changes: 1 addition & 1 deletion tests/test_backend_searching.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def test_basic_search(logger, mongodb, elastic):
]

rc = document.load(example_sdf)
assert rc['status'] == 'ok'
assert rc['status'] == 'success'
assert rc['adds'] == 2

# return all:
Expand Down
36 changes: 18 additions & 18 deletions tests/test_documentops.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ def test_document_add(logger, elastic, mongodb):

rc = document.load(example_sdf)

assert rc['status'] == 'ok'
assert rc['status'] == 'success'
assert rc['adds'] == 1
assert rc['deletes'] == 0
assert rc['error'] == ''
assert rc['warning'] == ''
assert rc['errors'] == []
assert rc['warnings'] == []

found = document.all()

Expand Down Expand Up @@ -71,11 +71,11 @@ def test_remove_on_emtpy(logger, mongodb):
]
rc = document.load(example_sdf)

assert rc['status'] == 'ok'
assert rc['status'] == 'success'
assert rc['adds'] == 0
assert rc['deletes'] == 1
assert rc['error'] == ''
assert rc['warning'] == ''
assert rc['errors'] == []
assert rc['warnings'] == []

found = document.all()
assert len(found) == 0
Expand Down Expand Up @@ -118,11 +118,11 @@ def test_add_remove(logger, mongodb):

rc = document.load(example_add_sdf)

assert rc['status'] == 'ok'
assert rc['status'] == 'success'
assert rc['adds'] == 1
assert rc['deletes'] == 0
assert rc['error'] == ''
assert rc['warning'] == ''
assert rc['errors'] == []
assert rc['warnings'] == []

report = document.report()

Expand All @@ -142,11 +142,11 @@ def test_add_remove(logger, mongodb):
]
rc = document.load(example_remove_sdf)

assert rc['status'] == 'ok'
assert rc['status'] == 'success'
assert rc['adds'] == 0
assert rc['deletes'] == 1
assert rc['error'] == ''
assert rc['warning'] == ''
assert rc['errors'] == []
assert rc['warnings'] == []

found = document.all()
assert len(found) == 0
Expand Down Expand Up @@ -199,11 +199,11 @@ def test_remove_then_search(logger, mongodb):

rc = document.load(example_add_sdf)

assert rc['status'] == 'ok'
assert rc['status'] == 'success'
assert rc['adds'] == 1
assert rc['deletes'] == 0
assert rc['error'] == ''
assert rc['warning'] == ''
assert rc['errors'] == []
assert rc['warnings'] == []

report = document.report()

Expand All @@ -223,11 +223,11 @@ def test_remove_then_search(logger, mongodb):
]
rc = document.load(example_remove_sdf)

assert rc['status'] == 'ok'
assert rc['status'] == 'success'
assert rc['adds'] == 0
assert rc['deletes'] == 1
assert rc['error'] == ''
assert rc['warning'] == ''
assert rc['errors'] == []
assert rc['warnings'] == []

found = document.all()
assert len(found) == 0
Expand Down