Commit cf97da7b authored by Robert's avatar Robert

Add test

parent c7e16cce
Pipeline #1267 failed with stage
in 1 minute and 40 seconds
{% block content %}{% endblock %}
{% block footer %}{% if subscription %}
--
Du erhältst diese Benachrichtigung, weil Du {% if membership %}Mitglied der Gruppe {{ membership.group }} bist und die Gruppe{% else %}die Gruppe {{ subscription.subscribed_to }}{% endif %} abonniert hast.
{{ subscription.subscribed_to.get_absolute_url|full_url }}{% endif %}{% endblock %}
Du erhältst diese Benachrichtigung, weil Du {% if membership %}Mitglied der Gruppe '{{ membership.group }}' bist und die Gruppe{% else %}die Gruppe '{{ subscription.subscribed_to }}'{% endif %} abonniert hast.{% if not membership %} Zum Abbestellen der Benachrichtigungen folge bitte diesem Verweis:{% endif %}
{% if membership %}{{ subscription.subscribed_to.get_absolute_url|full_url }}{% else %}{% if subscription.subscriber.can_login %}{% url 'group-unsubscribe' subscription.subscribed_to.pk as unsub_url %}{% else %}{% url 'group-unsubscribe-request' subscription.subscribed_to.pk as unsub_url %}{% endif %}{{ unsub_url|full_url }}{% endif %}{% endif %}{% endblock %}
Jemand hat Deine E-Mail-Adresse auf {{ site.name }} angegeben. Wenn Du es nicht warst, kannst Du diese Nachricht gefahrlos ignorieren.
Wenn Du Dein Abonnement der Gruppe '{{ object }}' kündigen möchtest, bestätige dies bitte, indem Du dem folgenden Verweis folgst:
Wenn Du Dein Abonnement der Gruppe '{{ object }}' kündigen möchtest, bestätige dies bitte, indem Du diesem Verweis folgst:
{% url 'group-unsubscribe-confirm' token.secret_key as url %}{{ url|full_url }}
......@@ -4,9 +4,11 @@ from django.core import mail
from django.urls import reverse
from django.test import TestCase
from core.models import PermissionToken
from features.gestalten.tests import AuthenticatedMixin
from features.groups.tests.mixins import GroupMixin
from features.memberships.test_mixins import AuthenticatedMemberMixin, MemberMixin
from . import models
TEST_EMAIL = 'test.subscription@test.local'
......@@ -33,8 +35,42 @@ class Subscription(MemberMixin, TestCase):
reverse('create-group-article', args=(self.group.slug,)),
{'title': 'Test', 'text': 'Test', 'public': True})
self.assertTrue(mail.outbox)
self.assertTrue(list(filterfalse(
lambda x: x < 0, map(lambda m: m.to[0].find(TEST_EMAIL), mail.outbox))))
for email_obj in mail.outbox:
if email_obj.to[0].find(TEST_EMAIL) >= 0:
break
self.assertTrue(email_obj.to[0].find(TEST_EMAIL) >= 0)
# cleanup
mail.outbox = []
self.client.logout()
# notification contains link to unsubscribe form
unsubscribe_request_url = reverse('group-unsubscribe-request', args=(self.group.pk,))
self.assertTrue(unsubscribe_request_url in email_obj.body)
# unsubscribe form renders ok
r = self.client.get(unsubscribe_request_url)
self.assertEquals(r.status_code, 200)
# unsubscription succeeds with email address
r = self.client.post(unsubscribe_request_url, {'subscriber': TEST_EMAIL})
self.assertRedirects(r, self.group.get_absolute_url())
# subscriber gets email with link to unsubscribe confirmation
token = PermissionToken.objects.get(feature_key='group-unsubscribe')
unsubscribe_confirm_url = reverse('group-unsubscribe-confirm', args=(token.secret_key,))
self.assertEqual(len(mail.outbox), 1)
self.assertTrue(unsubscribe_confirm_url in mail.outbox[0].body)
# unsubscription confirmation page renders ok
r = self.client.get(unsubscribe_confirm_url)
self.assertEquals(r.status_code, 200)
# unsubscription confirmation removes subscription
num_subscriptions = models.Subscription.objects.count()
r = self.client.post(unsubscribe_confirm_url)
self.assertRedirects(r, self.group.get_absolute_url())
self.assertEqual(models.Subscription.objects.count(), num_subscriptions-1)
class AuthenticatedSubscription(AuthenticatedMixin, GroupMixin, TestCase):
......
......@@ -61,6 +61,13 @@ class GroupUnsubscribe(PermissionMixin, DeleteView):
model = Subscription
template_name = 'subscriptions/delete.html'
def delete(self, *args, **kwargs):
success(
self.request,
'Du erhältst zukünftig keine Benachrichtigungen mehr für Beiträge dieser '
'Gruppe.')
return super().delete(*args, **kwargs)
def get_object(self):
return self.gestalt.subscriptions.filter(
subscribed_to_type=self.group.content_type, subscribed_to_id=self.group.id)
......@@ -75,13 +82,6 @@ class GroupUnsubscribe(PermissionMixin, DeleteView):
class GroupUnsubscribeConfirm(GroupUnsubscribe):
def delete(self, *args, **kwargs):
success(
self.request,
'Dein Abonnement wurde gekündigt. Du erhältst zukünftig keine '
'Benachrichtigungen mehr für diese Gruppe.')
return super().delete(*args, **kwargs)
def get_permission_object(self):
token = get_object_or_404(
PermissionToken, feature_key='group-unsubscribe',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment