<commit_before>"""
:Copyright: 2006-2021 <NAME>
:License: Revised BSD (see `LICENSE` file for details)
"""

from flask import Flask

from byceps.email import _get_config


def test_get_config_with_defaults():
    app = Flask(__name__)

    actual = _get_config(app)

    assert actual == {
        'transport.use': 'smtp',
        'transport.host': 'localhost',
        'transport.port': 25,
        'transport.debug': False,
        'message.author': None,
    }


def test_get_config_with_custom_values():
    app = Flask(__name__)
    app.config.update({
        'MAIL_SERVER': 'mail.server.example',
        'MAIL_PORT': 2525,
        'MAIL_DEBUG': True,
        'MAIL_DEFAULT_SENDER': 'Mailer <<EMAIL>>',
        'MAIL_USERNAME': 'paperboy',
        'MAIL_PASSWORD': '<PASSWORD>!',
    })

    actual = _get_config(app)

    assert actual == {
        'transport.use': 'smtp',
        'transport.host': 'mail.server.example',
        'transport.port': 2525,
        'transport.debug': True,
        'transport.username': 'paperboy',
        'transport.password': '<PASSWORD>!',
        'message.author': 'Mailer <<EMAIL>>',
    }


def test_get_config_with_ssl():
    app = Flask(__name__)
    app.config['MAIL_USE_SSL'] = True

    actual = _get_config(app)

    assert actual['transport.tls'] == 'ssl'


def test_get_config_with_tls():
    app = Flask(__name__)
    app.config['MAIL_USE_TLS'] = True

    actual = _get_config(app)

    assert actual['transport.tls'] == 'required'


def test_get_config_with_ssl_and_tls():
    # Can only be set to SSL or TLS.
    # If both are requested, TLS wins.

    app = Flask(__name__)
    app.config['MAIL_USE_SSL'] = True
    app.config['MAIL_USE_TLS'] = True

    actual = _get_config(app)

    assert actual['transport.tls'] == 'required'<commit_msg>Include config defaults in email config unit tests<commit_after>"""
:Copyright: 2006-2021 <NAME>
:License: Revised BSD (see `LICENSE` file for details)
"""

from flask import Flask

from byceps import config_defaults
from byceps.email import _get_config


def test_get_config_with_defaults():
    app = create_app()

    actual = _get_config(app)

    assert actual == {
        'transport.use': 'smtp',
        'transport.host': 'localhost',
        'transport.port': 25,
        'transport.debug': False,
        'message.author': None,
    }


def test_get_config_with_custom_values():
    app = create_app()
    app.config.update(
        {
            'MAIL_SERVER': 'mail.server.example',
            'MAIL_PORT': 2525,
            'MAIL_DEBUG': True,
            'MAIL_DEFAULT_SENDER': 'Mailer <<EMAIL>>',
            'MAIL_USERNAME': 'paperboy',
            'MAIL_PASSWORD': '<PASSWORD>!',
        }
    )

    actual = _get_config(app)

    assert actual == {
        'transport.use': 'smtp',
        'transport.host': 'mail.server.example',
        'transport.port': 2525,
        'transport.debug': True,
        'transport.username': 'paperboy',
        'transport.password': '<PASSWORD>!',
        'message.author': 'Mailer <<EMAIL>>',
    }


def test_get_config_with_ssl():
    app = create_app()
    app.config['MAIL_USE_SSL'] = True

    actual = _get_config(app)

    assert actual['transport.tls'] == 'ssl'


def test_get_config_with_tls():
    app = create_app()
    app.config['MAIL_USE_TLS'] = True

    actual = _get_config(app)

    assert actual['transport.tls'] == 'required'


def test_get_config_with_ssl_and_tls():
    # Can only be set to SSL or TLS.
    # If both are requested, TLS wins.

    app = create_app()
    app.config['MAIL_USE_SSL'] = True
    app.config['MAIL_USE_TLS'] = True

    actual = _get_config(app)

    assert actual['transport.tls'] == 'required'


def create_app() -> Flask:
    app = Flask(__name__)
    app.config.from_object(config_defaults)
    return app
{'fraction_non_alphanumeric': 0.13944954128440368, 'fraction_numerical': 0.00943643512450852, 'mean_word_length': 2.921891058581706, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1341409', 'n_tokens_mistral': 1297, 'n_tokens_neox': 1263, 'n_words': 266}