summaryrefslogtreecommitdiff
path: root/service/test/unit/adapter
diff options
context:
space:
mode:
authormnandri <mnandri@eunglick.corporate.thoughtworks.com>2015-12-18 11:21:48 +0100
committermnandri <mnandri@eunglick.corporate.thoughtworks.com>2015-12-18 11:22:34 +0100
commitb73185d27fe5d59d64b0759c1efbbcdf89086d11 (patch)
tree2d9d00d1a0b977878b1aad736464313b5fdc66e7 /service/test/unit/adapter
parent06ac408dbd7629d387dd7b311a26c144ee56631e (diff)
ensuring the same file is not saved twice
Issue #548
Diffstat (limited to 'service/test/unit/adapter')
-rw-r--r--service/test/unit/adapter/mailstore/test_leap_attachment_store.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/service/test/unit/adapter/mailstore/test_leap_attachment_store.py b/service/test/unit/adapter/mailstore/test_leap_attachment_store.py
index 172cceb6..4e9b56b1 100644
--- a/service/test/unit/adapter/mailstore/test_leap_attachment_store.py
+++ b/service/test/unit/adapter/mailstore/test_leap_attachment_store.py
@@ -16,6 +16,7 @@
# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
import json
from uuid import uuid4
+import u1db
from leap.mail.adaptors.soledad_indexes import MAIL_INDEXES
from leap.soledad.common.document import SoledadDocument
@@ -68,6 +69,26 @@ class TestLeapAttachmentStore(TestCase):
verify(self.soledad).create_doc(cdoc_serialized, doc_id=attachment_id)
@defer.inlineCallbacks
+ def test_store_attachment_twice_does_not_cause_exception(self):
+ attachment_id = '9863729729D2E2EE8E52F0A7115CE33AD18DDA4B58E49AE08DD092D1C8E699B0'
+ content = 'this is some attachment content'
+ content_type = 'text/plain'
+ cdoc_serialized = {'content_transfer_encoding': 'base64', 'lkf': [], 'content_disposition': 'attachment',
+ 'ctype': '', 'raw': 'dGhpcyBpcyBzb21lIGF0dGFjaG1lbnQgY29udGVudA==',
+ 'phash': '9863729729D2E2EE8E52F0A7115CE33AD18DDA4B58E49AE08DD092D1C8E699B0',
+ 'content_type': 'text/plain', 'type': 'cnt'}
+ doc = SoledadDocument(json=json.dumps({'content_type': content_type, 'raw': content}))
+ when(self.soledad).get_from_index('by-type-and-payloadhash', 'cnt', attachment_id).thenReturn(defer.succeed([doc]))
+
+ store = LeapAttachmentStore(self.soledad)
+
+ when(self.soledad).create_doc(cdoc_serialized, doc_id=attachment_id).thenRaise(u1db.errors.RevisionConflict())
+
+ actual_attachment_id = yield store.add_attachment(content, content_type)
+
+ self.assertEqual(attachment_id, actual_attachment_id)
+
+ @defer.inlineCallbacks
def test_get_mail_attachment_different_content_encodings(self):
attachment_id = '1B0A9AAD9E153D24265395203C53884506ABA276394B9FEC02B214BF9E77E48E'
encoding_examples = [('', 'asdf', 'asdf'),