コード例 #1
0
class MoreComposeActionsTestCase(TestCase):
    """
    Test compose-action related stuff that requires an on-disk store.
    """
    def setUp(self):
        self.store = Store(dbdir=self.mktemp())

        installOn(inbox.Inbox(store=self.store), self.store)
        self.composer = compose.Composer(store=self.store)
        installOn(self.composer, self.store)

        LoginMethod(store=self.store,
                    internal=False,
                    protocol=u'email',
                    localpart=u'recipient',
                    domain=u'host',
                    verified=True,
                    account=self.store)

        self.msg = testMessageFactory(
            store=self.store,
            spam=False,
            impl=DummyMessageImplWithABunchOfAddresses(store=self.store))
        self.msgDetail = MessageDetail(self.msg)

    def test_setStatus(self):
        """
        Test that statuses requested for parent messages get set after
        the created message is sent.
        """
        # (bypass Item.__setattr__)
        object.__setattr__(self.composer, 'sendMessage',
                           lambda fromA, toA, msg: None)

        class MsgStub:
            impl = MIMEPart()
            statuses = None

            def addStatus(self, status):
                if self.statuses is None:
                    self.statuses = [status]
                else:
                    self.statuses.append(status)

        parent = MsgStub()
        parent.impl.headers = [
            Header("message-id", "<*****@*****.**>"),
            Header("references", "<*****@*****.**>"),
            Header("references", "<*****@*****.**>")
        ]

        toAddresses = [
            mimeutil.EmailAddress('*****@*****.**', mimeEncoded=False)
        ]
        cf = self.msgDetail._composeSomething(toAddresses, u'Sup dood',
                                              u'A body', [], parent,
                                              REPLIED_STATUS)
        cf._sendOrSave(self.store.findFirst(smtpout.FromAddress), toAddresses,
                       u'Sup dood', u'A body', [], [], [], False)
        self.assertEqual(parent.statuses, [REPLIED_STATUS])
コード例 #2
0
ファイル: test_message.py プロジェクト: pombredanne/quotient
class MoreComposeActionsTestCase(TestCase):
    """
    Test compose-action related stuff that requires an on-disk store.
    """

    def setUp(self):
        self.store = Store(dbdir=self.mktemp())

        installOn(inbox.Inbox(store=self.store), self.store)
        self.composer = compose.Composer(store=self.store)
        installOn(self.composer, self.store)

        LoginMethod(store=self.store, internal=False, protocol=u'email',
                localpart=u'recipient', domain=u'host', verified=True,
                account=self.store)

        self.msg = testMessageFactory(
                    store=self.store,
                    spam=False,
                    impl=DummyMessageImplWithABunchOfAddresses(store=self.store))
        self.msgDetail = MessageDetail(self.msg)



    def test_setStatus(self):
        """
        Test that statuses requested for parent messages get set after
        the created message is sent.
        """
        # (bypass Item.__setattr__)
        object.__setattr__(self.composer, 'sendMessage',
                           lambda fromA, toA, msg: None)
        class MsgStub:
            impl = MIMEPart()
            statuses = None
            def addStatus(self, status):
                if self.statuses is None:
                    self.statuses = [status]
                else:
                    self.statuses.append(status)

        parent = MsgStub()
        parent.impl.headers = [Header("message-id", "<*****@*****.**>"),
                               Header("references", "<*****@*****.**>"),
                               Header("references", "<*****@*****.**>")]

        toAddresses = [mimeutil.EmailAddress(
            '*****@*****.**',
            mimeEncoded=False)]
        cf = self.msgDetail._composeSomething(
            toAddresses,
            u'Sup dood', u'A body', [], parent, REPLIED_STATUS)
        cf._sendOrSave(self.store.findFirst(smtpout.FromAddress),
                       toAddresses, u'Sup dood', u'A body',
                       [], [], [], False)
        self.assertEqual(parent.statuses, [REPLIED_STATUS])
コード例 #3
0
class ComposeActionsTestCase(TestCase):
    """
    Tests for the compose-related actions of L{xquotient.exmess.MessageDetail}
    (reply, forward, etc) and related functionality
    """
    def setUp(self):
        # XXX Incorrect setup.  See xquotient.test.test_compose.CompositionTestMixin
        self.store = Store(self.mktemp())

        LoginMethod(store=self.store,
                    internal=False,
                    protocol=u'email',
                    localpart=u'recipient',
                    domain=u'host',
                    verified=True,
                    account=self.store)

        self.fromAddr = smtpout.FromAddress(address=u'recipient@host',
                                            store=self.store)
        self.inbox = inbox.Inbox(store=self.store)
        installOn(self.inbox, self.store)
        self.composer = compose.Composer(store=self.store)
        installOn(self.composer, self.store)
        self.defaultFromAddress = self.store.findUnique(
            smtpout.FromAddress, smtpout.FromAddress._address == None)

        self.message = testMessageFactory(
            store=self.store,
            spam=False,
            impl=DummyMessageImplWithABunchOfAddresses(store=self.store))
        self.messageDetail = MessageDetail(self.message)

    def _recipientsToStrings(self, recipients):
        """
        Convert a mapping of "strings to lists of
        L{xquotient.mimeutil.EmailAddress} instances" into a mapping of
        "strings to lists of string email addresses"
        """
        result = {}
        for (k, v) in recipients.iteritems():
            result[k] = list(e.email for e in v)
        return result

    def test_replyToAll(self):
        """
        Test L{xquotient.exmess.MessageDetail.replyAll}
        """
        self.assertEquals(
            self._recipientsToStrings(
                self.messageDetail.replyAll().recipients), {
                    'bcc': ['blind-copy@host'],
                    'cc': ['copy@host'],
                    'to': ['sender@host', 'recipient2@host']
                })

    def test_replyToAllFromAddress(self):
        """
        Test that L{xquotient.exmess.MessageDetail.replyAll} doesn't include
        addresses of L{xquotient.smtpout.FromAddress} items that exist in the
        same store as the message that is being replied to
        """
        addrs = set(
            u'blind-copy@host copy@host sender@host recipient2@host'.split())
        for addr in addrs:
            fromAddr = smtpout.FromAddress(address=addr,
                                           store=self.message.store)
            gotAddrs = set()
            for l in self.messageDetail.replyAll().recipients.itervalues():
                gotAddrs.update(e.email for e in l)
            self.assertEquals(gotAddrs, addrs - set([addr]))
            fromAddr.deleteFromStore()

    def test_createDraftComposeFragment(self):
        """
        Verify that an instance of L{DraftComposeFragment} which refers
        to the correct draft item is returned by L{InboxScreen.editDraft}.
        """
        fragment = self.messageDetail.editDraft()
        self.failUnless(
            isinstance(fragment, compose.DraftComposeFragment),
            "Got %r instead of DraftComposeFragment" % (fragment, ))
        self.assertIdentical(fragment._savedDraft, self.message)

    def test_slotData(self):
        """
        Verify that L{DraftComposeFragment.slotData} returns a dictionary
        which reflects the message which was used as the draft.
        """
        subject = u'subject text'
        body = u'hello, world?\n'
        to = u'*****@*****.**'
        cc = u'*****@*****.**'
        bcc = u'*****@*****.**'
        message = createMessage(
            self.composer,
            None,
            None,
            self.defaultFromAddress,
            [mimeutil.EmailAddress(to, mimeEncoded=False)],
            subject,
            body,
            [mimeutil.EmailAddress(cc, mimeEncoded=False)],
            [mimeutil.EmailAddress(bcc, mimeEncoded=False)],
            [],
        )
        fragment = self.messageDetail._composeSomething(draft=message)
        slotData = fragment.slotData()
        self.assertEqual(slotData['to'], to)
        self.assertEqual(slotData['from'][0], self.defaultFromAddress)
        self.assertEqual(slotData['subject'], subject)
        self.assertEqual(slotData['message-body'], body)
        self.assertEqual(slotData['cc'], cc)

        # XXX This assertion should succeed.
        # self.assertEqual(slotData['bcc'], bcc)

    def test_addPersonForm(self):
        """
        Test that the add-person form is created correctly.
        """
        installOn(people.AddPerson(store=self.store), self.store)
        apf = self.messageDetail.render_addPersonFragment(None, None)
        self.assertEquals(apf.organizer,
                          self.store.findUnique(people.Organizer))
