Skip to content
Snippets Groups Projects
test_mailutils.py 2.25 KiB
Newer Older
from django.core import mail
from django_q.tasks import result

import pytest
from gregui import mailutils


@pytest.mark.django_db
def test_registration_template(registration_template):
    prefilled_template = {
        "from_email": None,
        "recipient_list": ["test@example.com"],
        "subject": "registration subject",
        "message": """Dette er en automatisk generert melding fra gjesteregistreringstjenesten.
Du har blitt registrert som gjest på InstanceName av Foo Bar.
For å fullføre registreringen av gjestekontoen følg denne lenken: www.google.com

This message has been automatically generated by the guest registration system.
You have been registered as a guest at InstanceName by Foo Bar.
To complete the registration of your guest account, please follow this link: www.google.com""",
    }
    rendered_template = mailutils.registration_template(
        "InstanceName", "Foo Bar", "test@example.com"
    )
    assert rendered_template == prefilled_template


@pytest.mark.django_db
def test_confirmation_template(confirmation_template):
    prefilled_template = {
        "from_email": None,
        "recipient_list": ["test@example.com"],
        "subject": "confirmation subject",
        "message": """Dette er en automatisk generert melding fra gjesteregistreringstjenesten.
Din gjest, Foo Bar, har fullført registrering, bekreft gjesten her: www.google.com

This message has been automatically generated by the guest registration system.
Your guest, Foo Bar, has completed their registration, please confirm the guest here: www.google.com""",
    }
    rendered_template = mailutils.confirmation_template("Foo Bar", "test@example.com")
    assert rendered_template == prefilled_template


@pytest.mark.django_db
def test_registration_mail(registration_template):
    mail.outbox = []
    task_id = mailutils.send_registration_mail("test@example.no", "Foo")
    assert result(task_id) == 1
    assert len(mail.outbox) == 1
    assert mail.outbox[0].to == ["test@example.no"]


@pytest.mark.django_db
def test_confirmation_mail(confirmation_template):
    mail.outbox = []
    task_id = mailutils.send_confirmation_mail("test@example.no", "Foo")
    assert result(task_id) == 1
    assert len(mail.outbox) == 1
    assert mail.outbox[0].to == ["test@example.no"]