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): self.host = User(email="*****@*****.**", username="******") self.host.save() Event( host=self.host, start=datetime.datetime(1999, 5, 1, 20, 0, tzinfo=pytz.UTC) ).save() Event( host=self.host, start=datetime.datetime(2222, 5, 1, 20, 0, tzinfo=pytz.UTC) ).save()
def test_upcoming(self): self.host = User(email="*****@*****.**", username="******") self.host.save() Event(host=self.host, start=datetime.datetime(1999, 5, 1, 20, 0, tzinfo=pytz.UTC)).save() Event(host=self.host, start=datetime.datetime(2222, 5, 1, 20, 0, tzinfo=pytz.UTC)).save() self.assertEqual(Event.objects.upcoming().count(), 1)
def test_check_current_not_deleted(self): past_event = Event(host=self.host, start=timezone.now(), language="de") past_event.save() self.assertEqual(Event.objects.all().count(), 1) call_command("cron") self.assertEqual(Event.objects.all().count(), 1)
def test_post_event_past(self): yesterday = timezone.now() - datetime.timedelta(days=1) past_event = Event(host=self.host, start=yesterday) past_event.save() url = reverse("circles:participate", args=[past_event.pk]) response = self.client.post(url, {"email": "*****@*****.**",}) self.assertContains(response, "You can not join", status_code=400)
def test_is_past(self): event = Event(host=self.host, start=datetime.datetime(1999, 5, 1, 20, 0, tzinfo=pytz.UTC)) self.assertTrue(event.is_past)
def test_check_old_are_deleted(self): past_event = Event( host=self.host, start=datetime.datetime(1999, 5, 1, 20, 0, tzinfo=pytz.UTC), language="de", ) past_event.save() self.assertEqual(Event.objects.all().count(), 1) call_command("cron") self.assertEqual(Event.objects.all().count(), 0)
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.participation = Participation.objects.create(event=self.event, user=user) self.url = reverse("circles:leave", args=[self.participation.uuid])
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 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")