예제 #1
0
    def testMostRecentMessages(self):
        s = Store()

        o = Organizer(store=s)
        installOn(o, s)

        def makePerson(name, address):
            return EmailAddress(store=s,
                                address=address,
                                person=Person(store=s,
                                              organizer=o,
                                              name=name)).person

        p11 = makePerson(u'11 Message Person', u'11@person')
        p2  = makePerson(u'2 Message Person', u'2@person')

        def makeMessages(n, email):
            return list(reversed(list(
                        testMessageFactory(store=s,
                                           subject=u'Message %d' % (i,),
                                           sender=email,
                                           spam=False,
                                           receivedWhen=Time())
                        for i in xrange(n))))

        p11messages = makeMessages(11, u'11@person')
        p2messages  = makeMessages(2, u'2@person')

        lister = MessageLister(store=s)

        getMessages = lambda person, count: list(
            lister.mostRecentMessages(person, count))

        self.assertEquals(getMessages(p2, 3), p2messages)
        self.assertEquals(getMessages(p2, 2), p2messages)
        self.assertEquals(getMessages(p2, 1), p2messages[:-1])

        self.assertEquals(getMessages(p11, 12), p11messages)
        self.assertEquals(getMessages(p11, 11), p11messages)
        self.assertEquals(getMessages(p11, 10), p11messages[:-1])

        p11messages[0].trainSpam()

        self.assertEquals(getMessages(p11, 11), p11messages[1:])

        # Used to be:
        # p11messages[1].draft = True
        # but this is now a nonsensical transition.
        p11messages[1].trainSpam()

        self.assertEquals(getMessages(p11, 11), p11messages[2:])

        p11messages[2].moveToTrash()

        self.assertEquals(getMessages(p11, 11), p11messages[3:])
예제 #2
0
    def test_peopleMessageListRendering(self):
        mlister = MessageLister(store=self.substore)
        installOn(mlister, self.substore)

        p = Person(store=self.substore, name=u'Bob')

        EmailAddress(store=self.substore, person=p, address=u'bob@internet')

        for i in xrange(5):
            testMessageFactory(
                store=self.substore, subject=unicode(str(i)),
                receivedWhen=Time(), spam=False, sender=u'bob@internet')


        self.assertEqual(len(list(mlister.mostRecentMessages(p))), 5)
        return renderPage(
            rend.Page(docFactory=loaders.stan(MessageList(mlister, p))))
예제 #3
0
    def test_peopleMessageListRendering(self):
        mlister = MessageLister(store=self.substore)
        installOn(mlister, self.substore)

        p = Person(store=self.substore, name=u'Bob')

        EmailAddress(store=self.substore, person=p, address=u'bob@internet')

        for i in xrange(5):
            testMessageFactory(store=self.substore,
                               subject=unicode(str(i)),
                               receivedWhen=Time(),
                               spam=False,
                               sender=u'bob@internet')

        self.assertEqual(len(list(mlister.mostRecentMessages(p))), 5)
        return renderPage(
            rend.Page(docFactory=loaders.stan(MessageList(mlister, p))))
    def getInbox(self):
        """
        Return a newly created Inbox, in a newly created Store.
        """
        s = Store()
        LoginMethod(store=s,
                    internal=False,
                    protocol=u'email',
                    localpart=u'default',
                    domain=u'host',
                    verified=True,
                    account=s)

        installOn(Composer(store=s), s)
        installOn(Catalog(store=s), s)
        installOn(MessageLister(store=s), s)
        inbox = Inbox(store=s)
        installOn(inbox, s)
        return inbox
예제 #5
0
def createDatabase(s):
    Organizer(store=s).installOn(s)
    MessageLister(store=s).installOn(s)