Beispiel #1
0
def test_queue_mail_message_and_send_via_mandrill(settings):
    settings.EMAIL_BACKEND = "djrill.mail.backends.djrill.DjrillBackend"
    with mock.patch('django.core.mail.EmailMultiAlternatives') as mock_mail:
        mock_mail.return_value.mandrill_response = [{
            "email": "*****@*****.**",
            "status": "sent",
            "_id": "123",
            "reject_reason": None,
        }]
        email_address = get_env_variable('TEST_EMAIL_ADDRESS_2')
        enquiry = make_enquiry(
            email_address,
            "Welcome",
            'Can I join your club?',
        )
        template = _create_goodbye_mandrill_template()
        content_data = {
            email_address: {
                "name": "Fred",
                "title": "SpaceX",
                "question": enquiry.description
            }
        }
        queue_mail_template(enquiry, template.slug, content_data)
        m = _mail(enquiry)
        assert m.sent is None
        assert m.sent_response_code is None
        assert m.message.subject == 'Goodbye *|name|*'
        # test the send facility using djrill mail backend
        # temp_email_backend = settings.EMAIL_BACKEND
        send_mail()
        m = _mail(enquiry)
        assert m.sent is not None
        assert m.sent_response_code is not None
Beispiel #2
0
def test_queue_no_email():
    email_address = get_env_variable('TEST_EMAIL_ADDRESS_1')
    enquiry = make_enquiry(
        email_address,
        "Farming",
        'How many cows in the field?',
    )
    with pytest.raises(MailError) as e:
        queue_mail_message(
            enquiry,
            [],
            enquiry.subject,
            enquiry.description,
        )
    expect = "Cannot 'queue_mail_message' without 'email_addresses'"
    assert expect in str(e.value)
Beispiel #3
0
def _queue_enquiry(attachments=None):
    if not attachments:
        attachments = []
    email_address = get_env_variable('TEST_EMAIL_ADDRESS_1')
    enquiry = make_enquiry(
        email_address,
        "Farming",
        'How many cows in the field?',
    )
    queue_mail_message(
        enquiry,
        [enquiry.email, ],
        enquiry.subject,
        enquiry.description,
        attachments=attachments,
    )
    return enquiry
Beispiel #4
0
def test_queue_mail_message():
    email_address = get_env_variable('TEST_EMAIL_ADDRESS_2')
    if not email_address:
        raise MailError("Cannot test without a 'TEST_EMAIL_ADDRESS_2'")
    enquiry = make_enquiry(
        email_address,
        "Welcome",
        'Can I join your club?',
    )
    template = _create_welcome_template()
    content_data = {
        email_address: {
            "name": "Fred",
            "title": "SpaceX",
            "question": enquiry.description
        }
    }
    queue_mail_template(enquiry, template.slug, content_data)
    message = Message.objects.get(subject='Welcome {{name}}')
    mail_item = Mail.objects.get(email=email_address)
    assert message == mail_item.message
    assert enquiry == mail_item.message.content_object
Beispiel #5
0
def test_queue_mail_message():
    email_address = get_env_variable('TEST_EMAIL_ADDRESS_2')
    if not email_address:
        raise MailError("Cannot test without a 'TEST_EMAIL_ADDRESS_2'")
    enquiry = make_enquiry(
        email_address,
        "Welcome",
        'Can I join your club?',
    )
    template = _create_welcome_template()
    content_data = {
        email_address: {
            "name": "Fred",
            "title": "SpaceX",
            "question": enquiry.description,
            "dict": {'age': 52, 'colour': 'blue'},
            "list": [1, 3, 9],
        }
    }
    queue_mail_template(enquiry, template.slug, content_data)
    message = Message.objects.get(subject='Welcome {{name}}')
    mail_item = Mail.objects.get(email=email_address)
    assert message == mail_item.message
    assert enquiry == mail_item.message.content_object
    # name
    obj = MailField.objects.get(key='name')
    assert 'Fred' == obj.value
    assert obj.is_json is False
    # dict
    obj = MailField.objects.get(key='dict')
    assert obj.is_json is True
    assert {'age': 52, 'colour': 'blue'} == json.loads(obj.value)
    # list
    obj = MailField.objects.get(key='list')
    assert obj.is_json is True
    assert [1, 3, 9] == json.loads(obj.value)