mirror of
https://github.com/pretix/pretix.git
synced 2026-05-09 15:54:03 +00:00
tests: Remove on_commit monkeypatch
This commit is contained in:
@@ -24,7 +24,6 @@ from decimal import Decimal
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from django.core import mail as djmail
|
from django.core import mail as djmail
|
||||||
from django.db import transaction
|
|
||||||
from django.utils.timezone import now
|
from django.utils.timezone import now
|
||||||
from django_scopes import scope
|
from django_scopes import scope
|
||||||
|
|
||||||
@@ -75,47 +74,42 @@ def user(team):
|
|||||||
return user
|
return user
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def monkeypatch_on_commit(monkeypatch):
|
|
||||||
monkeypatch.setattr("django.db.transaction.on_commit", lambda t: t())
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_notification_trigger_event_specific(event, order, user, monkeypatch_on_commit):
|
def test_notification_trigger_event_specific(event, order, user, django_capture_on_commit_callbacks):
|
||||||
djmail.outbox = []
|
djmail.outbox = []
|
||||||
user.notification_settings.create(
|
user.notification_settings.create(
|
||||||
method='mail', event=event, action_type='pretix.event.order.paid', enabled=True
|
method='mail', event=event, action_type='pretix.event.order.paid', enabled=True
|
||||||
)
|
)
|
||||||
with transaction.atomic():
|
with django_capture_on_commit_callbacks(execute=True):
|
||||||
order.log_action('pretix.event.order.paid', {})
|
order.log_action('pretix.event.order.paid', {})
|
||||||
assert len(djmail.outbox) == 1
|
assert len(djmail.outbox) == 1
|
||||||
assert djmail.outbox[0].subject.endswith("DUMMY: Order FOO has been marked as paid.")
|
assert djmail.outbox[0].subject.endswith("DUMMY: Order FOO has been marked as paid.")
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_notification_trigger_global(event, order, user, monkeypatch_on_commit):
|
def test_notification_trigger_global(event, order, user, django_capture_on_commit_callbacks):
|
||||||
djmail.outbox = []
|
djmail.outbox = []
|
||||||
user.notification_settings.create(
|
user.notification_settings.create(
|
||||||
method='mail', event=None, action_type='pretix.event.order.paid', enabled=True
|
method='mail', event=None, action_type='pretix.event.order.paid', enabled=True
|
||||||
)
|
)
|
||||||
with transaction.atomic():
|
with django_capture_on_commit_callbacks(execute=True):
|
||||||
order.log_action('pretix.event.order.paid', {})
|
order.log_action('pretix.event.order.paid', {})
|
||||||
assert len(djmail.outbox) == 1
|
assert len(djmail.outbox) == 1
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_notification_trigger_global_wildcard(event, order, user, monkeypatch_on_commit):
|
def test_notification_trigger_global_wildcard(event, order, user, django_capture_on_commit_callbacks):
|
||||||
djmail.outbox = []
|
djmail.outbox = []
|
||||||
user.notification_settings.create(
|
user.notification_settings.create(
|
||||||
method='mail', event=None, action_type='pretix.event.order.changed.*', enabled=True
|
method='mail', event=None, action_type='pretix.event.order.changed.*', enabled=True
|
||||||
)
|
)
|
||||||
with transaction.atomic():
|
with django_capture_on_commit_callbacks(execute=True):
|
||||||
order.log_action('pretix.event.order.changed.item', {})
|
order.log_action('pretix.event.order.changed.item', {})
|
||||||
assert len(djmail.outbox) == 1
|
assert len(djmail.outbox) == 1
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_notification_enabled_global_ignored_specific(event, order, user, monkeypatch_on_commit):
|
def test_notification_enabled_global_ignored_specific(event, order, user, django_capture_on_commit_callbacks):
|
||||||
djmail.outbox = []
|
djmail.outbox = []
|
||||||
user.notification_settings.create(
|
user.notification_settings.create(
|
||||||
method='mail', event=None, action_type='pretix.event.order.paid', enabled=True
|
method='mail', event=None, action_type='pretix.event.order.paid', enabled=True
|
||||||
@@ -123,24 +117,24 @@ def test_notification_enabled_global_ignored_specific(event, order, user, monkey
|
|||||||
user.notification_settings.create(
|
user.notification_settings.create(
|
||||||
method='mail', event=event, action_type='pretix.event.order.paid', enabled=False
|
method='mail', event=event, action_type='pretix.event.order.paid', enabled=False
|
||||||
)
|
)
|
||||||
with transaction.atomic():
|
with django_capture_on_commit_callbacks(execute=True):
|
||||||
order.log_action('pretix.event.order.paid', {})
|
order.log_action('pretix.event.order.paid', {})
|
||||||
assert len(djmail.outbox) == 0
|
assert len(djmail.outbox) == 0
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_notification_ignore_same_user(event, order, user, monkeypatch_on_commit):
|
def test_notification_ignore_same_user(event, order, user, django_capture_on_commit_callbacks):
|
||||||
djmail.outbox = []
|
djmail.outbox = []
|
||||||
user.notification_settings.create(
|
user.notification_settings.create(
|
||||||
method='mail', event=event, action_type='pretix.event.order.paid', enabled=True
|
method='mail', event=event, action_type='pretix.event.order.paid', enabled=True
|
||||||
)
|
)
|
||||||
with transaction.atomic():
|
with django_capture_on_commit_callbacks(execute=True):
|
||||||
order.log_action('pretix.event.order.paid', {}, user=user)
|
order.log_action('pretix.event.order.paid', {}, user=user)
|
||||||
assert len(djmail.outbox) == 0
|
assert len(djmail.outbox) == 0
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_notification_ignore_insufficient_permissions(event, order, user, team, monkeypatch_on_commit):
|
def test_notification_ignore_insufficient_permissions(event, order, user, team, django_capture_on_commit_callbacks):
|
||||||
djmail.outbox = []
|
djmail.outbox = []
|
||||||
team.all_event_permissions = False
|
team.all_event_permissions = False
|
||||||
team.limit_event_permissions = {"event.vouchers:read": True}
|
team.limit_event_permissions = {"event.vouchers:read": True}
|
||||||
@@ -148,7 +142,7 @@ def test_notification_ignore_insufficient_permissions(event, order, user, team,
|
|||||||
user.notification_settings.create(
|
user.notification_settings.create(
|
||||||
method='mail', event=event, action_type='pretix.event.order.paid', enabled=True
|
method='mail', event=event, action_type='pretix.event.order.paid', enabled=True
|
||||||
)
|
)
|
||||||
with transaction.atomic():
|
with django_capture_on_commit_callbacks(execute=True):
|
||||||
order.log_action('pretix.event.order.paid', {})
|
order.log_action('pretix.event.order.paid', {})
|
||||||
assert len(djmail.outbox) == 0
|
assert len(djmail.outbox) == 0
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ from decimal import Decimal
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import responses
|
import responses
|
||||||
from django.db import transaction
|
|
||||||
from django.utils.timezone import now
|
from django.utils.timezone import now
|
||||||
from django_scopes import scopes_disabled
|
from django_scopes import scopes_disabled
|
||||||
|
|
||||||
@@ -82,14 +81,9 @@ def force_str(v):
|
|||||||
return v.decode() if isinstance(v, bytes) else str(v)
|
return v.decode() if isinstance(v, bytes) else str(v)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def monkeypatch_on_commit(monkeypatch):
|
|
||||||
monkeypatch.setattr("django.db.transaction.on_commit", lambda t: t())
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
@responses.activate
|
@responses.activate
|
||||||
def test_webhook_trigger_event_specific(event, order, webhook, monkeypatch_on_commit):
|
def test_webhook_trigger_event_specific(event, order, webhook, django_capture_on_commit_callbacks):
|
||||||
responses.add_callback(
|
responses.add_callback(
|
||||||
responses.POST, 'https://google.com',
|
responses.POST, 'https://google.com',
|
||||||
callback=lambda r: (200, {}, 'ok'),
|
callback=lambda r: (200, {}, 'ok'),
|
||||||
@@ -97,7 +91,7 @@ def test_webhook_trigger_event_specific(event, order, webhook, monkeypatch_on_co
|
|||||||
match_querystring=None, # https://github.com/getsentry/responses/issues/464
|
match_querystring=None, # https://github.com/getsentry/responses/issues/464
|
||||||
)
|
)
|
||||||
|
|
||||||
with transaction.atomic():
|
with django_capture_on_commit_callbacks(execute=True):
|
||||||
le = order.log_action('pretix.event.order.paid', {})
|
le = order.log_action('pretix.event.order.paid', {})
|
||||||
assert len(responses.calls) == 1
|
assert len(responses.calls) == 1
|
||||||
assert json.loads(force_str(responses.calls[0].request.body)) == {
|
assert json.loads(force_str(responses.calls[0].request.body)) == {
|
||||||
@@ -119,12 +113,12 @@ def test_webhook_trigger_event_specific(event, order, webhook, monkeypatch_on_co
|
|||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
@responses.activate
|
@responses.activate
|
||||||
def test_webhook_trigger_global(event, order, webhook, monkeypatch_on_commit):
|
def test_webhook_trigger_global(event, order, webhook, django_capture_on_commit_callbacks):
|
||||||
webhook.limit_events.clear()
|
webhook.limit_events.clear()
|
||||||
webhook.all_events = True
|
webhook.all_events = True
|
||||||
webhook.save()
|
webhook.save()
|
||||||
responses.add(responses.POST, 'https://google.com', status=200)
|
responses.add(responses.POST, 'https://google.com', status=200)
|
||||||
with transaction.atomic():
|
with django_capture_on_commit_callbacks(execute=True):
|
||||||
le = order.log_action('pretix.event.order.paid', {})
|
le = order.log_action('pretix.event.order.paid', {})
|
||||||
assert len(responses.calls) == 1
|
assert len(responses.calls) == 1
|
||||||
assert json.loads(force_str(responses.calls[0].request.body)) == {
|
assert json.loads(force_str(responses.calls[0].request.body)) == {
|
||||||
@@ -138,13 +132,13 @@ def test_webhook_trigger_global(event, order, webhook, monkeypatch_on_commit):
|
|||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
@responses.activate
|
@responses.activate
|
||||||
def test_webhook_trigger_global_wildcard(event, order, webhook, monkeypatch_on_commit):
|
def test_webhook_trigger_global_wildcard(event, order, webhook, django_capture_on_commit_callbacks):
|
||||||
webhook.listeners.create(action_type="pretix.event.order.changed.*")
|
webhook.listeners.create(action_type="pretix.event.order.changed.*")
|
||||||
webhook.limit_events.clear()
|
webhook.limit_events.clear()
|
||||||
webhook.all_events = True
|
webhook.all_events = True
|
||||||
webhook.save()
|
webhook.save()
|
||||||
responses.add(responses.POST, 'https://google.com', status=200)
|
responses.add(responses.POST, 'https://google.com', status=200)
|
||||||
with transaction.atomic():
|
with django_capture_on_commit_callbacks(execute=True):
|
||||||
le = order.log_action('pretix.event.order.changed.item', {})
|
le = order.log_action('pretix.event.order.changed.item', {})
|
||||||
assert len(responses.calls) == 1
|
assert len(responses.calls) == 1
|
||||||
assert json.loads(force_str(responses.calls[0].request.body)) == {
|
assert json.loads(force_str(responses.calls[0].request.body)) == {
|
||||||
@@ -158,30 +152,30 @@ def test_webhook_trigger_global_wildcard(event, order, webhook, monkeypatch_on_c
|
|||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
@responses.activate
|
@responses.activate
|
||||||
def test_webhook_ignore_wrong_action_type(event, order, webhook, monkeypatch_on_commit):
|
def test_webhook_ignore_wrong_action_type(event, order, webhook, django_capture_on_commit_callbacks):
|
||||||
responses.add(responses.POST, 'https://google.com', status=200)
|
responses.add(responses.POST, 'https://google.com', status=200)
|
||||||
with transaction.atomic():
|
with django_capture_on_commit_callbacks(execute=True):
|
||||||
order.log_action('pretix.event.order.changed.item', {})
|
order.log_action('pretix.event.order.changed.item', {})
|
||||||
assert len(responses.calls) == 0
|
assert len(responses.calls) == 0
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
@responses.activate
|
@responses.activate
|
||||||
def test_webhook_ignore_disabled(event, order, webhook, monkeypatch_on_commit):
|
def test_webhook_ignore_disabled(event, order, webhook, django_capture_on_commit_callbacks):
|
||||||
webhook.enabled = False
|
webhook.enabled = False
|
||||||
webhook.save()
|
webhook.save()
|
||||||
responses.add(responses.POST, 'https://google.com', status=200)
|
responses.add(responses.POST, 'https://google.com', status=200)
|
||||||
with transaction.atomic():
|
with django_capture_on_commit_callbacks(execute=True):
|
||||||
order.log_action('pretix.event.order.changed.item', {})
|
order.log_action('pretix.event.order.changed.item', {})
|
||||||
assert len(responses.calls) == 0
|
assert len(responses.calls) == 0
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
@responses.activate
|
@responses.activate
|
||||||
def test_webhook_ignore_wrong_event(event, order, webhook, monkeypatch_on_commit):
|
def test_webhook_ignore_wrong_event(event, order, webhook, django_capture_on_commit_callbacks):
|
||||||
webhook.limit_events.clear()
|
webhook.limit_events.clear()
|
||||||
responses.add(responses.POST, 'https://google.com', status=200)
|
responses.add(responses.POST, 'https://google.com', status=200)
|
||||||
with transaction.atomic():
|
with django_capture_on_commit_callbacks(execute=True):
|
||||||
order.log_action('pretix.event.order.changed.item', {})
|
order.log_action('pretix.event.order.changed.item', {})
|
||||||
assert len(responses.calls) == 0
|
assert len(responses.calls) == 0
|
||||||
|
|
||||||
@@ -189,10 +183,10 @@ def test_webhook_ignore_wrong_event(event, order, webhook, monkeypatch_on_commit
|
|||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
@pytest.mark.xfail(reason="retries can't be tested with celery_always_eager")
|
@pytest.mark.xfail(reason="retries can't be tested with celery_always_eager")
|
||||||
@responses.activate
|
@responses.activate
|
||||||
def test_webhook_retry(event, order, webhook, monkeypatch_on_commit):
|
def test_webhook_retry(event, order, webhook, django_capture_on_commit_callbacks):
|
||||||
responses.add(responses.POST, 'https://google.com', status=500)
|
responses.add(responses.POST, 'https://google.com', status=500)
|
||||||
responses.add(responses.POST, 'https://google.com', status=200)
|
responses.add(responses.POST, 'https://google.com', status=200)
|
||||||
with transaction.atomic():
|
with django_capture_on_commit_callbacks(execute=True):
|
||||||
order.log_action('pretix.event.order.paid', {})
|
order.log_action('pretix.event.order.paid', {})
|
||||||
assert len(responses.calls) == 2
|
assert len(responses.calls) == 2
|
||||||
with scopes_disabled():
|
with scopes_disabled():
|
||||||
@@ -216,9 +210,9 @@ def test_webhook_retry(event, order, webhook, monkeypatch_on_commit):
|
|||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
@responses.activate
|
@responses.activate
|
||||||
def test_webhook_disable_gone(event, order, webhook, monkeypatch_on_commit):
|
def test_webhook_disable_gone(event, order, webhook, django_capture_on_commit_callbacks):
|
||||||
responses.add(responses.POST, 'https://google.com', status=410)
|
responses.add(responses.POST, 'https://google.com', status=410)
|
||||||
with transaction.atomic():
|
with django_capture_on_commit_callbacks(execute=True):
|
||||||
order.log_action('pretix.event.order.paid', {})
|
order.log_action('pretix.event.order.paid', {})
|
||||||
assert len(responses.calls) == 1
|
assert len(responses.calls) == 1
|
||||||
webhook.refresh_from_db()
|
webhook.refresh_from_db()
|
||||||
|
|||||||
@@ -131,3 +131,8 @@ def set_lock_namespaces(request):
|
|||||||
yield
|
yield
|
||||||
else:
|
else:
|
||||||
yield
|
yield
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def class_monkeypatch(request, monkeypatch):
|
||||||
|
request.cls.monkeypatch = monkeypatch
|
||||||
|
|||||||
@@ -385,11 +385,6 @@ class RegistrationFormTest(TestCase):
|
|||||||
self.assertEqual(response.status_code, 403)
|
self.assertEqual(response.status_code, 403)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def class_monkeypatch(request, monkeypatch):
|
|
||||||
request.cls.monkeypatch = monkeypatch
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("class_monkeypatch")
|
@pytest.mark.usefixtures("class_monkeypatch")
|
||||||
class Login2FAFormTest(TestCase):
|
class Login2FAFormTest(TestCase):
|
||||||
|
|
||||||
|
|||||||
@@ -49,11 +49,6 @@ from tests.base import SoupTest, extract_form_fields
|
|||||||
from pretix.base.models import Event, LogEntry, Order, Organizer, Team, User
|
from pretix.base.models import Event, LogEntry, Order, Organizer, Team, User
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def class_monkeypatch(request, monkeypatch):
|
|
||||||
request.cls.monkeypatch = monkeypatch
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("class_monkeypatch")
|
@pytest.mark.usefixtures("class_monkeypatch")
|
||||||
class EventsTest(SoupTest):
|
class EventsTest(SoupTest):
|
||||||
@scopes_disabled()
|
@scopes_disabled()
|
||||||
|
|||||||
@@ -33,11 +33,6 @@ from tests.base import SoupTest, extract_form_fields
|
|||||||
from pretix.base.models import Event, Organizer, OutgoingMail, Team, User
|
from pretix.base.models import Event, Organizer, OutgoingMail, Team, User
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def class_monkeypatch(request, monkeypatch):
|
|
||||||
request.cls.monkeypatch = monkeypatch
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("class_monkeypatch")
|
@pytest.mark.usefixtures("class_monkeypatch")
|
||||||
class OrganizerTest(SoupTest):
|
class OrganizerTest(SoupTest):
|
||||||
@scopes_disabled()
|
@scopes_disabled()
|
||||||
|
|||||||
@@ -286,11 +286,6 @@ class UserPasswordChangeTest(SoupTest):
|
|||||||
assert self.user.needs_password_change is False
|
assert self.user.needs_password_change is False
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def class_monkeypatch(request, monkeypatch):
|
|
||||||
request.cls.monkeypatch = monkeypatch
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("class_monkeypatch")
|
@pytest.mark.usefixtures("class_monkeypatch")
|
||||||
class UserSettings2FATest(SoupTest):
|
class UserSettings2FATest(SoupTest):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user