def test_email_send_campaign_again_later(self) -> None: """Test same campaign mail sent a while ago.""" email_policy = mail_blast.EmailPolicy( days_since_any_email=7, days_since_same_campaign_unread=14, days_since_same_campaign=90) emails_sent = [ # We sent the email, but user ignored it. self._make_email('focus-network', days_ago=100), # We re-sent the email and users clicked a link in it. self._make_email('focus-network', days_ago=93, status=user_pb2.EMAIL_SENT_CLICKED), ] self.assertTrue(email_policy.can_send('focus-network', emails_sent)) emails_sent = [ # We sent the email, but user ignored it. self._make_email('focus-network', days_ago=91), # We re-sent the email and users clicked a link in it. self._make_email('focus-network', days_ago=78, status=user_pb2.EMAIL_SENT_CLICKED), ] self.assertFalse(email_policy.can_send('focus-network', emails_sent))
def test_email_not_send_campaign_again(self) -> None: """Test policy where we don't resend the same campaign.""" email_policy = mail_blast.EmailPolicy( days_since_any_email=7, days_since_same_campaign_unread=0) emails_sent = [self._make_email('focus-network', days_ago=13)] self.assertFalse(email_policy.can_send('focus-network', emails_sent)) emails_sent = [self._make_email('focus-network', days_ago=365)] self.assertFalse(email_policy.can_send('focus-network', emails_sent))
def test_email_send_campaign_again(self) -> None: """Test same campaign mail sent recently.""" email_policy = mail_blast.EmailPolicy( days_since_any_email=7, days_since_same_campaign_unread=14) emails_sent = [self._make_email('focus-network', days_ago=13)] self.assertFalse(email_policy.can_send('focus-network', emails_sent)) emails_sent = [self._make_email('focus-network', days_ago=15)] self.assertTrue(email_policy.can_send('focus-network', emails_sent))
def test_email_sent_recently(self): """Test email sent recently.""" email_policy = mail_blast.EmailPolicy( days_since_any_email=7, days_since_same_campaign_unread=14) emails_sent = [self._make_email('other-mail', days_ago=6)] self.assertFalse(email_policy.can_send('focus-network', emails_sent)) emails_sent = [self._make_email('other-mail', days_ago=8)] self.assertTrue(email_policy.can_send('focus-network', emails_sent))
def test_several_email_sent(self) -> None: """Test a common case where several emails has been sent.""" email_policy = mail_blast.EmailPolicy( days_since_any_email=7, days_since_same_campaign_unread=0) emails_sent = [] emails_sent.append(self._make_email('nps-survey', days_ago=30)) emails_sent.append(self._make_email('focus-network', days_ago=13)) self.assertTrue(email_policy.can_send('focus-spontaneous', emails_sent)) self.assertFalse(email_policy.can_send('focus-network', emails_sent)) emails_sent.append(self._make_email('other', days_ago=2)) self.assertFalse( email_policy.can_send('focus-spontaneous', emails_sent)) self.assertFalse(email_policy.can_send('focus-network', emails_sent))
def test_mail_status_not_updated(self) -> None: """Test the case where mail status has not been updated.""" email_policy = mail_blast.EmailPolicy( days_since_any_email=7, days_since_same_campaign_unread=14) emails_sent = [] emails_sent.append( self._make_email('focus-network', days_ago=60, status_updated_days_after=8)) emails_sent.append( self._make_email('focus-spontaneous', days_ago=60, status_updated_days_after=4)) emails_sent.append( self._make_email('focus-marvel', days_ago=60, status_updated_days_after=None)) self.assertTrue(email_policy.can_send('focus-network', emails_sent)) self.assertFalse( email_policy.can_send('focus-spontaneous', emails_sent)) self.assertFalse(email_policy.can_send('focus-marvel', emails_sent))
def test_no_previous_mails(self) -> None: """Basic test.""" email_policy = mail_blast.EmailPolicy( days_since_any_email=7, days_since_same_campaign_unread=14) self.assertTrue(email_policy.can_send('focus-network', []))