Fix #543 -- Allow send mail from order (#550)

- Add send email directly for order
- Add email history (from mass and custom) to each specific order
This commit is contained in:
Daniel
2017-07-18 17:45:30 +08:00
committed by Raphael Michel
parent 921834c917
commit b90894c20f
15 changed files with 367 additions and 28 deletions

View File

@@ -452,6 +452,100 @@ def test_order_go_not_found(client, env):
assert response['Location'].endswith('/control/event/dummy/dummy/orders/')
@pytest.fixture
def order_url(env):
event = env[0]
order = env[2]
url = '/control/event/{orga}/{event}/orders/{code}'.format(
event=event.slug, orga=event.organizer.slug, code=order.code
)
return url
@pytest.mark.django_db
def test_order_sendmail_view(client, order_url):
client.login(email='dummy@dummy.dummy', password='dummy')
sendmail_url = order_url + '/sendmail'
response = client.get(sendmail_url)
assert response.status_code == 200
@pytest.mark.django_db
def test_order_sendmail_simple_case(client, order_url, env):
order = env[2]
client.login(email='dummy@dummy.dummy', password='dummy')
sendmail_url = order_url + '/sendmail'
mail.outbox = []
response = client.post(
sendmail_url,
{
'sendto': order.email,
'subject': 'Test subject',
'message': 'This is a test file for sending mails.'
},
follow=True)
assert response.status_code == 200
assert 'alert-success' in response.rendered_content
assert len(mail.outbox) == 1
assert mail.outbox[0].to == [order.email]
assert mail.outbox[0].subject == 'Test subject'
assert 'This is a test file for sending mails.' in mail.outbox[0].body
mail_history_url = order_url + '/mail_history'
response = client.get(mail_history_url)
assert response.status_code == 200
assert 'Test subject' in response.rendered_content
@pytest.mark.django_db
def test_order_sendmail_preview(client, order_url, env):
order = env[2]
client.login(email='dummy@dummy.dummy', password='dummy')
sendmail_url = order_url + '/sendmail'
mail.outbox = []
response = client.post(
sendmail_url,
{
'sendto': order.email,
'subject': 'Test subject',
'message': 'This is a test file for sending mails.',
'action': 'preview'
},
follow=True)
assert response.status_code == 200
assert 'E-mail preview' in response.rendered_content
assert len(mail.outbox) == 0
@pytest.mark.django_db
def test_order_sendmail_invalid_data(client, order_url, env):
order = env[2]
client.login(email='dummy@dummy.dummy', password='dummy')
sendmail_url = order_url + '/sendmail'
mail.outbox = []
response = client.post(
sendmail_url,
{
'sendto': order.email,
'subject': 'Test invalid mail',
},
follow=True)
assert 'has-error' in response.rendered_content
assert len(mail.outbox) == 0
mail_history_url = order_url + '/mail_history'
response = client.get(mail_history_url)
assert response.status_code == 200
assert 'Test invalid mail' not in response.rendered_content
class OrderChangeTests(SoupTest):
def setUp(self):
super().setUp()

View File

@@ -39,7 +39,7 @@ def order(item):
o = Order.objects.create(event=item.event, status=Order.STATUS_PENDING,
expires=now() + datetime.timedelta(hours=1),
total=13, code='DUMMY', email='dummy@dummy.test',
datetime=now(), payment_provider='banktransfer')
datetime=now(), payment_provider='banktransfer', locale='en')
OrderPosition.objects.create(order=o, item=item, price=13)
return o