Exemple #1
0
def test_email_action_with_template_body():
    with override_settings(LANGUAGES=(("en", "en"))):
        SUPER_TEST_TEMPLATE_DATA = {
            "en": {
                # English
                "subject": "Hello, {{ name }}!",
                "body_template": "<html><style>.dog-color { color: red; }</style><body>%html_body%</body></html>",
                "body": "Hi, {{ name }}. This is a test.",
                "content_type": "plain"
            }
        }

        if settings.EMAIL_BACKEND != 'django.core.mail.backends.locmem.EmailBackend':
            pytest.skip("Need locmem email backend")

        mail.outbox = []  # Clear the Django testing mail outbox

        event = get_initialized_test_event()
        ctx = Context.from_event(event, shop=factories.get_default_shop())
        ctx.set("name", "Luke J. Warm")  # This variable isn't published by the event, but it's used by the template
        se = SendEmail({
            "template_data": SUPER_TEST_TEMPLATE_DATA,
            "from_email": {"constant": "*****@*****.**"},
            "recipient": {"constant": "*****@*****.**"},
            "language": {"constant": "ja"},
        })
        se.execute(ctx)  # Once
        assert len(mail.outbox) == 1  # 'send_identifier' should ensure this is true
        msg = mail.outbox[0]
        assert msg.to == ['*****@*****.**']
        assert msg.from_email == '*****@*****.**'
        assert ".dog-color { color: red; }" in msg.body
        assert "Luke J. Warm" in msg.body
Exemple #2
0
def test_email_action():
    if settings.EMAIL_BACKEND != 'django.core.mail.backends.locmem.EmailBackend':
        pytest.skip("Need locmem email backend")

    mail.outbox = []  # Clear the Django testing mail outbox

    event = get_initialized_test_event()
    ctx = Context.from_event(event, shop=factories.get_default_shop())
    ctx.set("name", "Luke Warm")  # This variable isn't published by the event, but it's used by the template
    se = SendEmail({
        "template_data": TEST_TEMPLATE_DATA,
        "from_email": {"constant": "*****@*****.**"},
        "recipient": {"constant": "*****@*****.**"},
        "language": {"constant": "ja"},
        "send_identifier": {"constant": "hello, hello, hello"}
    })
    se.execute(ctx)  # Once,
    se.execute(ctx)  # Twice!
    assert len(mail.outbox) == 1  # 'send_identifier' should ensure this is true
    msg = mail.outbox[0]
    assert msg.to == ['*****@*****.**']
    assert msg.from_email == '*****@*****.**'
    assert ctx.get("name").upper() in msg.subject  # The Japanese template upper-cases the name