Skip to content

Commit

Permalink
tests/projects: add tests for moderator and participant invite accept…
Browse files Browse the repository at this point in the history
… and reject
  • Loading branch information
fuzzylogic2000 authored and philli-m committed May 6, 2021
1 parent 9c6077f commit 0c93068
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/projects/conftest.py
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)
24 changes: 24 additions & 0 deletions tests/projects/factories.py
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)
56 changes: 56 additions & 0 deletions tests/projects/test_moderator_invite_detail_views.py
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
56 changes: 56 additions & 0 deletions tests/projects/test_participant_invite_detail_views.py
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

0 comments on commit 0c93068

Please sign in to comment.