Automated emails: Extend filter by check-in state (#3489)

Co-authored-by: Richard Schreiber <schreiber@rami.io>
Co-authored-by: Raphael Michel <michel@rami.io>
This commit is contained in:
Phin Wolkwitz
2023-08-23 16:19:27 +02:00
committed by GitHub
parent c2b25bad06
commit 4baf317934
9 changed files with 220 additions and 14 deletions

View File

@@ -39,7 +39,8 @@ TEST_RULE_RES = {
'template': {'en': 'foo'},
'all_products': True,
'limit_products': [],
"restrict_to_status": ['p', 'n__valid_if_pending'],
'restrict_to_status': ['p', 'n__valid_if_pending'],
'checked_in_status': None,
'send_date': '2021-07-08T00:00:00Z',
'send_offset_days': None,
'send_offset_time': None,
@@ -160,7 +161,8 @@ def test_sendmail_rule_create_full(token_client, organizer, event, item):
'template': {'en': 'foobar'},
'all_products': False,
'limit_products': [event.items.first().pk],
"restrict_to_status": ['p', 'n__not_pending_approval_and_not_valid_if_pending', 'n__valid_if_pending'],
'restrict_to_status': ['p', 'n__not_pending_approval_and_not_valid_if_pending', 'n__valid_if_pending'],
'checked_in_status': None,
'send_offset_days': 3,
'send_offset_time': '09:30',
'date_is_absolute': False,
@@ -174,6 +176,7 @@ def test_sendmail_rule_create_full(token_client, organizer, event, item):
assert r.all_products is False
assert [i.pk for i in r.limit_products.all()] == [event.items.first().pk]
assert r.restrict_to_status == ['p', 'n__not_pending_approval_and_not_valid_if_pending', 'n__valid_if_pending']
assert r.checked_in_status is None
assert r.send_offset_days == 3
assert r.send_offset_time == datetime.time(9, 30)
assert r.date_is_absolute is False
@@ -348,6 +351,49 @@ def test_sendmail_rule_restrict_recipients(token_client, organizer, event, rule)
)
@scopes_disabled()
@pytest.mark.django_db
def test_sendmail_rule_checkin(token_client, organizer, event, rule):
valid_states = [None, 'checked_in', 'no_checkin', ]
invalid_states = ['', 'foo']
for s in valid_states:
result = create_rule(
token_client, organizer, event,
data={
'subject': {'en': 'meow'},
'template': {'en': 'creative text here'},
'send_date': '2018-03-17T13:31Z',
'checked_in_status': s,
},
expected_failure=False
)
assert result.checked_in_status == s
for s in invalid_states:
create_rule(
token_client, organizer, event,
data={
'subject': {'en': 'meow'},
'template': {'en': 'creative text here'},
'send_date': '2018-03-17T13:31Z',
'checked_in_status': s,
},
expected_failure=True
)
result = create_rule(
token_client, organizer, event,
data={
'subject': {'en': 'meow'},
'template': {'en': 'creative text here'},
'send_date': '2018-03-17T13:31Z',
},
expected_failure=False
)
assert result.checked_in_status is None
@scopes_disabled()
@pytest.mark.django_db
def test_sendmail_rule_change(token_client, organizer, event, rule):

View File

@@ -29,6 +29,7 @@ from django.utils.timezone import now
from django_scopes import scopes_disabled
from pretix.base.models import InvoiceAddress, Order
from pretix.base.services.checkin import perform_checkin
from pretix.plugins.sendmail.models import Rule, ScheduledMail
from pretix.plugins.sendmail.signals import sendmail_run_rules
@@ -276,6 +277,100 @@ def test_sendmail_rule_send_correct_products(event, order, item, item2):
assert djmail.outbox[0].to[0] == p1.attendee_email
@pytest.mark.django_db
@scopes_disabled()
def test_sendmail_rule_not_checked_in_all_get_mail(event, order, item):
order.status = Order.STATUS_PAID
order.save()
event.sendmail_rules.create(send_date=dt_now - datetime.timedelta(hours=1), checked_in_status="all",
subject='meow', template='meow meow meow')
djmail.outbox = []
sendmail_run_rules(None)
assert len(djmail.outbox) == 1, "email not sent"
@pytest.mark.django_db
@scopes_disabled()
def test_sendmail_rule_checked_in_all_get_mail(event, order, item):
order.status = Order.STATUS_PAID
order.save()
p1 = order.all_positions.create(item=item, price=13, attendee_email='item1@dummy.test')
clist = event.checkin_lists.create(name="Default", all_products=True)
perform_checkin(p1, clist, {})
event.sendmail_rules.create(send_date=dt_now - datetime.timedelta(hours=1), checked_in_status="all",
subject='meow', template='meow meow meow')
djmail.outbox = []
sendmail_run_rules(None)
assert len(djmail.outbox) == 1, "email not sent"
@pytest.mark.django_db
@scopes_disabled()
def test_sendmail_rule_not_checked_in_no_mail(event, order, item):
order.status = Order.STATUS_PAID
order.save()
event.sendmail_rules.create(send_date=dt_now - datetime.timedelta(hours=1), checked_in_status="checked_in",
subject='meow', template='meow meow meow')
# receives no mail when not checked in
djmail.outbox = []
sendmail_run_rules(None)
assert len(djmail.outbox) == 0, "email sent unexpectedly"
@pytest.mark.django_db
@scopes_disabled()
def test_sendmail_rule_not_checked_in_get_mail(event, order, item):
order.status = Order.STATUS_PAID
order.save()
order.all_positions.create(item=item, price=13, attendee_email='item1@dummy.test')
event.sendmail_rules.create(send_date=dt_now - datetime.timedelta(hours=1), checked_in_status="no_checkin",
subject='meow', template='meow meow meow')
# receives mail when not checked in
djmail.outbox = []
sendmail_run_rules(None)
assert len(djmail.outbox) == 1, "email not sent"
@pytest.mark.django_db
@scopes_disabled()
def test_sendmail_rule_checked_in_no_mail(event, order, item):
order.status = Order.STATUS_PAID
order.save()
p1 = order.all_positions.create(item=item, price=13, attendee_email='item1@dummy.test')
clist = event.checkin_lists.create(name="Default", all_products=True)
# receives no mail when checked in
djmail.outbox = []
perform_checkin(p1, clist, {})
assert clist.checkin_count == 1
event.sendmail_rules.create(send_date=dt_now - datetime.timedelta(hours=1), checked_in_status="no_checkin",
subject='meow', template='meow meow meow')
sendmail_run_rules(None)
assert len(djmail.outbox) == 0, "email sent unexpectedly"
@pytest.mark.django_db
@scopes_disabled()
def test_sendmail_rule_checked_in_get_mail(event, order, item):
order.status = Order.STATUS_PAID
order.save()
p1 = order.all_positions.create(item=item, price=13, attendee_email='item1@dummy.test')
clist = event.checkin_lists.create(name="Default", all_products=True)
# receives mail when checked in
djmail.outbox = []
perform_checkin(p1, clist, {})
assert clist.checkin_count == 1
event.sendmail_rules.create(send_date=dt_now - datetime.timedelta(hours=1), checked_in_status="checked_in",
subject='meow', template='meow meow meow')
sendmail_run_rules(None)
assert len(djmail.outbox) == 1, "email not sent"
@pytest.mark.django_db
@scopes_disabled()
def run_restriction_test(event, order, restrictions_pass=[], restrictions_fail=[]):