Exemple #1
0
    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)
class EventLeaveViewTestCase(TestCase):
    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 test_get(self):
        response = self.client.get(self.url)
        self.assertContains(response, "Leave circle", status_code=200)

    def test_get_404(self):
        url = reverse("circles:leave", args=["8511c737-4498-40ce-8657-9057e8d2cef2"])
        response = self.client.get(url)
        self.assertContains(response, "Not Found", status_code=404)

    def test_post(self):
        response = self.client.post(self.url)
        self.assertRedirects(response, "/", target_status_code=302)

        # Participation was deleted
        self.assertEqual(Participation.objects.all().count(), 0)
Exemple #3
0
    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 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 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()
Exemple #6
0
 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)
Exemple #7
0
    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()
class EventJoinTestCase(TestCase):
    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_get(self):
        response = self.client.get(self.url)
        self.assertContains(response, "Participate in circle", status_code=200)

    def test_post(self):
        response = self.client.post(self.url, {"email": "*****@*****.**",})
        self.assertContains(response, "You are participating", status_code=200)

        # user is added as participant
        self.assertEqual(self.event.participants.count(), 1)
        self.assertEqual(self.event.participants.get().email, "*****@*****.**")

        # email is sent
        self.assertEqual(len(mail.outbox), 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_post_same_user_twice(self):
        """Test that a user is not added twice as participant"""
        self.client.post(self.url, {"email": "*****@*****.**"})
        self.client.post(self.url, {"email": "*****@*****.**"})
        self.assertEqual(self.event.participants.count(), 1)
Exemple #11
0
 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 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()
class EventDeleteTestCase(TestCase):
    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_get(self):
        response = self.client.get(self.url)
        self.assertContains(response, "Delete circle", status_code=200)

    def test_get_404(self):
        url = reverse("circles:delete", args=["8511c737-4498-40ce-8657-9057e8d2cef2"])
        response = self.client.get(url)
        self.assertContains(response, "Not Found", status_code=404)

    def test_post(self):
        response = self.client.post(self.url)
        self.assertRedirects(response, "/", target_status_code=302)

        # event was deleted
        self.assertEqual(Event.objects.all().count(), 0)

        # mail sent to participants and host
        self.assertEqual(len(mail.outbox), 2)
        self.assertEqual(mail.outbox[0].to, ["*****@*****.**"])
Exemple #14
0
class EventTestCase(TestCase):
    def setUp(self):
        self.host = User(email="*****@*****.**", username="******")
        self.host.save()

        self.event = Event(host=self.host,
                           start=datetime.datetime(2020,
                                                   5,
                                                   1,
                                                   20,
                                                   0,
                                                   tzinfo=pytz.UTC))
        self.event.save()

    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_is_full(self):
        self.assertFalse(self.event.is_full)
        # create 6 participants
        for i in range(1, 7):
            email = f"test{i}@example.com"
            user = User(email=email, username=email)
            user.save()
            self.event.participants.add(user)
        self.event.save()
        self.assertTrue(self.event.is_full)

    def test_ical(self):
        self.assertEqual(
            self.event.ical,
            b"BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nSUMMARY:Corona Circle\r\nDTSTART;VALUE=DATE-TIME:20200501T200000Z\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n",
        )
Exemple #15
0
    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")
Exemple #16
0
class EventTestCase(TestCase):
    def setUp(self):
        self.host = User(email="*****@*****.**", username="******")
        self.host.save()

        self.event = Event(host=self.host,
                           start=datetime.datetime(2020,
                                                   5,
                                                   1,
                                                   20,
                                                   0,
                                                   tzinfo=pytz.UTC))
        self.event.save()

    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_is_full(self):
        self.assertFalse(self.event.is_full)
        # create 6 participants
        for i in range(1, 7):
            email = f"test{i}@example.com"
            user = User(email=email, username=email)
            user.save()
            self.event.participants.add(user)
        self.event.save()
        self.assertTrue(self.event.is_full)

    def test_participate_url(self):
        self.assertIn(
            reverse("circles:participate", args=[self.event.pk]),
            self.event.participate_url,
        )

    def test_ical(self):
        self.assertEqual(
            self.event.ical,
            b"BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nSUMMARY:Corona Circle\r\nDTSTART;VALUE=DATE-TIME:20200501T200000Z\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n",
        )

    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")