from tempfile import NamedTemporaryFile

import pytest


def test_config_template():
    config = {
        'subject': "Test Subject",
        'message': "Test Body",
    }

    from mailer.email_template import EmailTemplate
    tmpl = EmailTemplate.from_config(config)

    assert tmpl.generate({}) == "Subject: Test Subject\n\nTest Body\n"


@pytest.fixture()
def temp_file():
    with NamedTemporaryFile(delete=False) as f:
        yield f


def test_file_template(temp_file):
    temp_file.write(
        b'Subject: This is a test subject\r\n\r\nTest body\r\n{text}\r\n'
    )
    temp_file.flush()

    config = {'file': temp_file.name}
    from mailer.email_template import EmailTemplate
    tmpl = EmailTemplate.from_config(config)

    expected = 'Subject: This is a test subject\n\nTest body\nfoobar\n'

    assert tmpl.generate({'text': 'foobar'}) == expected

04ecfe026c196e5e14a80913fb70e58599b3c830
<mask token>


def test_config_template():
    config = {'subject': 'Test Subject', 'message': 'Test Body'}
    from mailer.email_template import EmailTemplate
    tmpl = EmailTemplate.from_config(config)
    assert tmpl.generate({}) == 'Subject: Test Subject\n\nTest Body\n'


<mask token>

<mask token>


def test_config_template():
    config = {'subject': 'Test Subject', 'message': 'Test Body'}
    from mailer.email_template import EmailTemplate
    tmpl = EmailTemplate.from_config(config)
    assert tmpl.generate({}) == 'Subject: Test Subject\n\nTest Body\n'


<mask token>


def test_file_template(temp_file):
    temp_file.write(
        b'Subject: This is a test subject\r\n\r\nTest body\r\n{text}\r\n')
    temp_file.flush()
    config = {'file': temp_file.name}
    from mailer.email_template import EmailTemplate
    tmpl = EmailTemplate.from_config(config)
    expected = 'Subject: This is a test subject\n\nTest body\nfoobar\n'
    assert tmpl.generate({'text': 'foobar'}) == expected

<mask token>


def test_config_template():
    config = {'subject': 'Test Subject', 'message': 'Test Body'}
    from mailer.email_template import EmailTemplate
    tmpl = EmailTemplate.from_config(config)
    assert tmpl.generate({}) == 'Subject: Test Subject\n\nTest Body\n'


@pytest.fixture()
def temp_file():
    with NamedTemporaryFile(delete=False) as f:
        yield f


def test_file_template(temp_file):
    temp_file.write(
        b'Subject: This is a test subject\r\n\r\nTest body\r\n{text}\r\n')
    temp_file.flush()
    config = {'file': temp_file.name}
    from mailer.email_template import EmailTemplate
    tmpl = EmailTemplate.from_config(config)
    expected = 'Subject: This is a test subject\n\nTest body\nfoobar\n'
    assert tmpl.generate({'text': 'foobar'}) == expected

from tempfile import NamedTemporaryFile
import pytest


def test_config_template():
    config = {'subject': 'Test Subject', 'message': 'Test Body'}
    from mailer.email_template import EmailTemplate
    tmpl = EmailTemplate.from_config(config)
    assert tmpl.generate({}) == 'Subject: Test Subject\n\nTest Body\n'


@pytest.fixture()
def temp_file():
    with NamedTemporaryFile(delete=False) as f:
        yield f


def test_file_template(temp_file):
    temp_file.write(
        b'Subject: This is a test subject\r\n\r\nTest body\r\n{text}\r\n')
    temp_file.flush()
    config = {'file': temp_file.name}
    from mailer.email_template import EmailTemplate
    tmpl = EmailTemplate.from_config(config)
    expected = 'Subject: This is a test subject\n\nTest body\nfoobar\n'
    assert tmpl.generate({'text': 'foobar'}) == expected

from tempfile import NamedTemporaryFile

import pytest


def test_config_template():
    config = {
        'subject': "Test Subject",
        'message': "Test Body",
    }

    from mailer.email_template import EmailTemplate
    tmpl = EmailTemplate.from_config(config)

    assert tmpl.generate({}) == "Subject: Test Subject\n\nTest Body\n"


@pytest.fixture()
def temp_file():
    with NamedTemporaryFile(delete=False) as f:
        yield f


def test_file_template(temp_file):
    temp_file.write(
        b'Subject: This is a test subject\r\n\r\nTest body\r\n{text}\r\n'
    )
    temp_file.flush()

    config = {'file': temp_file.name}
    from mailer.email_template import EmailTemplate
    tmpl = EmailTemplate.from_config(config)

    expected = 'Subject: This is a test subject\n\nTest body\nfoobar\n'

    assert tmpl.generate({'text': 'foobar'}) == expected
