def _messageWithPostiniHeader(self, header): part = Part() part.addHeader(u"X-pstn-levels", unicode(header)) msg = Message(store=self.store) # part._addToStore(self.store, msg, None) part.associateWithMessage(msg) msg.impl = part return msg
def testPreferredFormat(self): """ Make sure that we are sent the preferred type of text/html. """ s = Store() m = Message(store=s) impl = PartItem(store=s) m.impl = impl installOn(PreferenceAggregator(store=s), s) mdp = MessageDisplayPreferenceCollection(store=s) installOn(mdp, s) m.walkMessage() self.assertEqual(impl.preferred, 'text/html')
def test_retrain(self): """ Verify that retraining a few messages will tell our new test filter to learn about a bunch of new messages. """ f = Filter(store=self.store) installOn(f, self.store) tf = TestFilter(store=self.store, test=self) installOn(tf, self.store) COUNT = 10 for j in range(2): for x in range(COUNT): msg = Message.createIncoming( self.store, DummyMessageImplementation(store=self.store), u"test://retrain" ) _spamState(msg, (x % 2), j) # This isn't quite correct. We're relying on the fact that the batch # processor is supposed to run in a subprocess (which isn't going) so # the callback is only going to be triggered for our set of messages # during the test. Bleah. def _(ign): self.assertEquals(tf.trainCount, COUNT) return f.retrain().addCallback(_)
def test_draft(self): """ Verify that a draft is not focused. """ impl = Part() message = Message.createDraft( self.userStore, impl, u'test://test_draft') self.focus.processItem(message) statuses = set(message.iterStatuses()) self.failIfIn(FOCUS_STATUS, statuses)
def setUp(self): """ Make a draft message using an L{xquotient.iquotient.IMessageData} with a bunch of related addresses """ self.store = Store() self.messageData = DummyMessageImplWithABunchOfAddresses( store=self.store) self.message = Message.createDraft( self.store, self.messageData, u'test')
def test_postiniWithoutHeaderHamFiltering(self): """ Check that when postini filtering is enabled but a message has no postini header then the other filter is consulted. """ msg = Message.createIncoming(self.store, Part(), u"test://postiniWithoutHeaderHamFiltering") f = Filter(store=self.store, usePostiniScore=True, postiniThreshhold=1.0) installOn(TestFilter(store=self.store, result=False), self.store) f.processItem(msg) self.assertNotIn(SPAM_STATUS, list(msg.iterStatuses()))
def test_outbox(self): """ Verify that a message in the outbox is not focused. """ impl = Part() message = Message.createDraft( self.userStore, impl, u'test://test_outbox') message.startedSending() self.focus.processItem(message) statuses = set(message.iterStatuses()) self.failIfIn(FOCUS_STATUS, statuses)
def createDatabase(s): """ Populate the given Store with a deferred message. """ messageData = DummyMessageImplementation(store=s) fakeScheduler = FakeScheduler(store=s) s.powerUp(fakeScheduler, IScheduler) m = Message.createIncoming(s, messageData, u"test") m.classifyClean() m.markRead() now = Time() m.deferFor(timedelta(days=1), timeFactory=lambda: now)
def test_bounced(self): """ Verify that a message which has bounced is not focused. """ impl = Part() message = Message.createDraft( self.userStore, impl, u'test://test_bounced') message.startedSending() message.allBounced() self.focus.processItem(message) statuses = set(message.iterStatuses()) self.failIfIn(FOCUS_STATUS, statuses)
def test_partiallySent(self): """ Verify that a message which has been sent to one recipient is not focused. """ impl = Part() message = Message.createDraft( self.userStore, impl, u'test://test_partiallySent') message.startedSending() message.sent() self.focus.processItem(message) statuses = set(message.iterStatuses()) self.failIfIn(FOCUS_STATUS, statuses)
def test_nonPart(self): """ Test that a message with an implementation which isn't a L{Part} that the Message doesn't get focused. This is primarily here for completeness at this point. The only non-Part Messages which exist are probably created by the test suite. """ impl = DummyMessageImplementation(store=self.userStore) message = Message.createIncoming( self.userStore, impl, u'test://test_nonPart') self.focus.processItem(message) statuses = set(message.iterStatuses()) self.failIfIn(FOCUS_STATUS, statuses)
class DeletionTestCase(TestCase): """ Tests for the interaction between message deletion and the indexer. """ def setUp(self): """ Create a Store with a Message in it. """ self.store = Store() self.message = Message(store=self.store) def test_deletionNotification(self): """ Test that when a Message is deleted, all L{ixmantissa.IFulltextIndexer} powerups on that message's store are notified of the event. """ indexers = [] for i in range(2): indexers.append(DummyIndexer(store=self.store)) self.store.powerUp(indexers[-1], ixmantissa.IFulltextIndexer) self.assertEqual(indexers[-1].removed, []) self.message.deleteFromStore() for i in range(2): self.assertEqual(indexers[i].removed, [self.message]) def test_deletionWithoutIndexers(self): """ Test that deletion of a message can succeed even if there are no L{ixmantissa.IFulltextIndexer} powerups on the message's store. """ self.message.deleteFromStore() self.assertEqual(list(self.store.query(Message)), [])
def testEZMLMFilter(self): """ Ensure that match_EZMLM doesn't kerplode when presented with a header that doesn't parse well. """ part = Part() part.addHeader(u'X-Mailman-Version', u"2.1.5") part.addHeader(u'List-Post', u"Random bytes") part.source = FilePath(self.storepath).child("files").child("x") msg = Message.createIncoming(self.store, part, u'test://test_mailing_list_filter') self.mlfp.processItem(msg) self.assertEqual(list(self.tagcatalog.tagsOf(msg)), [])
def _setUpMsg(self): """ Install an innocuous incoming message in a newly-created store @rtype: L{xquotient.exmess.Message} """ s = self._setUpStore() m = Message.createIncoming(s, _Part(store=s), u'test://test') m.subject = u'the subject' m.sender = u'sender@host' m.senderDisplay = u'Sender' m.recipient = u'recipient@host' m.sentWhen = Time.fromPOSIXTimestamp(0) m.receivedWhen = Time.fromPOSIXTimestamp(1) m.classifyClean() return m
def testMailingListFilter(self): """ Ensures that mailing list messages are not handled by RuleFilteringPowerup but are handled by MailingListFilteringPowerup. """ part = Part() part.addHeader(u'X-Mailman-Version', u"2.1.5") part.addHeader(u'List-Id', u"Some mailing list <some-list.example.com>") part.source = FilePath(self.storepath).child("files").child("x") msg = Message.createIncoming(self.store, part, u'test://test_mailing_list_filter') self.rfp.processItem(msg) self.assertEqual(list(self.tagcatalog.tagsOf(msg)), []) self.mlfp.processItem(msg) self.assertEqual(list(self.tagcatalog.tagsOf(msg)), [u'some-list.example.com'])
def createDatabase(s): Message(store=s, impl=Part(store=s), **attrs)
def createDatabase(s): Inbox(store=s) Message(store=s, source=u'source one') Message(store=s, source=u'source one') Message(store=s, source=u'source two')
def setUp(self): """ Create a Store with a Message in it. """ self.store = Store() self.message = Message(store=self.store)
def _focusedTest(self, part): message = Message.createIncoming( self.userStore, part, u'test://test_otherPrecedence') self.focus.processItem(message) statuses = set(message.iterStatuses()) self.failUnlessIn(FOCUS_STATUS, statuses)
def testMessageFactory(store, archived=False, spam=None, read=False, sentWhen=None, receivedWhen=None, subject=u'', trash=False, outgoing=False, draft=False, impl=None, sent=True, bounced=False, sender=None, recipient=u''): """ Provide a simulacrum of message's old constructor signature to avoid unnecessarily deep modification of tests. @return: an exmess.Message object. """ if impl is None: impl = DummyMessageImplementation(store=store) if sender is not None: impl.senderInfo = sender if outgoing: m = Message.createDraft(store, impl, u'test://test/draft') if not draft: # XXX: this is *actually* the status change that transpires when # you transition a message from "draft" to "sent" status. m.startedSending() if sent: m.sent() m.finishedSending() elif bounced: m.allBounced() if spam is not None: assert spam is False, "That doesn't make any sense." else: m = Message.createIncoming(store, impl, u'test://test') if spam is not None: if spam: m.classifySpam() else: m.classifyClean() m.subject = subject m.recipient = recipient # should this be handled somewhere else? ugh. if read: m.markRead() if archived: m.archive() if trash: m.moveToTrash() # these next bits are definitely wrong. they should be set up by analysis # of the body part, probably? if receivedWhen: m.receivedWhen = receivedWhen # we're supplying our own received date, after message creation, but # this won't be reflected in the statusDate of the statuses that were # added to the message as a result of createIncoming, so we'll remove # them all and re-add them for s in m.iterStatuses(): m.removeStatus(s) m.addStatus(s) if sentWhen: m.sentWhen = sentWhen if sender: m.sender = sender m.senderDisplay = sender # Cheat so that nit test setup will work; this is gross, but inverting # it to be specified properly (in the tests' impl) would be even more # of a pain in the ass right now... -glyph Correspondent(store=store, relation=SENDER_RELATION, message=m, address=sender) return m
def _unfocusedTest(self, part): message = Message.createIncoming( self.userStore, part, u'test://unfocused') self.focus.processItem(message) statuses = set(message.iterStatuses()) self.failIfIn(FOCUS_STATUS, statuses)
def testDeletion(self): s = Store() m = Message(store=s) m.deleteFromStore()