email: beef up the tests very slightly

- add a day/days case for '1' exactly
  - make some other daysold be non ints
broken-hint-logging
Iain Lane 8 years ago
parent 0579677457
commit 322108df73

@ -194,13 +194,13 @@ class T(unittest.TestCase):
lp.return_value = ['example@email.com'] lp.return_value = ['example@email.com']
e = EmailPolicy(FakeOptions, None) e = EmailPolicy(FakeOptions, None)
FakeExcuse.is_valid = False FakeExcuse.is_valid = False
FakeExcuse.daysold = 0 FakeExcuse.daysold = 0.002
e.apply_policy_impl(None, None, 'chromium-browser', None, FakeSourceData, FakeExcuse) e.apply_policy_impl(None, None, 'chromium-browser', None, FakeSourceData, FakeExcuse)
FakeExcuse.is_valid = True FakeExcuse.is_valid = True
FakeExcuse.daysold = 4 FakeExcuse.daysold = 4.28
e.apply_policy_impl(None, None, 'chromium-browser', None, FakeSourceData, FakeExcuse) e.apply_policy_impl(None, None, 'chromium-browser', None, FakeSourceData, FakeExcuse)
# Would email but no address found # Would email but no address found
FakeExcuse.daysold = 10 FakeExcuse.daysold = 10.12
lp.return_value = [] lp.return_value = []
e.apply_policy_impl(None, None, 'chromium-browser', None, FakeSourceData, FakeExcuse) e.apply_policy_impl(None, None, 'chromium-browser', None, FakeSourceData, FakeExcuse)
self.assertEqual(smtp.mock_calls, []) self.assertEqual(smtp.mock_calls, [])
@ -220,20 +220,31 @@ class T(unittest.TestCase):
@patch('britney2.policies.email.smtplib', autospec=True) @patch('britney2.policies.email.smtplib', autospec=True)
def test_smtp_days(self, smtp, lp): def test_smtp_days(self, smtp, lp):
"""Pluralize correctly.""" """Pluralize correctly."""
sendmail = smtp.SMTP().sendmail
lp.return_value = ['email@address.com'] lp.return_value = ['email@address.com']
e = EmailPolicy(FakeOptions, None) e = EmailPolicy(FakeOptions, None)
FakeExcuse.is_valid = False FakeExcuse.is_valid = False
# day
FakeExcuse.daysold = 1.01 FakeExcuse.daysold = 1.01
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') _, args, _ = sendmail.mock_calls[-1]
name, args, kwargs = smtp.SMTP().sendmail.mock_calls[0]
text = args[2] text = args[2]
self.assertEquals(sendmail.call_count, 1)
self.assertIn(' 1 day.', text) self.assertIn(' 1 day.', text)
# days
FakeExcuse.daysold = 4.9 FakeExcuse.daysold = 4.9
e.apply_policy_impl(None, None, 'chromium-browser', None, FakeSourceData, FakeExcuse) e.apply_policy_impl(None, None, 'chromium-browser', None, FakeSourceData, FakeExcuse)
name, args, kwargs = smtp.SMTP().sendmail.mock_calls[-1] _, args, _ = sendmail.mock_calls[-1]
text = args[2] text = args[2]
self.assertEquals(sendmail.call_count, 2)
self.assertIn(' 4 days.', text) self.assertIn(' 4 days.', text)
# day, exactly 1
FakeExcuse.daysold = 1
e.apply_policy_impl(None, None, 'chromium-browser', None, FakeSourceData, FakeExcuse)
_, args, _ = sendmail.mock_calls[-1]
text = args[2]
self.assertEquals(sendmail.call_count, 3)
self.assertIn(' 1 day.', text)
if __name__ == '__main__': if __name__ == '__main__':

Loading…
Cancel
Save