Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit b434ca9

Browse files
authored
Merge pull request #432 from aogier/feature/test_update_field_success_on_retry
Fixing test_update_field_success_on_retry
2 parents 00b6cbb + 0bf212f commit b434ca9

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

tests/unit/document_tests.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15+
import cloudant
1516
"""
1617
_document_tests_
1718
@@ -523,9 +524,18 @@ def test_update_field_success_on_retry(self):
523524
# Mock when saving the document
524525
# 1st call throw a 409
525526
# 2nd call delegate to the real doc.save()
526-
with mock.patch('cloudant.document.Document.save',
527-
side_effect=[requests.HTTPError(response=mock.Mock(status_code=409, reason='conflict')),
528-
doc.save()]) as m_save:
527+
528+
class SaveMock(object):
529+
calls = 0
530+
def save(self):
531+
if self.calls == 0:
532+
self.calls += 1
533+
raise requests.HTTPError(response=mock.Mock(status_code=409, reason='conflict'))
534+
else:
535+
return cloudant.document.Document.save(doc)
536+
537+
with mock.patch.object(doc, 'save',
538+
side_effect=SaveMock().save) as m_save:
529539
# A list of side effects containing only 1 element
530540
doc.update_field(doc.field_set, 'age', 7, max_tries=1)
531541
# Two calls to save, one with a 409 and one that succeeds

0 commit comments

Comments
 (0)