-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests/projects: add tests for moderator and participant invite accept…
… and reject
- Loading branch information
1 parent
9c6077f
commit 0c93068
Showing
4 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from pytest_factoryboy import register | ||
|
||
from . import factories as invites | ||
|
||
register(invites.ModeratorInviteFactory) | ||
register(invites.ParticipantInviteFactory) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |