Ejemplo n.º 1
0
class SoledadTestBase(unittest.TestCase, AppTestClient):
    # these are so long because our CI is so slow at the moment.
    DEFERRED_TIMEOUT = 120
    DEFERRED_TIMEOUT_LONG = 300

    @defer.inlineCallbacks
    def setUp(self):
        set_events_enabled(False)
        super(SoledadTestBase, self).setUp()
        self.adaptor = SoledadMailAdaptor()
        self.mbox_uuid = str(uuid4())
        yield self.start_client()

    def tearDown(self):
        set_events_enabled(True)
        self.cleanup()

    @defer.inlineCallbacks
    def _create_mail_in_soledad(self, mail):
        yield self.adaptor.initialize_store(self.soledad)
        mbox = yield self.adaptor.get_or_create_mbox(self.soledad, 'INBOX')
        message = self._convert_mail_to_leap_message(mail, mbox.uuid)
        yield self.adaptor.create_msg(self.soledad, message)

        defer.returnValue(message.get_wrapper().mdoc.doc_id)

    def _convert_mail_to_leap_message(self, mail, mbox_uuid):
        message = self.adaptor.get_msg_from_string(Message, mail.as_string())
        message.get_wrapper().set_mbox_uuid(mbox_uuid)
        return message
class SoledadTestBase(unittest.TestCase, AppTestClient):
    # these are so long because our CI is so slow at the moment.
    DEFERRED_TIMEOUT = 120
    DEFERRED_TIMEOUT_LONG = 300

    @defer.inlineCallbacks
    def setUp(self):
        set_events_enabled(False)
        super(SoledadTestBase, self).setUp()
        self.adaptor = SoledadMailAdaptor()
        self.mbox_uuid = str(uuid4())
        yield self.start_client()

    def tearDown(self):
        set_events_enabled(True)
        self.cleanup()

    @defer.inlineCallbacks
    def _create_mail_in_soledad(self, mail):
        yield self.adaptor.initialize_store(self.soledad)
        mbox = yield self.adaptor.get_or_create_mbox(self.soledad, "INBOX")
        message = self._convert_mail_to_leap_message(mail, mbox.uuid)
        yield self.adaptor.create_msg(self.soledad, message)

        defer.returnValue(message.get_wrapper().mdoc.doc_id)

    def _convert_mail_to_leap_message(self, mail, mbox_uuid):
        message = self.adaptor.get_msg_from_string(Message, mail.as_string())
        message.get_wrapper().set_mbox_uuid(mbox_uuid)
        return message
Ejemplo n.º 3
0
    def get_collection(self, mbox_collection=True, mbox_name=None,
                       mbox_uuid=None):
        """
        Get a collection for tests.
        """
        adaptor = SoledadMailAdaptor()
        store = self._soledad
        adaptor.store = store

        if mbox_collection:
            mbox_indexer = MailboxIndexer(store)
            mbox_name = mbox_name or "TestMbox"
            mbox_uuid = mbox_uuid or str(uuid.uuid4())
        else:
            mbox_indexer = mbox_name = None

        def get_collection_from_mbox_wrapper(wrapper):
            wrapper.uuid = mbox_uuid
            return MessageCollection(
                adaptor, store,
                mbox_indexer=mbox_indexer, mbox_wrapper=wrapper)

        d = adaptor.initialize_store(store)
        if mbox_collection:
            d.addCallback(lambda _: mbox_indexer.create_table(mbox_uuid))
        d.addCallback(lambda _: adaptor.get_or_create_mbox(store, mbox_name))
        d.addCallback(get_collection_from_mbox_wrapper)
        return d
    def add_mail(self, mailbox_name, raw_msg):
        mailbox = yield self._get_or_create_mailbox(mailbox_name)
        message = SoledadMailAdaptor().get_msg_from_string(Message, raw_msg)
        message.get_wrapper().set_mbox_uuid(mailbox.uuid)

        yield SoledadMailAdaptor().create_msg(self.soledad, message)

        # add behavious from insert_mdoc_id from mail.py
        mail = yield self._leap_message_to_leap_mail(message.get_wrapper().mdoc.doc_id, message, include_body=True)  # TODO test that asserts include_body
        defer.returnValue(mail)
    def _attachment_to_cdoc(self, content, content_type, encoder=encoders.encode_base64):
        major, sub = content_type.split('/')
        attachment = MIMENonMultipart(major, sub)
        attachment.set_payload(content)
        encoder(attachment)
        attachment.add_header('Content-Disposition', 'attachment', filename='does_not_matter.txt')

        pseudo_mail = MIMEMultipart()
        pseudo_mail.attach(attachment)

        tmp_mail = SoledadMailAdaptor().get_msg_from_string(MessageClass=Message, raw_msg=pseudo_mail.as_string())

        cdoc = tmp_mail.get_wrapper().cdocs[1]
        return cdoc
