From 0c9306810113e85b37efd947ddba2b54328f8599 Mon Sep 17 00:00:00 2001 From: fuzzylogic2000 Date: Thu, 6 May 2021 11:52:24 +0200 Subject: [PATCH] tests/projects: add tests for moderator and participant invite accept and reject --- tests/projects/conftest.py | 6 ++ tests/projects/factories.py | 24 ++++++++ .../test_moderator_invite_detail_views.py | 56 +++++++++++++++++++ .../test_participant_invite_detail_views.py | 56 +++++++++++++++++++ 4 files changed, 142 insertions(+) create mode 100644 tests/projects/conftest.py create mode 100644 tests/projects/factories.py create mode 100644 tests/projects/test_moderator_invite_detail_views.py create mode 100644 tests/projects/test_participant_invite_detail_views.py diff --git a/tests/projects/conftest.py b/tests/projects/conftest.py new file mode 100644 index 0000000000..8d30b76c61 --- /dev/null +++ b/tests/projects/conftest.py @@ -0,0 +1,6 @@ +from pytest_factoryboy import register + +from . import factories as invites + +register(invites.ModeratorInviteFactory) +register(invites.ParticipantInviteFactory) diff --git a/tests/projects/factories.py b/tests/projects/factories.py new file mode 100644 index 0000000000..941eec9b7c --- /dev/null +++ b/tests/projects/factories.py @@ -0,0 +1,24 @@ +import factory + +from adhocracy4.test import factories as a4_factories +from meinberlin.apps.projects import models + + +class ParticipantInviteFactory(factory.django.DjangoModelFactory): + + class Meta: + model = models.ParticipantInvite + + creator = factory.SubFactory(a4_factories.USER_FACTORY) + project = factory.SubFactory(a4_factories.ProjectFactory) + email = factory.Sequence(lambda n: 'user%d@liqd.net' % n) + + +class ModeratorInviteFactory(factory.django.DjangoModelFactory): + + class Meta: + model = models.ModeratorInvite + + creator = factory.SubFactory(a4_factories.USER_FACTORY) + project = factory.SubFactory(a4_factories.ProjectFactory) + email = factory.Sequence(lambda n: 'user%d@liqd.net' % n) diff --git a/tests/projects/test_moderator_invite_detail_views.py b/tests/projects/test_moderator_invite_detail_views.py new file mode 100644 index 0000000000..93635a906c --- /dev/null +++ b/tests/projects/test_moderator_invite_detail_views.py @@ -0,0 +1,56 @@ +import pytest +from django.core import mail +from django.urls import reverse + +from adhocracy4.test.helpers import redirect_target +from meinberlin.apps.projects.models import ModeratorInvite + + +@pytest.mark.django_db +def test_user_can_accept(client, moderator_invite, user): + url = moderator_invite.get_absolute_url() + response = client.get(url) + assert response.status_code == 200 + assert response.template_name[0] == \ + 'meinberlin_projects/moderatorinvite_detail.html' + + client.login(username=user.email, password='password') + response = client.get(url) + assert response.status_code == 302 + assert redirect_target(response) == 'project-moderator-invite-update' + assert ModeratorInvite.objects.all().count() == 1 + assert str(ModeratorInvite.objects.first()) == \ + 'Moderation invite to {} for {}'.format( + moderator_invite.project, moderator_invite.email) + + data = { + 'accept': '' + } + + url = reverse( + 'project-moderator-invite-update', + kwargs={'invite_token': moderator_invite.token}) + + response = client.post(url, data) + assert response.status_code == 302 + assert redirect_target(response) == 'project-detail' + assert len(mail.outbox) == 0 + assert ModeratorInvite.objects.all().count() == 0 + + +@pytest.mark.django_db +def test_user_can_reject(client, moderator_invite, user): + client.login(username=user.email, password='password') + data = { + 'reject': '' + } + + url = reverse( + 'project-moderator-invite-update', + kwargs={'invite_token': moderator_invite.token}) + + response = client.post(url, data) + assert response.status_code == 302 + assert redirect_target(response) == 'wagtail_serve' + assert len(mail.outbox) == 0 + assert ModeratorInvite.objects.all().count() == 0 diff --git a/tests/projects/test_participant_invite_detail_views.py b/tests/projects/test_participant_invite_detail_views.py new file mode 100644 index 0000000000..bc449b2073 --- /dev/null +++ b/tests/projects/test_participant_invite_detail_views.py @@ -0,0 +1,56 @@ +import pytest +from django.core import mail +from django.urls import reverse + +from adhocracy4.test.helpers import redirect_target +from meinberlin.apps.projects.models import ParticipantInvite + + +@pytest.mark.django_db +def test_user_can_accept(client, participant_invite, user): + url = participant_invite.get_absolute_url() + response = client.get(url) + assert response.status_code == 200 + assert response.template_name[0] == \ + 'meinberlin_projects/participantinvite_detail.html' + + client.login(username=user.email, password='password') + response = client.get(url) + assert response.status_code == 302 + assert redirect_target(response) == 'project-participant-invite-update' + assert ParticipantInvite.objects.all().count() == 1 + assert str(ParticipantInvite.objects.first()) == \ + 'Participation invite to {} for {}'.format( + participant_invite.project, participant_invite.email) + + data = { + 'accept': '' + } + + url = reverse( + 'project-participant-invite-update', + kwargs={'invite_token': participant_invite.token}) + + response = client.post(url, data) + assert response.status_code == 302 + assert redirect_target(response) == 'project-detail' + assert len(mail.outbox) == 0 + assert ParticipantInvite.objects.all().count() == 0 + + +@pytest.mark.django_db +def test_user_can_reject(client, participant_invite, user): + client.login(username=user.email, password='password') + data = { + 'reject': '' + } + + url = reverse( + 'project-participant-invite-update', + kwargs={'invite_token': participant_invite.token}) + + response = client.post(url, data) + assert response.status_code == 302 + assert redirect_target(response) == 'wagtail_serve' + assert len(mail.outbox) == 0 + assert ParticipantInvite.objects.all().count() == 0