Stop writing "1 days" in emails.

This commit is contained in:
Robert Bruce Park 2017-03-13 10:26:59 -07:00
parent 1b4828bfb3
commit 0579677457
2 changed files with 21 additions and 1 deletions

View File

@ -31,7 +31,7 @@ Hi,
{source_name} {version} needs attention. {source_name} {version} needs attention.
It has been stuck in {series}-proposed for {age:.0f} day{plural}. It has been stuck in {series}-proposed for {age} day{plural}.
You either sponsored or uploaded this package, please investigate why it hasn't been approved for migration. You either sponsored or uploaded this package, please investigate why it hasn't been approved for migration.
@ -160,6 +160,7 @@ class EmailPolicy(BasePolicy, Rest):
sent = self.cache.get(source_name, {}).get(version, False) sent = self.cache.get(source_name, {}).get(version, False)
age = excuse.daysold or 0 age = excuse.daysold or 0
stuck = age >= max_age stuck = age >= max_age
age = int(age)
plural = 's' if age != 1 else '' plural = 's' if age != 1 else ''
if self.dry_run: if self.dry_run:
self.log("[email dry run] Considering: %s/%s: %s" % self.log("[email dry run] Considering: %s/%s: %s" %

View File

@ -216,6 +216,25 @@ class T(unittest.TestCase):
e.apply_policy_impl(None, None, 'chromium-browser', None, FakeSourceData, FakeExcuse) e.apply_policy_impl(None, None, 'chromium-browser', None, FakeSourceData, FakeExcuse)
smtp.SMTP.assert_called_once_with('localhost') smtp.SMTP.assert_called_once_with('localhost')
@patch('britney2.policies.email.EmailPolicy.lp_get_emails')
@patch('britney2.policies.email.smtplib', autospec=True)
def test_smtp_days(self, smtp, lp):
"""Pluralize correctly."""
lp.return_value = ['email@address.com']
e = EmailPolicy(FakeOptions, None)
FakeExcuse.is_valid = False
FakeExcuse.daysold = 1.01
e.apply_policy_impl(None, None, 'chromium-browser', None, FakeSourceData, FakeExcuse)
smtp.SMTP.assert_called_once_with('localhost')
name, args, kwargs = smtp.SMTP().sendmail.mock_calls[0]
text = args[2]
self.assertIn(' 1 day.', text)
FakeExcuse.daysold = 4.9
e.apply_policy_impl(None, None, 'chromium-browser', None, FakeSourceData, FakeExcuse)
name, args, kwargs = smtp.SMTP().sendmail.mock_calls[-1]
text = args[2]
self.assertIn(' 4 days.', text)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()