mirror of
https://github.com/pretix/pretix.git
synced 2026-05-04 15:04:03 +00:00
Email: Allow to override backend for custom SMTP connections (#2368)
This commit is contained in:
@@ -81,7 +81,34 @@ def test_send_mail_with_event_sender(env):
|
||||
assert len(djmail.outbox) == 1
|
||||
assert djmail.outbox[0].to == [user.email]
|
||||
assert djmail.outbox[0].subject == 'Test subject'
|
||||
assert djmail.outbox[0].from_email == 'Dummy <foo@bar>'
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
@pytest.mark.parametrize("smtp_use_custom", (True, False))
|
||||
def test_send_mail_custom_event_smtp(env, smtp_use_custom):
|
||||
djmail.outbox = []
|
||||
event, user, organizer = env
|
||||
event.settings.set("smtp_use_custom", smtp_use_custom)
|
||||
|
||||
mail('dummy@dummy.dummy', 'Test subject', 'mailtest.txt', {}, event=event)
|
||||
|
||||
assert len(djmail.outbox) == 1
|
||||
assert djmail.outbox[0].to == [user.email]
|
||||
assert djmail.outbox[0].subject == 'Test subject'
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
@pytest.mark.parametrize("smtp_use_custom", (True, False))
|
||||
def test_send_mail_custom_organizer_smtp(env, smtp_use_custom):
|
||||
djmail.outbox = []
|
||||
event, user, organizer = env
|
||||
organizer.settings.set("smtp_use_custom", smtp_use_custom)
|
||||
|
||||
mail('dummy@dummy.dummy', 'Test subject', 'mailtest.txt', {}, organizer=organizer)
|
||||
|
||||
assert len(djmail.outbox) == 1
|
||||
assert djmail.outbox[0].to == [user.email]
|
||||
assert djmail.outbox[0].subject == 'Test subject'
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
|
||||
@@ -501,8 +501,7 @@ class EventsTest(SoupTest):
|
||||
|
||||
def test_email_settings(self):
|
||||
with mocker_context() as mocker:
|
||||
mocked = mocker.patch('pretix.base.email.CustomSMTPBackend.test')
|
||||
|
||||
mocked = mocker.patch('pretix.control.views.event.test_custom_smtp_backend')
|
||||
doc = self.get_doc('/control/event/%s/%s/settings/email' % (self.orga1.slug, self.event1.slug))
|
||||
data = extract_form_fields(doc.select("form")[0])
|
||||
data['test'] = '1'
|
||||
|
||||
@@ -27,6 +27,7 @@ from django_scopes import scopes_disabled
|
||||
from tests.base import SoupTest, extract_form_fields
|
||||
|
||||
from pretix.base.models import Event, Organizer, Team, User
|
||||
from pretix.testutils.mock import mocker_context
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -97,3 +98,15 @@ class OrganizerTest(SoupTest):
|
||||
self.orga1.settings.flush()
|
||||
assert self.orga1.settings.primary_color == "#33c33c"
|
||||
assert called
|
||||
|
||||
def test_email_settings(self):
|
||||
with mocker_context() as mocker:
|
||||
mocked = mocker.patch('pretix.control.views.organizer.test_custom_smtp_backend')
|
||||
doc = self.get_doc('/control/organizer/%s/settings/email' % self.orga1.slug)
|
||||
data = extract_form_fields(doc.select("form")[0])
|
||||
data['test'] = '1'
|
||||
doc = self.post_doc('/control/organizer/%s/settings/email' % self.orga1.slug,
|
||||
data, follow=True)
|
||||
assert doc.select('.alert-success')
|
||||
self.event1.settings.flush()
|
||||
assert mocked.called
|
||||
|
||||
Reference in New Issue
Block a user