From 64599778229e0592fb07604239ec30260ed5beaf Mon Sep 17 00:00:00 2001 From: Steve Langasek Date: Thu, 29 Jun 2017 12:46:37 -0700 Subject: [PATCH] Make it possible to test the email frequency for a package that is sometimes a valid candidate and sometimes not --- tests/test_email.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/test_email.py b/tests/test_email.py index dfbae26..09b9306 100755 --- a/tests/test_email.py +++ b/tests/test_email.py @@ -225,8 +225,10 @@ class T(unittest.TestCase): @patch('britney2.policies.email.EmailPolicy.lp_get_emails') @patch('britney2.policies.email.smtplib', autospec=True) - def smtp_repetition(self, smtp, lp, valid=False, expected=None): + def smtp_repetition(self, smtp, lp, valid, expected): """Resend mails periodically, with decreasing frequency.""" + if not isinstance(valid,list): + valid = [valid]*len(expected) FakeExcuse.is_valid = valid lp.return_value = ['email@address.com'] sendmail = smtp.SMTP().sendmail @@ -237,6 +239,11 @@ class T(unittest.TestCase): previous = sendmail.call_count age = hours / 24 FakeExcuse.daysold = age + try: + FakeExcuse.is_valid = valid[len(called)] + except IndexError: + # we've already gotten all the mails we expect + pass e.apply_policy_impl(None, None, 'unity8', None, FakeSourceData, FakeExcuse) if sendmail.call_count > previous: e.initialise(None) # Refill e.cache from disk