This repository was archived by the owner on Aug 30, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed
Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments