~homeworkprod/byceps

ref: ee44f550bd6c9f49e72424cd5826669dd1f57c1c byceps/tests/unit/test_email_config.py -rw-r--r-- 1.8 KiB
ee44f550 — Jochen Kupperschmidt Avoid same German translation for different meanings of "cancel" 1 year, 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""
:Copyright: 2006-2021 Jochen Kupperschmidt
: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 <noreply@server.example>',
        'MAIL_USERNAME': 'paperboy',
        'MAIL_PASSWORD': 'secret!',
    })

    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': 'secret!',
        'message.author': 'Mailer <noreply@server.example>',
    }


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'