mirror of
https://github.com/pretix/pretix.git
synced 2026-05-04 15:04:03 +00:00
Implement notifications for admin users (#700)
* First stab at notification settings * Add "global" setting for notification levels * Trigger notification task * Get users with permission for event * Actually send notification emails * More notifications * Allow to turn off notifications * Link in email to pause all notifications * Add NotificationType to wordlist * Add notification tests * Add documentation * Rebase fixes
This commit is contained in:
118
src/tests/base/test_notifications.py
Normal file
118
src/tests/base/test_notifications.py
Normal file
@@ -0,0 +1,118 @@
|
||||
from datetime import timedelta
|
||||
from decimal import Decimal
|
||||
|
||||
import pytest
|
||||
from django.core import mail as djmail
|
||||
from django.db import transaction
|
||||
from django.utils.timezone import now
|
||||
|
||||
from pretix.base.models import (
|
||||
Event, Item, Order, OrderPosition, Organizer, User,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def event():
|
||||
o = Organizer.objects.create(name='Dummy', slug='dummy')
|
||||
event = Event.objects.create(
|
||||
organizer=o, name='Dummy', slug='dummy',
|
||||
date_from=now()
|
||||
)
|
||||
return event
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def order(event):
|
||||
o = Order.objects.create(
|
||||
code='FOO', event=event, email='dummy@dummy.test',
|
||||
status=Order.STATUS_PENDING, locale='en',
|
||||
datetime=now(), expires=now() + timedelta(days=10),
|
||||
total=Decimal('46.00'), payment_provider='banktransfer'
|
||||
)
|
||||
tr19 = event.tax_rules.create(rate=Decimal('19.00'))
|
||||
ticket = Item.objects.create(event=event, name='Early-bird ticket', tax_rule=tr19,
|
||||
default_price=Decimal('23.00'), admission=True)
|
||||
OrderPosition.objects.create(
|
||||
order=o, item=ticket, variation=None,
|
||||
price=Decimal("23.00"), attendee_name="Peter", positionid=1
|
||||
)
|
||||
return o
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def team(event):
|
||||
return event.organizer.teams.create(all_events=True, can_view_orders=True)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def user(team):
|
||||
user = User.objects.create_user('dummy@dummy.dummy', 'dummy')
|
||||
team.members.add(user)
|
||||
return user
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def monkeypatch_on_commit(monkeypatch):
|
||||
monkeypatch.setattr("django.db.transaction.on_commit", lambda t: t())
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_notification_trigger_event_specific(event, order, user, monkeypatch_on_commit):
|
||||
djmail.outbox = []
|
||||
user.notification_settings.create(
|
||||
method='mail', event=event, action_type='pretix.event.order.paid', enabled=True
|
||||
)
|
||||
with transaction.atomic():
|
||||
order.log_action('pretix.event.order.paid', {})
|
||||
assert len(djmail.outbox) == 1
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_notification_trigger_global(event, order, user, monkeypatch_on_commit):
|
||||
djmail.outbox = []
|
||||
user.notification_settings.create(
|
||||
method='mail', event=None, action_type='pretix.event.order.paid', enabled=True
|
||||
)
|
||||
with transaction.atomic():
|
||||
order.log_action('pretix.event.order.paid', {})
|
||||
assert len(djmail.outbox) == 1
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_notification_enabled_global_ignored_specific(event, order, user, monkeypatch_on_commit):
|
||||
djmail.outbox = []
|
||||
user.notification_settings.create(
|
||||
method='mail', event=None, action_type='pretix.event.order.paid', enabled=True
|
||||
)
|
||||
user.notification_settings.create(
|
||||
method='mail', event=event, action_type='pretix.event.order.paid', enabled=False
|
||||
)
|
||||
with transaction.atomic():
|
||||
order.log_action('pretix.event.order.paid', {})
|
||||
assert len(djmail.outbox) == 0
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_notification_ignore_same_user(event, order, user, monkeypatch_on_commit):
|
||||
djmail.outbox = []
|
||||
user.notification_settings.create(
|
||||
method='mail', event=event, action_type='pretix.event.order.paid', enabled=True
|
||||
)
|
||||
with transaction.atomic():
|
||||
order.log_action('pretix.event.order.paid', {}, user=user)
|
||||
assert len(djmail.outbox) == 0
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_notification_ignore_insufficient_permissions(event, order, user, team, monkeypatch_on_commit):
|
||||
djmail.outbox = []
|
||||
team.can_view_orders = False
|
||||
team.save()
|
||||
user.notification_settings.create(
|
||||
method='mail', event=event, action_type='pretix.event.order.paid', enabled=True
|
||||
)
|
||||
with transaction.atomic():
|
||||
order.log_action('pretix.event.order.paid', {})
|
||||
assert len(djmail.outbox) == 0
|
||||
|
||||
# TODO: Test email content
|
||||
Reference in New Issue
Block a user