Merge ~robru/britney/+git/britney2-ubuntu:fix-email-plurals into ~ubuntu-release/britney/+git/britney2-ubuntu:master

Proposed by Robert Bruce Park on 2017-03-13
Status: Merged
Merged at revision: 057967745765ee36e6b4b813856d10e2bb26b15e
Proposed branch: ~robru/britney/+git/britney2-ubuntu:fix-email-plurals
Merge into: ~ubuntu-release/britney/+git/britney2-ubuntu:master
Diff against target: 51 lines (+21/-1)
2 files modified
britney2/policies/email.py (+2/-1)
tests/test_email.py (+19/-0)
Reviewer Review Type Date Requested Status
Ubuntu Release Team 2017-03-13 Pending
Review via email: mp+319726@code.launchpad.net

Description of the Change

Rounding issue in email policy: When deciding when to pluralize "days", "age != 1" uses the un-rounded age, but then the email rounds the value after, so for example the value of age might be 1.01, that's != to 1 so the plural form is chosen, but then 1.01 rounds down to 1 for display, so the result is "1 days".

This commit rounds at the appropriate time so that the correct plural can be chosen.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/britney2/policies/email.py b/britney2/policies/email.py
2index 385a7ed..60947c8 100644
3--- a/britney2/policies/email.py
4+++ b/britney2/policies/email.py
5@@ -31,7 +31,7 @@ Hi,
6
7 {source_name} {version} needs attention.
8
9-It has been stuck in {series}-proposed for {age:.0f} day{plural}.
10+It has been stuck in {series}-proposed for {age} day{plural}.
11
12 You either sponsored or uploaded this package, please investigate why it hasn't been approved for migration.
13
14@@ -160,6 +160,7 @@ class EmailPolicy(BasePolicy, Rest):
15 sent = self.cache.get(source_name, {}).get(version, False)
16 age = excuse.daysold or 0
17 stuck = age >= max_age
18+ age = int(age)
19 plural = 's' if age != 1 else ''
20 if self.dry_run:
21 self.log("[email dry run] Considering: %s/%s: %s" %
22diff --git a/tests/test_email.py b/tests/test_email.py
23index fa398e4..cdaeca2 100755
24--- a/tests/test_email.py
25+++ b/tests/test_email.py
26@@ -216,6 +216,25 @@ class T(unittest.TestCase):
27 e.apply_policy_impl(None, None, 'chromium-browser', None, FakeSourceData, FakeExcuse)
28 smtp.SMTP.assert_called_once_with('localhost')
29
30+ @patch('britney2.policies.email.EmailPolicy.lp_get_emails')
31+ @patch('britney2.policies.email.smtplib', autospec=True)
32+ def test_smtp_days(self, smtp, lp):
33+ """Pluralize correctly."""
34+ lp.return_value = ['email@address.com']
35+ e = EmailPolicy(FakeOptions, None)
36+ FakeExcuse.is_valid = False
37+ FakeExcuse.daysold = 1.01
38+ e.apply_policy_impl(None, None, 'chromium-browser', None, FakeSourceData, FakeExcuse)
39+ smtp.SMTP.assert_called_once_with('localhost')
40+ name, args, kwargs = smtp.SMTP().sendmail.mock_calls[0]
41+ text = args[2]
42+ self.assertIn(' 1 day.', text)
43+ FakeExcuse.daysold = 4.9
44+ e.apply_policy_impl(None, None, 'chromium-browser', None, FakeSourceData, FakeExcuse)
45+ name, args, kwargs = smtp.SMTP().sendmail.mock_calls[-1]
46+ text = args[2]
47+ self.assertIn(' 4 days.', text)
48+
49
50 if __name__ == '__main__':
51 unittest.main()

Subscribers

People subscribed via source and target branches