class MailTemplateTestCase(TestCase): def setUp(self): self.template = MailTemplate( type="join_confirmation", language_code="de", subject_template="Event beigetreten", body_template="{{ testvariable }}", ) self.template.save() def test_render(self): mail = self.template.render({"testvariable": "This is a test"}, "*****@*****.**") self.assertEqual(mail.body, "This is a test") self.assertEqual(mail.subject, "Event beigetreten") self.assertEqual(mail.to, ["*****@*****.**"]) def test_get_mail(self): mail = MailTemplate.get_mail( "join_confirmation", "de", {"testvariable": "This is a test"}, "*****@*****.**", ) self.assertEqual(mail.subject, "Event beigetreten")
def setUp(self): self.template = MailTemplate( type="join_confirmation", language_code="de", subject_template="Event beigetreten", body_template="{{ testvariable }}", ) self.template.save()
def test_render(self): self.template = MailTemplate( type="join_confirmation", subject_template="Event beigetreten", body_template="{{ testvariable }}", ) self.template.save() email = self.template.render({"testvariable": "This is a test"}, "*****@*****.**") self.assertEqual(email.body, "This is a test") self.assertEqual(email.subject, "Event beigetreten") self.assertEqual(email.to, ["*****@*****.**"])
class MailTemplateTestCase(TestCase): def test_render(self): self.template = MailTemplate( type="join_confirmation", subject_template="Event beigetreten", body_template="{{ testvariable }}", ) self.template.save() email = self.template.render({"testvariable": "This is a test"}, "*****@*****.**") self.assertEqual(email.body, "This is a test") self.assertEqual(email.subject, "Event beigetreten") self.assertEqual(email.to, ["*****@*****.**"]) def test_get_mail(self): self.template = MailTemplate( type="join_confirmation", subject_template="Event beigetreten", body_template="{{ testvariable }}", ) self.template.save() email = MailTemplate.get_mail( "join_confirmation", {"testvariable": "This is a test"}, "*****@*****.**", ) self.assertEqual(email.subject, "Event beigetreten") def test_get_right_language(self): MailTemplate( type="join_confirmation", subject_template_en="english", body_template_en="english", subject_template_de="deutsch", body_template_de="deutsch", ).save() translation.activate("de") email = MailTemplate.get_mail( "join_confirmation", {}, "*****@*****.**", ) self.assertEqual(email.subject, "deutsch") translation.activate("en") email = MailTemplate.get_mail( "join_confirmation", {}, "*****@*****.**", ) self.assertEqual(email.subject, "english")
def test_get_mail(self): self.template = MailTemplate( type="join_confirmation", subject_template="Event beigetreten", body_template="{{ testvariable }}", ) self.template.save() email = MailTemplate.get_mail( "join_confirmation", {"testvariable": "This is a test"}, "*****@*****.**", ) self.assertEqual(email.subject, "Event beigetreten")
def test_post_email_language(self): MailTemplate( type="host_confirmation", subject_template="test", body_template="test", body_template_de="german test", ).save() self.client.post( self.url, { "start": self.tomorrow, "email": "*****@*****.**", "language": "en", "tzname": "Europe/Berlin", }, ) # email is sent in language of event (english) self.assertEqual(mail.outbox[0].body, "test") self.client.post( self.url, { "start": self.tomorrow, "email": "*****@*****.**", "language": "de", "tzname": "Europe/Berlin", }, ) # email is sent in language of event (german) self.assertEqual(mail.outbox[1].body, "german test")
def test_post(self): # mail template MailTemplate( type="host_confirmation", subject_template="test", body_template="test", ).save() response = self.client.post( self.url, { "start": self.tomorrow, "email": "*****@*****.**", "language": "en", "tzname": "Europe/Berlin", }, follow=True, ) self.assertContains(response, "was created", status_code=200) # user and event were created self.assertEqual(User.objects.count(), 1) self.assertEqual(Event.objects.count(), 1) event = Event.objects.get() # user was added as host self.assertEqual(event.host.email, "*****@*****.**") # email is sent self.assertEqual(len(mail.outbox), 1)
def setUp(self): # users self.host = User(email="*****@*****.**", username="******") self.host.save() self.participant = User(email="*****@*****.**", username="******") self.participant.save() # events past_event = Event( host=self.host, start=datetime.datetime(1999, 5, 1, 20, 0, tzinfo=pytz.UTC), language="de", ) past_event.save() past_event.participants.add(self.participant) Event( host=self.host, start=datetime.datetime(2222, 5, 1, 20, 0, tzinfo=pytz.UTC), ).save() # mail template MailTemplate( type="join", subject_template="test", body_template="test", ).save()
def setUp(self): # mail template MailTemplate( type="host_confirmation", language_code="en", subject_template="test", body_template="test", ).save()
def test_get_mail(self): mail = MailTemplate.get_mail( "join_confirmation", "de", {"testvariable": "This is a test"}, "*****@*****.**", ) self.assertEqual(mail.subject, "Event beigetreten")
def test_get_right_language(self): MailTemplate( type="join_confirmation", subject_template_en="english", body_template_en="english", subject_template_de="deutsch", body_template_de="deutsch", ).save() translation.activate("de") email = MailTemplate.get_mail( "join_confirmation", {}, "*****@*****.**", ) self.assertEqual(email.subject, "deutsch") translation.activate("en") email = MailTemplate.get_mail( "join_confirmation", {}, "*****@*****.**", ) self.assertEqual(email.subject, "english")
def setUp(self): self.host = User(email="*****@*****.**", username="******") self.host.save() tomorrow = timezone.now() + datetime.timedelta(days=1) self.event = Event(host=self.host, start=tomorrow) self.event.save() self.url = reverse("circles:participate", args=[self.event.pk]) # mail template MailTemplate( type="join_confirmation", language_code="en", subject_template="test", body_template="test", ).save()
def test_email_timezone(self): MailTemplate( type="host_confirmation", subject_template="test", body_template="{{ event.start }} {{ event.start|date:'e' }}", ).save() self.client.post( self.url, { "start": datetime.datetime(2030, 5, 1, 10, 0), "email": "*****@*****.**", "language": "en", "tzname": "US/Pacific", }, ) self.assertEqual(mail.outbox[0].body, "May 1, 2030, 5 p.m. UTC")
def test_can_get_delete_url(self): MailTemplate( type="host_confirmation", subject_template="test", body_template="{{ event.delete_url }}", ).save() self.client.post( self.url, { "start": self.tomorrow, "email": "*****@*****.**", "language": "en", "tzname": "Europe/Berlin", }, ) event = Event.objects.get() self.assertEqual(mail.outbox[0].body, event.delete_url)
def setUp(self): self.host = User(email="*****@*****.**", username="******") self.host.save() self.tomorrow = timezone.now() + datetime.timedelta(days=1) self.event = Event(host=self.host, start=self.tomorrow) self.event.save() # add participant user, _ = User.objects.get_or_create( email="*****@*****.**", username="******" ) self.event.participants.add(user) self.event.save() self.url = reverse("circles:delete", args=[self.event.uuid]) # mail template MailTemplate( type="deleted", subject_template="test", body_template="test", ).save()
def test_mail_participants(self): event = Event( host=self.host, start=datetime.datetime(2020, 5, 1, 20, 0, tzinfo=pytz.UTC), language="de", tzname="US/Pacific", ) event.save() MailTemplate( type="join", subject_template_en="english", body_template_en="english", subject_template_de="deutsch", body_template_de="{{ event.start }}", ).save() event.mail_participants() # mail is sent self.assertEqual(len(mail.outbox), 1) # mail is on right language self.assertEqual(mail.outbox[0].subject, "deutsch") # mail is in right timezone (20:00 UTC is 22:00 CEST) self.assertEqual(mail.outbox[0].body, "1. Mai 2020 22:00")