mirror of
https://github.com/pretix/pretix.git
synced 2026-08-17 11:56:27 +00:00
Allow to send e-mails to attendees individually (#1299)
* . * Add a position detail page to the frontend * Mail templates * Send mails * Send reminder email * Add position support to sendmail plugin * Add and fix some tests * Fix failing test on real databases
This commit is contained in:
@@ -401,6 +401,28 @@ class DownloadReminderTests(TestCase):
|
||||
send_download_reminders(sender=self.event)
|
||||
assert len(djmail.outbox) == 1
|
||||
|
||||
def test_send_to_attendees(self):
|
||||
self.event.settings.mail_send_download_reminder_attendee = True
|
||||
self.event.settings.mail_days_download_reminder = 2
|
||||
self.op1.attendee_email = 'attendee@dummy.test'
|
||||
self.op1.save()
|
||||
send_download_reminders(sender=self.event)
|
||||
assert len(djmail.outbox) == 2
|
||||
assert djmail.outbox[0].to == ['dummy@dummy.test']
|
||||
assert djmail.outbox[1].to == ['attendee@dummy.test']
|
||||
assert '/ticket/' in djmail.outbox[1].body
|
||||
assert '/order/' not in djmail.outbox[1].body
|
||||
|
||||
def test_send_not_to_attendees_with_same_address(self):
|
||||
self.event.settings.mail_send_download_reminder_attendee = True
|
||||
self.event.settings.mail_days_download_reminder = 2
|
||||
self.op1.attendee_email = 'dummy@dummy.test'
|
||||
self.op1.save()
|
||||
send_download_reminders(sender=self.event)
|
||||
assert len(djmail.outbox) == 1
|
||||
assert djmail.outbox[0].to == ['dummy@dummy.test']
|
||||
assert '/order/' in djmail.outbox[0].body
|
||||
|
||||
def test_sent_paid_only(self):
|
||||
self.event.settings.mail_days_download_reminder = 2
|
||||
self.order.status = Order.STATUS_PENDING
|
||||
|
||||
@@ -70,6 +70,7 @@ def test_sendmail_simple_case(logged_in_client, sendmail_url, event, order):
|
||||
djmail.outbox = []
|
||||
response = logged_in_client.post(sendmail_url,
|
||||
{'sendto': 'n',
|
||||
'recipients': 'orders',
|
||||
'items': order.positions.first().item_id,
|
||||
'subject_0': 'Test subject',
|
||||
'message_0': 'This is a test file for sending mails.'
|
||||
@@ -95,6 +96,7 @@ def test_sendmail_email_not_sent_if_order_not_match(logged_in_client, sendmail_u
|
||||
djmail.outbox = []
|
||||
response = logged_in_client.post(sendmail_url,
|
||||
{'sendto': 'p',
|
||||
'recipients': 'orders',
|
||||
'items': order.positions.first().item_id,
|
||||
'subject_0': 'Test subject',
|
||||
'message_0': 'This is a test file for sending mails.'
|
||||
@@ -110,6 +112,7 @@ def test_sendmail_preview(logged_in_client, sendmail_url, event, order):
|
||||
djmail.outbox = []
|
||||
response = logged_in_client.post(sendmail_url,
|
||||
{'sendto': 'n',
|
||||
'recipients': 'orders',
|
||||
'items': order.positions.first().item_id,
|
||||
'subject_0': 'Test subject',
|
||||
'message_0': 'This is a test file for sending mails.',
|
||||
@@ -127,6 +130,7 @@ def test_sendmail_invalid_data(logged_in_client, sendmail_url, event, order):
|
||||
djmail.outbox = []
|
||||
response = logged_in_client.post(sendmail_url,
|
||||
{'sendto': 'n',
|
||||
'recipients': 'orders',
|
||||
'items': order.positions.first().item_id,
|
||||
'subject_0': 'Test subject',
|
||||
},
|
||||
@@ -152,6 +156,7 @@ def test_sendmail_multi_locales(logged_in_client, sendmail_url, event, item):
|
||||
|
||||
response = logged_in_client.post(sendmail_url,
|
||||
{'sendto': 'p',
|
||||
'recipients': 'orders',
|
||||
'items': item.pk,
|
||||
'subject_0': 'Test subject',
|
||||
'message_0': 'Test message',
|
||||
@@ -188,6 +193,7 @@ def test_sendmail_subevents(logged_in_client, sendmail_url, event, order):
|
||||
djmail.outbox = []
|
||||
response = logged_in_client.post(sendmail_url,
|
||||
{'sendto': 'n',
|
||||
'recipients': 'orders',
|
||||
'items': order.positions.first().item_id,
|
||||
'subject_0': 'Test subject',
|
||||
'message_0': 'This is a test file for sending mails.',
|
||||
@@ -201,6 +207,7 @@ def test_sendmail_subevents(logged_in_client, sendmail_url, event, order):
|
||||
djmail.outbox = []
|
||||
response = logged_in_client.post(sendmail_url,
|
||||
{'sendto': 'n',
|
||||
'recipients': 'orders',
|
||||
'items': order.positions.first().item_id,
|
||||
'subject_0': 'Test subject',
|
||||
'message_0': 'This is a test file for sending mails.',
|
||||
@@ -221,6 +228,7 @@ def test_sendmail_placeholder(logged_in_client, sendmail_url, event, order):
|
||||
djmail.outbox = []
|
||||
response = logged_in_client.post(sendmail_url,
|
||||
{'sendto': 'n',
|
||||
'recipients': 'orders',
|
||||
'items': order.positions.first().item_id,
|
||||
'subject_0': '{code} Test subject',
|
||||
'message_0': 'This is a test file for sending mails.',
|
||||
@@ -232,3 +240,130 @@ def test_sendmail_placeholder(logged_in_client, sendmail_url, event, order):
|
||||
assert 'ORDER1234' in response.rendered_content
|
||||
|
||||
assert len(djmail.outbox) == 0
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_sendmail_attendee_mails(logged_in_client, sendmail_url, event, order):
|
||||
p = order.positions.first()
|
||||
event.settings.attendee_emails_asked = True
|
||||
p.attendee_email = 'attendee@dummy.test'
|
||||
p.save()
|
||||
|
||||
djmail.outbox = []
|
||||
response = logged_in_client.post(sendmail_url,
|
||||
{'sendto': 'n',
|
||||
'recipients': 'attendees',
|
||||
'items': order.positions.first().item_id,
|
||||
'subject_0': 'Test subject',
|
||||
'message_0': 'This is a test file for sending mails.'
|
||||
},
|
||||
follow=True)
|
||||
assert response.status_code == 200
|
||||
assert 'alert-success' in response.rendered_content
|
||||
assert len(djmail.outbox) == 1
|
||||
assert djmail.outbox[0].to == ['attendee@dummy.test']
|
||||
assert '/ticket/' in djmail.outbox[0].body
|
||||
assert '/order/' not in djmail.outbox[0].body
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_sendmail_both_mails(logged_in_client, sendmail_url, event, order):
|
||||
p = order.positions.first()
|
||||
event.settings.attendee_emails_asked = True
|
||||
p.attendee_email = 'attendee@dummy.test'
|
||||
p.save()
|
||||
|
||||
djmail.outbox = []
|
||||
response = logged_in_client.post(sendmail_url,
|
||||
{'sendto': 'n',
|
||||
'recipients': 'both',
|
||||
'items': order.positions.first().item_id,
|
||||
'subject_0': 'Test subject',
|
||||
'message_0': 'This is a test file for sending mails.'
|
||||
},
|
||||
follow=True)
|
||||
assert response.status_code == 200
|
||||
assert 'alert-success' in response.rendered_content
|
||||
assert len(djmail.outbox) == 2
|
||||
assert djmail.outbox[0].to == ['attendee@dummy.test']
|
||||
assert '/ticket/' in djmail.outbox[0].body
|
||||
assert '/order/' not in djmail.outbox[0].body
|
||||
assert djmail.outbox[1].to == ['dummy@dummy.test']
|
||||
assert '/ticket/' not in djmail.outbox[1].body
|
||||
assert '/order/' in djmail.outbox[1].body
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_sendmail_both_but_same_address(logged_in_client, sendmail_url, event, order):
|
||||
p = order.positions.first()
|
||||
event.settings.attendee_emails_asked = True
|
||||
p.attendee_email = 'dummy@dummy.test'
|
||||
p.save()
|
||||
|
||||
djmail.outbox = []
|
||||
response = logged_in_client.post(sendmail_url,
|
||||
{'sendto': 'n',
|
||||
'recipients': 'both',
|
||||
'items': order.positions.first().item_id,
|
||||
'subject_0': 'Test subject',
|
||||
'message_0': 'This is a test file for sending mails.'
|
||||
},
|
||||
follow=True)
|
||||
assert response.status_code == 200
|
||||
assert 'alert-success' in response.rendered_content
|
||||
assert len(djmail.outbox) == 1
|
||||
assert djmail.outbox[0].to == ['dummy@dummy.test']
|
||||
assert '/ticket/' not in djmail.outbox[0].body
|
||||
assert '/order/' in djmail.outbox[0].body
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_sendmail_attendee_fallback(logged_in_client, sendmail_url, event, order):
|
||||
p = order.positions.first()
|
||||
event.settings.attendee_emails_asked = True
|
||||
p.attendee_email = None
|
||||
p.save()
|
||||
|
||||
djmail.outbox = []
|
||||
response = logged_in_client.post(sendmail_url,
|
||||
{'sendto': 'n',
|
||||
'recipients': 'attendees',
|
||||
'items': order.positions.first().item_id,
|
||||
'subject_0': 'Test subject',
|
||||
'message_0': 'This is a test file for sending mails.'
|
||||
},
|
||||
follow=True)
|
||||
assert response.status_code == 200
|
||||
assert 'alert-success' in response.rendered_content
|
||||
assert len(djmail.outbox) == 1
|
||||
assert djmail.outbox[0].to == ['dummy@dummy.test']
|
||||
assert '/ticket/' not in djmail.outbox[0].body
|
||||
assert '/order/' in djmail.outbox[0].body
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_sendmail_attendee_product_filter(logged_in_client, sendmail_url, event, order):
|
||||
event.settings.attendee_emails_asked = True
|
||||
i2 = Item.objects.create(name='Test item', event=event, default_price=13)
|
||||
p = order.positions.first()
|
||||
p.attendee_email = 'attendee1@dummy.test'
|
||||
p.save()
|
||||
order.positions.create(
|
||||
item=i2, price=0, attendee_email='attendee2@dummy.test'
|
||||
)
|
||||
|
||||
djmail.outbox = []
|
||||
response = logged_in_client.post(sendmail_url,
|
||||
{'sendto': 'n',
|
||||
'recipients': 'attendees',
|
||||
'items': i2.pk,
|
||||
'subject_0': 'Test subject',
|
||||
'message_0': 'This is a test file for sending mails.'
|
||||
},
|
||||
follow=True)
|
||||
assert response.status_code == 200
|
||||
assert 'alert-success' in response.rendered_content
|
||||
assert len(djmail.outbox) == 1
|
||||
assert djmail.outbox[0].to == ['attendee2@dummy.test']
|
||||
assert '/ticket/' in djmail.outbox[0].body
|
||||
assert '/order/' not in djmail.outbox[0].body
|
||||
|
||||
@@ -130,6 +130,29 @@ class OrdersTest(TestCase):
|
||||
)
|
||||
assert response.status_code == 404
|
||||
|
||||
def test_unknown_position(self):
|
||||
response = self.client.get(
|
||||
'/%s/%s/ticket/ABCDE/1/123/' % (self.orga.slug, self.event.slug)
|
||||
)
|
||||
assert response.status_code == 404
|
||||
response = self.client.get(
|
||||
'/%s/%s/ticket/%s/1/123/' % (self.orga.slug, self.event.slug, self.order.code)
|
||||
)
|
||||
assert response.status_code == 404
|
||||
response = self.client.get(
|
||||
'/%s/%s/ticket/%s/1/%s/' % (self.orga.slug, self.event.slug, self.order.code, self.order.secret)
|
||||
)
|
||||
assert response.status_code == 404
|
||||
response = self.client.get(
|
||||
'/%s/%s/ticket/%s/1/123/' % (self.orga.slug, self.event.slug, self.not_my_order.code)
|
||||
)
|
||||
assert response.status_code == 404
|
||||
response = self.client.get(
|
||||
'/%s/%s/ticket/%s/%s/%s/' % (self.orga.slug, self.event.slug, self.order.code,
|
||||
self.deleted_pos.positionid, self.deleted_pos.web_secret)
|
||||
)
|
||||
assert response.status_code == 404
|
||||
|
||||
def test_orders_confirm_email(self):
|
||||
response = self.client.get(
|
||||
'/%s/%s/order/%s/%s/open/%s/' % (self.orga.slug, self.event.slug, self.order.code, self.order.secret, 'aabbccdd')
|
||||
@@ -156,6 +179,18 @@ class OrdersTest(TestCase):
|
||||
assert "Peter" in response.rendered_content
|
||||
assert "Lukas" not in response.rendered_content
|
||||
|
||||
def test_ticket_detail(self):
|
||||
response = self.client.get(
|
||||
'/%s/%s/ticket/%s/%s/%s/' % (self.orga.slug, self.event.slug, self.order.code,
|
||||
self.ticket_pos.positionid, self.ticket_pos.web_secret)
|
||||
)
|
||||
assert response.status_code == 200
|
||||
doc = BeautifulSoup(response.rendered_content, "lxml")
|
||||
assert len(doc.select(".cart-row")) > 0
|
||||
assert "pending" in doc.select(".label-warning")[0].text.lower()
|
||||
assert "Peter" in response.rendered_content
|
||||
assert "Lukas" not in response.rendered_content
|
||||
|
||||
def test_orders_modify_invalid(self):
|
||||
self.order.status = Order.STATUS_CANCELED
|
||||
self.order.save()
|
||||
@@ -432,6 +467,18 @@ class OrdersTest(TestCase):
|
||||
self.order.secret),
|
||||
target_status_code=200)
|
||||
|
||||
def test_ticket_download(self):
|
||||
self.event.settings.set('ticket_download', True)
|
||||
del self.event.settings['ticket_download_date']
|
||||
self.order.status = Order.STATUS_PAID
|
||||
self.order.save()
|
||||
response = self.client.post(
|
||||
'/%s/%s/ticket/%s/%s/%s/download/%d/testdummy' % (self.orga.slug, self.event.slug, self.order.code,
|
||||
self.ticket_pos.positionid, self.ticket_pos.web_secret,
|
||||
self.ticket_pos.pk),
|
||||
follow=True)
|
||||
assert response.status_code == 200
|
||||
|
||||
def test_orders_download(self):
|
||||
self.event.settings.set('ticket_download', True)
|
||||
del self.event.settings['ticket_download_date']
|
||||
|
||||
Reference in New Issue
Block a user