def test_update_newsletter_status_advanced(self): self.server.mails_hour = 2 self.server.save() mailer = Mailer(self.newsletter) mailer.smtp = FakeSMTP() mailer.build_email_content = fake_email_content mailer.run() self.assertEquals(mailer.smtp.mails_sent, 2) self.assertEquals(ContactMailingStatus.objects.filter( status=ContactMailingStatus.SENT, newsletter=self.newsletter).count(), 2) self.assertEquals(self.newsletter.status, Newsletter.SENDING) self.server.mails_hour = 0 self.server.save() mailer = Mailer(self.newsletter) mailer.smtp = FakeSMTP() mailer.build_email_content = fake_email_content mailer.run() self.assertEquals(mailer.smtp.mails_sent, 2) self.assertEquals(ContactMailingStatus.objects.filter( status=ContactMailingStatus.SENT, newsletter=self.newsletter).count(), 4) self.assertEquals(self.newsletter.status, Newsletter.SENT)
def test_update_newsletter_status_advanced(self): self.server.mails_hour = 2 self.server.save() mailer = Mailer(self.newsletter) mailer.smtp = FakeSMTP() mailer.run() self.assertEquals(mailer.smtp.mails_sent, 2) self.assertEquals( ContactMailingStatus.objects.filter( status=ContactMailingStatus.SENT, newsletter=self.newsletter).count(), 2) self.assertEquals(self.newsletter.status, Newsletter.SENDING) self.server.mails_hour = 0 self.server.save() mailer = Mailer(self.newsletter) mailer.smtp = FakeSMTP() mailer.run() self.assertEquals(mailer.smtp.mails_sent, 2) self.assertEquals( ContactMailingStatus.objects.filter( status=ContactMailingStatus.SENT, newsletter=self.newsletter).count(), 4) self.assertEquals(self.newsletter.status, Newsletter.SENT)
def test_run(self): mailer = Mailer(self.newsletter) mailer.smtp = FakeSMTP() mailer.run() self.assertEquals(mailer.smtp.mails_sent, 4) self.assertEquals(ContactMailingStatus.objects.filter( status=ContactMailingStatus.SENT, newsletter=self.newsletter).count(), 4) mailer = Mailer(self.newsletter, test=True) mailer.smtp = FakeSMTP() mailer.run() self.assertEquals(mailer.smtp.mails_sent, 2) self.assertEquals(ContactMailingStatus.objects.filter( status=ContactMailingStatus.SENT_TEST, newsletter=self.newsletter).count(), 2) mailer.smtp = None
def test_recipients_refused(self): server = SMTPServer.objects.create(name='Local SMTP', host='localhost', tls=False) contact = Contact.objects.create(email='thisisaninvalidemail') self.newsletter.test_contacts.clear() self.newsletter.test_contacts.add(contact) self.newsletter.server = server self.newsletter.save() self.assertEquals(contact.valid, True) self.assertEquals(ContactMailingStatus.objects.filter( status=ContactMailingStatus.INVALID, newsletter=self.newsletter).count(), 0) mailer = Mailer(self.newsletter, test=True) mailer.smtp = FakeSMTPRefuse() mailer.run() self.assertEquals(Contact.objects.get(email='thisisaninvalidemail').valid, False) self.assertEquals(ContactMailingStatus.objects.filter( status=ContactMailingStatus.INVALID, newsletter=self.newsletter).count(), 1)