summaryrefslogtreecommitdiff
path: root/src/leap
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2015-01-06 01:31:26 -0400
committerKali Kaneko <kali@leap.se>2015-02-11 14:05:43 -0400
commitce6008a326dfc8020b341904308115917eabd7de (patch)
tree27be866d7fb9191096ba0429be9a72321c0b69dc /src/leap
parent84888155b09b3af6a755262b28728de2f851c8cb (diff)
tests for mail.mail module: MessageCollection
Diffstat (limited to 'src/leap')
-rw-r--r--src/leap/mail/adaptors/soledad.py44
-rw-r--r--src/leap/mail/mail.py5
-rw-r--r--src/leap/mail/tests/test_mail.py18
3 files changed, 45 insertions, 22 deletions
diff --git a/src/leap/mail/adaptors/soledad.py b/src/leap/mail/adaptors/soledad.py
index f0808af..522d2d3 100644
--- a/src/leap/mail/adaptors/soledad.py
+++ b/src/leap/mail/adaptors/soledad.py
@@ -290,7 +290,7 @@ class SoledadDocumentWrapper(models.DocumentWrapper):
in the model as the `list_index`.
:rtype: Deferred
"""
- # TODO
+ # TODO LIST (get_all)
# [ ] extend support to indexes with n-ples
# [ ] benchmark the cost of querying and returning indexes in a big
# database. This might badly need pagination before being put to
@@ -428,19 +428,28 @@ class MessageWrapper(object):
content of the content-docs.
"""
if isinstance(mdoc, SoledadDocument):
+ mdoc_id = mdoc.doc_id
mdoc = mdoc.content
+ else:
+ mdoc_id = None
if not mdoc:
mdoc = {}
- self.mdoc = MetaMsgDocWrapper(**mdoc)
+ self.mdoc = MetaMsgDocWrapper(doc_id=mdoc_id, **mdoc)
if isinstance(fdoc, SoledadDocument):
+ fdoc_id = fdoc.doc_id
fdoc = fdoc.content
- self.fdoc = FlagsDocWrapper(**fdoc)
+ else:
+ fdoc_id = None
+ self.fdoc = FlagsDocWrapper(doc_id=fdoc_id, **fdoc)
self.fdoc.set_future_doc_id(self.mdoc.fdoc)
if isinstance(hdoc, SoledadDocument):
+ hdoc_id = hdoc.doc_id
hdoc = hdoc.content
- self.hdoc = HeaderDocWrapper(**hdoc)
+ else:
+ hdoc_id = None
+ self.hdoc = HeaderDocWrapper(doc_id=hdoc_id, **hdoc)
self.hdoc.set_future_doc_id(self.mdoc.hdoc)
if cdocs is None:
@@ -489,9 +498,15 @@ class MessageWrapper(object):
return self.fdoc.update(store)
def delete(self, store):
+ # TODO
# Eventually this would have to do the duplicate search or send for the
- # garbage collector. At least the fdoc can be unlinked.
- raise NotImplementedError()
+ # garbage collector. At least mdoc and t the mdoc and fdoc can be
+ # unlinked.
+ d = []
+ if self.mdoc.doc_id:
+ d.append(self.mdoc.delete(store))
+ d.append(self.fdoc.delete(store))
+ return defer.gatherResults(d)
def copy(self, store, newmailbox):
"""
@@ -565,9 +580,6 @@ class MailboxWrapper(SoledadDocumentWrapper):
closed = False
subscribed = False
- # I think we don't need to store this one.
- # rw = True
-
class __meta__(object):
index = "mbox"
list_index = (indexes.TYPE_IDX, 'type_')
@@ -717,9 +729,8 @@ class SoledadMailAdaptor(SoledadIndexMixin):
return self.get_msg_from_docs(
msg_class, mdoc, fdoc, hdoc, cdocs, uid=None)
- def get_msg_from_mdoc_id(self, MessageClass, store, doc_id,
+ def get_msg_from_mdoc_id(self, MessageClass, store, mdoc_id,
uid=None, get_cdocs=False):
- metamsg_id = doc_id
def wrap_meta_doc(doc):
cls = MetaMsgDocWrapper
@@ -740,8 +751,8 @@ class SoledadMailAdaptor(SoledadIndexMixin):
return d
def get_parts_doc_from_mdoc_id():
- mbox = re.findall(constants.METAMSGID_MBOX_RE, doc_id)[0]
- chash = re.findall(constants.METAMSGID_CHASH_RE, doc_id)[0]
+ mbox = re.findall(constants.METAMSGID_MBOX_RE, mdoc_id)[0]
+ chash = re.findall(constants.METAMSGID_CHASH_RE, mdoc_id)[0]
def _get_fdoc_id_from_mdoc_id():
return constants.FDOCID.format(mbox=mbox, chash=chash)
@@ -753,22 +764,19 @@ class SoledadMailAdaptor(SoledadIndexMixin):
fdoc_id = _get_fdoc_id_from_mdoc_id()
hdoc_id = _get_hdoc_id_from_mdoc_id()
+ d_docs.append(store.get_doc(mdoc_id))
d_docs.append(store.get_doc(fdoc_id))
d_docs.append(store.get_doc(hdoc_id))
d = defer.gatherResults(d_docs)
return d
- def add_mdoc_id_placeholder(docs_list):
- return [None] + docs_list
-
if get_cdocs:
- d = store.get_doc(metamsg_id)
+ d = store.get_doc(mdoc_id)
d.addCallback(wrap_meta_doc)
d.addCallback(get_part_docs_from_mdoc_wrapper)
else:
d = get_parts_doc_from_mdoc_id()
- d.addCallback(add_mdoc_id_placeholder)
d.addCallback(partial(self._get_msg_from_variable_doc_list,
msg_class=MessageClass, uid=uid))
diff --git a/src/leap/mail/mail.py b/src/leap/mail/mail.py
index 55e50f7..671642a 100644
--- a/src/leap/mail/mail.py
+++ b/src/leap/mail/mail.py
@@ -420,13 +420,12 @@ class MessageCollection(object):
"""
wrapper = msg.get_wrapper()
- def delete_mdoc_id(_):
- # XXX does this work?
+ def delete_mdoc_id(_, wrapper):
doc_id = wrapper.mdoc.doc_id
return self.mbox_indexer.delete_doc_by_hash(
self.mbox_name, doc_id)
d = wrapper.delete(self.store)
- d.addCallback(delete_mdoc_id)
+ d.addCallback(delete_mdoc_id, wrapper)
return d
# TODO should add a delete-by-uid to collection?
diff --git a/src/leap/mail/tests/test_mail.py b/src/leap/mail/tests/test_mail.py
index cb97be5..d11df40 100644
--- a/src/leap/mail/tests/test_mail.py
+++ b/src/leap/mail/tests/test_mail.py
@@ -259,7 +259,23 @@ class MessageCollectionTestCase(unittest.TestCase,
self.fail()
def test_delete_msg(self):
- self.fail()
+ d = self.add_msg_to_collection()
+
+ def del_msg(collection):
+ def _delete_it(msg):
+ return collection.delete_msg(msg)
+
+ d = collection.get_message_by_uid(1)
+ d.addCallback(_delete_it)
+ return d
+
+ d.addCallback(lambda _: self.get_collection())
+ d.addCallback(del_msg)
+ d.addCallback(self._test_delete_msg_cb)
+ return d
+
+ def _test_delete_msg_cb(self, _):
+ return partial(self.assert_collection_count, expected=0)
def test_update_flags(self):
d = self.add_msg_to_collection()