Ejemplo n.º 6
0
def initialize_soledad(tempdir):
    if os.path.isdir(tempdir):
        shutil.rmtree(tempdir)

    uuid = "foobar-uuid"
    passphrase = u"verysecretpassphrase"
    secret_path = os.path.join(tempdir, "secret.gpg")
    local_db_path = os.path.join(tempdir, "soledad.u1db")
    server_url = "http://provider"
    cert_file = ""

    class MockSharedDB(object):
        get_doc = Mock(return_value=None)
        put_doc = Mock()
        lock = Mock(return_value=('atoken', 300))
        unlock = Mock(return_value=True)
        close = Mock()

        def __call__(self):
            return self

    Soledad._shared_db = MockSharedDB()

    _soledad = Soledad(uuid,
                       passphrase,
                       secret_path,
                       local_db_path,
                       server_url,
                       cert_file,
                       defer_encryption=False,
                       syncable=False)

    yield SoledadMailAdaptor().initialize_store(_soledad)

    defer.returnValue(_soledad)
Ejemplo n.º 7
0
 def _get_or_create_mailbox(self, mailbox_name):
     mailbox_name_upper = mailbox_name.upper()
     mbx = yield SoledadMailAdaptor().get_or_create_mbox(
         self.soledad, mailbox_name_upper)
     if mbx.uuid is None:
         mbx.uuid = str(uuid4())
         yield mbx.update(self.soledad)
     defer.returnValue(mbx)
Ejemplo n.º 8
0
    def _attachment_to_cdoc(self,
                            content,
                            content_type,
                            encoder=encoders.encode_base64):
        major, sub = content_type.split('/')
        attachment = MIMENonMultipart(major, sub)
        attachment.set_payload(content)
        encoder(attachment)
        attachment.add_header('Content-Disposition',
                              'attachment',
                              filename='does_not_matter.txt')

        pseudo_mail = MIMEMultipart()
        pseudo_mail.attach(attachment)

        tmp_mail = SoledadMailAdaptor().get_msg_from_string(
            MessageClass=Message, raw_msg=pseudo_mail.as_string())

        cdoc = tmp_mail.get_wrapper().cdocs[1]
        return cdoc
Ejemplo n.º 9
0
    def _convert_mail_to_leap_message(self, mail, mbox_uuid=None):
        msg = SoledadMailAdaptor().get_msg_from_string(Message, mail.as_string())
        if mbox_uuid is None:
            msg.get_wrapper().set_mbox_uuid(self.mbox_uuid)
        else:
            msg.get_wrapper().set_mbox_uuid(mbox_uuid)

        return msg
Ejemplo n.º 10
0
    def add_mail(self, mailbox_name, raw_msg):
        mailbox = yield self._get_or_create_mailbox(mailbox_name)
        message = SoledadMailAdaptor().get_msg_from_string(Message, raw_msg)
        message.get_wrapper().set_mbox_uuid(mailbox.uuid)

        yield SoledadMailAdaptor().create_msg(self.soledad, message)

        # add behavious from insert_mdoc_id from mail.py
        mail = yield self._leap_message_to_leap_mail(
            message.get_wrapper().mdoc.doc_id, message,
            include_body=True)  # TODO test that asserts include_body
        defer.returnValue(mail)
Ejemplo n.º 11
0
 def setUp(self):
     set_events_enabled(False)
     super(SoledadTestBase, self).setUp()
     self.adaptor = SoledadMailAdaptor()
     self.mbox_uuid = str(uuid4())
     yield self.start_client()
Ejemplo n.º 12
0
 def _fetch_msg_from_soledad(self, mail_id, load_body=False):
     return SoledadMailAdaptor().get_msg_from_mdoc_id(Message,
                                                      self.soledad,
                                                      mail_id,
                                                      get_cdocs=load_body)
Ejemplo n.º 13
0
 def delete_mailbox(self, mailbox_name):
     mbx_wrapper = yield self._get_or_create_mailbox(mailbox_name)
     yield SoledadMailAdaptor().delete_mbox(self.soledad, mbx_wrapper)
 def setUp(self):
     set_events_enabled(False)
     super(SoledadTestBase, self).setUp()
     self.adaptor = SoledadMailAdaptor()
     self.mbox_uuid = str(uuid4())
     yield self.start_client()
Ejemplo n.º 15
0
 def get_adaptor(self):
     adaptor = SoledadMailAdaptor()
     adaptor.store = self._soledad
     return adaptor
Ejemplo n.º 16
0
 def get_adaptor(self):
     adaptor = SoledadMailAdaptor()
     adaptor.store = self._soledad
     return adaptor