Exemple #1
0
 def test_RevisionConflict_etc(self):
     self.exc = errors.RevisionConflict()
     resp = self.app.post('/req',
                          params='{}',
                          headers={'content-type': 'application/json'},
                          expect_errors=True)
     self.assertEqual(409, resp.status)
     self.assertEqual('application/json', resp.header('content-type'))
     self.assertEqual({"error": "revision conflict"}, json.loads(resp.body))
Exemple #2
0
 def put_doc(self, doc):
     if doc.doc_id is None:
         raise errors.InvalidDocId()
     self._check_doc_id(doc.doc_id)
     if self._has_conflicts(doc.doc_id):
         raise errors.ConflictedDoc()
     old_doc = self._get_doc(doc.doc_id)
     if old_doc and doc.rev is None and old_doc.is_tombstone():
         new_rev = self._allocate_doc_rev(old_doc.rev)
     else:
         if old_doc is not None:
             if old_doc.rev != doc.rev:
                 raise errors.RevisionConflict()
         else:
             if doc.rev is not None:
                 raise errors.RevisionConflict()
         new_rev = self._allocate_doc_rev(doc.rev)
     doc.rev = new_rev
     self._put_and_update_indexes(old_doc, doc)
     return new_rev
Exemple #3
0
 def delete_doc(self, doc):
     with self._db_handle:
         old_doc = self._get_doc(doc.doc_id, check_for_conflicts=True)
         if old_doc is None:
             raise errors.DocumentDoesNotExist
         if old_doc.rev != doc.rev:
             raise errors.RevisionConflict()
         if old_doc.is_tombstone():
             raise errors.DocumentAlreadyDeleted
         if old_doc.has_conflicts:
             raise errors.ConflictedDoc()
         new_rev = self._allocate_doc_rev(doc.rev)
         doc.rev = new_rev
         doc.make_tombstone()
         self._put_and_update_indexes(old_doc, doc)
     return new_rev