コード例 #4
0
ファイル: test_message.py プロジェクト: pombredanne/quotient
class ComposeActionsTestCase(TestCase):
    """
    Tests for the compose-related actions of L{xquotient.exmess.MessageDetail}
    (reply, forward, etc) and related functionality
    """
    def setUp(self):
        # XXX Incorrect setup.  See xquotient.test.test_compose.CompositionTestMixin
        self.store = Store(self.mktemp())

        LoginMethod(store=self.store, internal=False, protocol=u'email',
                localpart=u'recipient', domain=u'host', verified=True,
                account=self.store)

        self.fromAddr = smtpout.FromAddress(
            address=u'recipient@host', store=self.store)
        self.inbox = inbox.Inbox(store=self.store)
        installOn(self.inbox, self.store)
        self.composer = compose.Composer(store=self.store)
        installOn(self.composer, self.store)
        self.defaultFromAddress = self.store.findUnique(
            smtpout.FromAddress, smtpout.FromAddress._address == None)

        self.message = testMessageFactory(
                    store=self.store,
                    spam=False,
                    impl=DummyMessageImplWithABunchOfAddresses(store=self.store))
        self.messageDetail = MessageDetail(self.message)


    def _recipientsToStrings(self, recipients):
        """
        Convert a mapping of "strings to lists of
        L{xquotient.mimeutil.EmailAddress} instances" into a mapping of
        "strings to lists of string email addresses"
        """
        result = {}
        for (k, v) in recipients.iteritems():
            result[k] = list(e.email for e in v)
        return result


    def test_replyToAll(self):
        """
        Test L{xquotient.exmess.MessageDetail.replyAll}
        """
        self.assertEquals(
            self._recipientsToStrings(
                self.messageDetail.replyAll().recipients),
            {'bcc': ['blind-copy@host'],
             'cc': ['copy@host'],
             'to': ['sender@host', 'recipient2@host']})


    def test_replyToAllFromAddress(self):
        """
        Test that L{xquotient.exmess.MessageDetail.replyAll} doesn't include
        addresses of L{xquotient.smtpout.FromAddress} items that exist in the
        same store as the message that is being replied to
        """
        addrs = set(u'blind-copy@host copy@host sender@host recipient2@host'.split())
        for addr in addrs:
            fromAddr = smtpout.FromAddress(address=addr, store=self.message.store)
            gotAddrs = set()
            for l in self.messageDetail.replyAll().recipients.itervalues():
                gotAddrs.update(e.email for e in l)
            self.assertEquals(
                gotAddrs,
                addrs - set([addr]))
            fromAddr.deleteFromStore()


    def test_createDraftComposeFragment(self):
        """
        Verify that an instance of L{DraftComposeFragment} which refers
        to the correct draft item is returned by L{InboxScreen.editDraft}.
        """
        fragment = self.messageDetail.editDraft()
        self.failUnless(
            isinstance(fragment, compose.DraftComposeFragment),
            "Got %r instead of DraftComposeFragment" % (fragment,))
        self.assertIdentical(fragment._savedDraft, self.message)


    def test_slotData(self):
        """
        Verify that L{DraftComposeFragment.slotData} returns a dictionary
        which reflects the message which was used as the draft.
        """
        subject = u'subject text'
        body = u'hello, world?\n'
        to = u'*****@*****.**'
        cc = u'*****@*****.**'
        bcc = u'*****@*****.**'
        message = createMessage(
            self.composer,
            None,
            None,
            self.defaultFromAddress,
            [mimeutil.EmailAddress(to, mimeEncoded=False)],
            subject,
            body,
            [mimeutil.EmailAddress(cc, mimeEncoded=False)],
            [mimeutil.EmailAddress(bcc, mimeEncoded=False)],
            [],
            )
        fragment = self.messageDetail._composeSomething(draft=message)
        slotData = fragment.slotData()
        self.assertEqual(slotData['to'], to)
        self.assertEqual(slotData['from'][0], self.defaultFromAddress)
        self.assertEqual(slotData['subject'], subject)
        self.assertEqual(slotData['message-body'], body)
        self.assertEqual(slotData['cc'], cc)

        # XXX This assertion should succeed.
        # self.assertEqual(slotData['bcc'], bcc)



    def test_addPersonForm(self):
        """
        Test that the add-person form is created correctly.
        """
        installOn(people.AddPerson(store=self.store), self.store)
        apf = self.messageDetail.render_addPersonFragment(None, None)
        self.assertEquals(apf.organizer,
                          self.store.findUnique(people.Organizer))