Esempio n. 1
0
 def test_clear(self):
     # Clearing the cache gets rid of all entries, regardless of lifetime.
     self._cachemgr.add('abc', 'xyz', lifetime=timedelta(hours=3))
     self._cachemgr.add('def', 'uvw')
     self.assertEqual(self._cachemgr.get('abc'), 'xyz')
     self.assertEqual(self._cachemgr.get('def'), 'uvw')
     factory.fast_forward(days=1)
     self._cachemgr.clear()
     self.assertIsNone(self._cachemgr.get('abc'))
     self.assertIsNone(self._cachemgr.get('xyz'))
Esempio n. 2
0
 def test_evict(self):
     # Evicting all expired cache entries makes them inaccessible.
     self._cachemgr.add('abc', 'xyz', lifetime=timedelta(hours=3))
     self._cachemgr.add('def', 'uvw', lifetime=timedelta(days=3))
     self.assertEqual(self._cachemgr.get('abc'), 'xyz')
     self.assertEqual(self._cachemgr.get('def'), 'uvw')
     factory.fast_forward(days=1)
     self._cachemgr.evict()
     self.assertIsNone(self._cachemgr.get('abc'))
     self.assertEqual(self._cachemgr.get('def'), 'uvw')
Esempio n. 3
0
 def test_bump_monthly_not_yet(self):
     # The normal test date starts on the first day of the month, so let's
     # fast forward it a few days so we can set the digest last sent time
     # to earlier in the same month.
     self._mlist.digest_last_sent_at = self.right_now
     factory.fast_forward(days=26)
     self._mlist.digest_volume_frequency = DigestFrequency.monthly
     bump_digest_number_and_volume(self._mlist)
     self.assertEqual(self._mlist.volume, 7)
     self.assertEqual(self._mlist.next_digest_number, 5)
     self.assertEqual(self._mlist.digest_last_sent_at, right_now())
Esempio n. 4
0
 def test_bump_monthly_not_yet(self):
     # The normal test date starts on the first day of the month, so let's
     # fast forward it a few days so we can set the digest last sent time
     # to earlier in the same month.
     self._mlist.digest_last_sent_at = self.right_now
     factory.fast_forward(days=26)
     self._mlist.digest_volume_frequency = DigestFrequency.monthly
     bump_digest_number_and_volume(self._mlist)
     self.assertEqual(self._mlist.volume, 7)
     self.assertEqual(self._mlist.next_digest_number, 5)
     self.assertEqual(self._mlist.digest_last_sent_at, right_now())
Esempio n. 5
0
 def test_clobber_date_maybe_when_sane(self):
     # The date is not clobbered if it's nearer to now than its skew
     # period.
     self._msg['Date'] = now(strip_tzinfo=False).strftime(RFC822_DATE_FMT)
     # Now, before enqueuing the message (well, really, calling 'now()'
     # again as will happen in the runner), fast forward a few days.
     self._archiveq.enqueue(self._msg, {}, listid=self._mlist.list_id)
     factory.fast_forward(days=4)
     self._runner.run()
     # There should now be a copy of the message in the file system.
     filename = os.path.join(config.MESSAGES_DIR,
                             '4CMWUN6BHVCMHMDAOSJZ2Q72G5M32MWB')
     with open(filename) as fp:
         archived = message_from_file(fp)
     self.assertEqual(archived['message-id'], '<first>')
     self.assertEqual(archived['date'], 'Mon, 01 Aug 2005 07:49:23 +0000')
     self.assertEqual(archived['x-original-date'], None)
