cloudant / python-cloudant

A Python library for Cloudant and CouchDB
Apache License 2.0
163 stars 55 forks source link

Override dict's get method #505

Closed mojito317 closed 3 years ago

mojito317 commented 3 years ago

Checklist

Description

Merges #474 and tests.

Approach

One sentence in the pydoc was a little bit misleading, so I changed it to:

Dictates whether a remote request is made to retrieve the doc, if it is not present in the local cache.

Extended the tests to cover the new behaviour based on the proposed behaviour table.

Proposed behaviour

Call Doc is local Doc is remote Result Covered with tests
db['foo'] True True returns local doc test_create_document_that_already_exists
test_create_document_without_id
test_create_design_document
test_create_empty_document
db['foo'] False True returns remote doc test_get_document_from_remote
db['foo'] False False returns KeyError test_get_non_existing_doc_via_getitem
db['foo'] True False returns local doc test_get_document_from_cache
db.get('foo') True True returns local doc test_create_document_that_already_exists
test_create_document_without_id
test_create_design_document
db.get('foo') False True returns None test_get_document_from_remote
db.get('foo') False False returns None test_get_non_existing_document_from_cache
db.get('foo') True False returns local doc test_get_document_from_cache
db.get('foo', remote=True) True True returns local doc test_create_document_that_already_exists
test_create_document_without_id
test_create_design_document
test_create_empty_document
db.get('foo', remote=True) False True fetches remote doc test_get_document_from_remote
db.get('foo', remote=True) False False returns None test_get_non_existing_document_from_remote
db.get('foo', remote=True) True False returns local doc test_get_document_from_cache

Testing

New assertions to cover the new feature to:

New test cases:

Monitoring and Logging

mojito317 commented 3 years ago

Thank you @dominickj-tdi for the implementation. Thanks, @ricellis, and @emlaver for the reviews. I'm about to merge this.