def test_bump_before_send(self): with transaction(): self._mlist.digest_volume_frequency = DigestFrequency.monthly self._mlist.volume = 7 self._mlist.next_digest_number = 4 self._mlist.digest_last_sent_at = right_now() + timedelta( days=-32) msg = mfs("""\ To: [email protected] From: [email protected] Subject: message 1 """) config.handlers['to-digest'].process(self._mlist, msg, {}) json, response = call_api( 'http://localhost:9001/3.0/lists/ant.example.com/digest', dict( send=True, bump=True)) self.assertEqual(response.status_code, 202) make_testable_runner(DigestRunner, 'digest').run() # The volume is 8 and the digest number is 2 because a digest was sent # after the volume/number was bumped. self.assertEqual(self._mlist.volume, 8) self.assertEqual(self._mlist.next_digest_number, 2) self.assertEqual(self._mlist.digest_last_sent_at, right_now()) items = get_queue_messages('virgin') self.assertEqual(len(items), 1) self.assertEqual(items[0].msg['subject'], 'Ant Digest, Vol 8, Issue 1')
def test_bump_before_send(self): self._mlist.digest_volume_frequency = DigestFrequency.monthly self._mlist.volume = 7 self._mlist.next_digest_number = 4 self._mlist.digest_last_sent_at = right_now() + timedelta( days=-32) msg = mfs("""\ To: [email protected] From: [email protected] Subject: message 1 """) self._handler.process(self._mlist, msg, {}) args = FakeArgs() args.bump = True args.send = True args.lists.append('ant.example.com') self._command.process(args) self._runner.run() # The volume is 8 and the digest number is 2 because a digest was sent # after the volume/number was bumped. self.assertEqual(self._mlist.volume, 8) self.assertEqual(self._mlist.next_digest_number, 2) self.assertEqual(self._mlist.digest_last_sent_at, right_now()) items = get_queue_messages('virgin', expected_count=1) self.assertEqual(items[0].msg['subject'], 'Ant Digest, Vol 8, Issue 1')
def test_bump_before_send(self): self._mlist.digest_volume_frequency = DigestFrequency.monthly self._mlist.volume = 7 self._mlist.next_digest_number = 4 self._mlist.digest_last_sent_at = right_now() + timedelta(days=-32) msg = mfs("""\ To: [email protected] From: [email protected] Subject: message 1 """) self._handler.process(self._mlist, msg, {}) args = FakeArgs() args.bump = True args.send = True args.lists.append('ant.example.com') self._command.process(args) self._runner.run() # The volume is 8 and the digest number is 2 because a digest was sent # after the volume/number was bumped. self.assertEqual(self._mlist.volume, 8) self.assertEqual(self._mlist.next_digest_number, 2) self.assertEqual(self._mlist.digest_last_sent_at, right_now()) items = get_queue_messages('virgin', expected_count=1) self.assertEqual(items[0].msg['subject'], 'Ant Digest, Vol 8, Issue 1')
def setUp(self): self._mlist = create_list('*****@*****.**') self._mlist.digest_volume_frequency = DigestFrequency.monthly self._mlist.volume = 7 self._mlist.next_digest_number = 4 self.right_now = right_now() self._command = CliRunner()
def setUp(self): self._mlist = create_list('*****@*****.**') self._mlist.digest_volume_frequency = DigestFrequency.monthly self._mlist.volume = 7 self._mlist.next_digest_number = 4 self.right_now = right_now() self._command = Digests()
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())
def bump_digest_number_and_volume(mlist): """Bump the digest number and volume.""" now = right_now() if mlist.digest_last_sent_at is None: # There has been no previous digest. bump = False elif mlist.digest_volume_frequency == DigestFrequency.yearly: bump = (now.year > mlist.digest_last_sent_at.year) elif mlist.digest_volume_frequency == DigestFrequency.monthly: # Monthly. this_month = now.year * 100 + now.month digest_month = (mlist.digest_last_sent_at.year * 100 + mlist.digest_last_sent_at.month) bump = (this_month > digest_month) elif mlist.digest_volume_frequency == DigestFrequency.quarterly: # Quarterly. this_quarter = now.year * 100 + (now.month - 1) // 4 digest_quarter = (mlist.digest_last_sent_at.year * 100 + (mlist.digest_last_sent_at.month - 1) // 4) bump = (this_quarter > digest_quarter) elif mlist.digest_volume_frequency == DigestFrequency.weekly: this_week = now.year * 100 + now.isocalendar()[1] digest_week = (mlist.digest_last_sent_at.year * 100 + mlist.digest_last_sent_at.isocalendar()[1]) bump = (this_week > digest_week) elif mlist.digest_volume_frequency == DigestFrequency.daily: bump = (now.toordinal() > mlist.digest_last_sent_at.toordinal()) else: raise AssertionError( 'Bad DigestFrequency: {0}'.format( mlist.digest_volume_frequency)) if bump: mlist.volume += 1 mlist.next_digest_number = 1 else: # Just bump the digest number. mlist.next_digest_number += 1 mlist.digest_last_sent_at = now
def bump_digest_number_and_volume(mlist): """Bump the digest number and volume.""" now = right_now() if mlist.digest_last_sent_at is None: # There has been no previous digest. bump = False elif mlist.digest_volume_frequency == DigestFrequency.yearly: bump = (now.year > mlist.digest_last_sent_at.year) elif mlist.digest_volume_frequency == DigestFrequency.monthly: # Monthly. this_month = now.year * 100 + now.month digest_month = (mlist.digest_last_sent_at.year * 100 + mlist.digest_last_sent_at.month) bump = (this_month > digest_month) elif mlist.digest_volume_frequency == DigestFrequency.quarterly: # Quarterly. this_quarter = now.year * 100 + (now.month - 1) // 4 digest_quarter = (mlist.digest_last_sent_at.year * 100 + (mlist.digest_last_sent_at.month - 1) // 4) bump = (this_quarter > digest_quarter) elif mlist.digest_volume_frequency == DigestFrequency.weekly: this_week = now.year * 100 + now.isocalendar()[1] digest_week = (mlist.digest_last_sent_at.year * 100 + mlist.digest_last_sent_at.isocalendar()[1]) bump = (this_week > digest_week) elif mlist.digest_volume_frequency == DigestFrequency.daily: bump = (now.toordinal() > mlist.digest_last_sent_at.toordinal()) else: raise AssertionError( 'Bad DigestFrequency: {}'.format(mlist.digest_volume_frequency)) if bump: mlist.volume += 1 mlist.next_digest_number = 1 else: # Just bump the digest number. mlist.next_digest_number += 1 mlist.digest_last_sent_at = now
def setUp(self): self._mlist = create_list('*****@*****.**') self._mlist.volume = 7 self._mlist.next_digest_number = 4 self.right_now = right_now()