Esempio n. 6
0
 def test_clobber_date_maybe_when_sane(self):
     # The date is not clobbered if it's nearer to now than its skew
     # period.
     self._msg['Date'] = now(strip_tzinfo=False).strftime(RFC822_DATE_FMT)
     # Now, before enqueuing the message (well, really, calling 'now()'
     # again as will happen in the runner), fast forward a few days.
     self._archiveq.enqueue(
         self._msg, {},
         listid=self._mlist.list_id)
     factory.fast_forward(days=4)
     self._runner.run()
     # There should now be a copy of the message in the file system.
     filename = os.path.join(
         config.MESSAGES_DIR, '4CMWUN6BHVCMHMDAOSJZ2Q72G5M32MWB')
     with open(filename) as fp:
         archived = message_from_file(fp)
     self.assertEqual(archived['message-id'], '<first>')
     self.assertEqual(archived['date'], 'Mon, 01 Aug 2005 07:49:23 +0000')
     self.assertEqual(archived['x-original-date'], None)
Esempio n. 7
0
 def test_clobber_date_always(self):
     # The date always gets clobbered with the current received time.
     self._msg['Date'] = now(strip_tzinfo=False).strftime(RFC822_DATE_FMT)
     # Now, before enqueuing the message (well, really, calling 'now()'
     # again as will happen in the runner), fast forward a few days.
     self._archiveq.enqueue(
         self._msg, {},
         listname=self._mlist.fqdn_listname)
     factory.fast_forward(days=4)
     self._runner.run()
     # There should now be a copy of the message in the file system.
     filename = os.path.join(
         config.MESSAGES_DIR, '4CMWUN6BHVCMHMDAOSJZ2Q72G5M32MWB')
     with open(filename) as fp:
         archived = message_from_file(fp)
     self.assertEqual(archived['message-id'], '<first>')
     self.assertEqual(archived['date'], 'Fri, 05 Aug 2005 07:49:23 +0000')
     self.assertEqual(archived['x-original-date'],
                      'Mon, 01 Aug 2005 07:49:23 +0000')
Esempio n. 8
0
 def test_no_progress_on_retries_with_expired_retry_period(self):
     # We've had temporary failures with no progress, and the retry period
     # has expired.  In that case, a log entry is written and message is
     # discarded.  There's nothing more that can be done.
     temporary_failures.append('*****@*****.**')
     temporary_failures.append('*****@*****.**')
     retry_period = as_timedelta(config.mta.delivery_retry_period)
     deliver_until = datetime(2005, 8, 1, 7, 49, 23) + retry_period
     msgdata = dict(last_recip_count=2, deliver_until=deliver_until)
     self._outq.enqueue(self._msg, msgdata, listid='test.example.com')
     # Before the runner runs, several days pass.
     factory.fast_forward(retry_period.days + 1)
     mark = LogFileMark('mailman.smtp')
     self._runner.run()
     # There should be no message in the retry or outgoing queues.
     get_queue_messages('retry', expected_count=0)
     get_queue_messages('out', expected_count=0)
     # There should be a log message in the smtp log indicating that the
     # message has been discarded.
     line = mark.readline()
     self.assertEqual(
         line[-63:-1],
         'Discarding message with persistent temporary failures: <first>')
Esempio n. 9
0
 def test_no_progress_on_retries_with_expired_retry_period(self):
     # We've had temporary failures with no progress, and the retry period
     # has expired.  In that case, a log entry is written and message is
     # discarded.  There's nothing more that can be done.
     temporary_failures.append('*****@*****.**')
     temporary_failures.append('*****@*****.**')
     retry_period = as_timedelta(config.mta.delivery_retry_period)
     deliver_until = datetime(2005, 8, 1, 7, 49, 23) + retry_period
     msgdata = dict(last_recip_count=2,
                    deliver_until=deliver_until)
     self._outq.enqueue(self._msg, msgdata, listid='test.example.com')
     # Before the runner runs, several days pass.
     factory.fast_forward(retry_period.days + 1)
     mark = LogFileMark('mailman.smtp')
     self._runner.run()
     # There should be no message in the retry or outgoing queues.
     get_queue_messages('retry', expected_count=0)
     get_queue_messages('out', expected_count=0)
     # There should be a log message in the smtp log indicating that the
     # message has been discarded.
     line = mark.readline()
     self.assertEqual(
         line[-63:-1],
         'Discarding message with persistent temporary failures: <first>')