Passed
Push — main ( 1f94b4...a29a2e )
by Jochen
04:44
created

test_get_config_with_ssl()   A

Complexity

Conditions 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
"""
2
:Copyright: 2006-2021 Jochen Kupperschmidt
3
:License: Revised BSD (see `LICENSE` file for details)
4
"""
5
6
from flask import Flask
7
8
from byceps import config_defaults
9
from byceps.email import _get_config
10
11
12
def test_get_config_with_defaults():
13
    app = create_app()
14
15
    actual = _get_config(app)
16
17
    assert actual == {
18
        'transport.use': 'smtp',
19
        'transport.host': 'localhost',
20
        'transport.port': 25,
21
        'transport.debug': False,
22
        'message.author': 'BYCEPS <[email protected]>',
23
    }
24
25
26
def test_get_config_with_custom_values():
27
    app = create_app()
28
    app.config.update(
29
        {
30
            'MAIL_SERVER': 'mail.server.example',
31
            'MAIL_PORT': 2525,
32
            'MAIL_DEBUG': True,
33
            'MAIL_DEFAULT_SENDER': 'Mailer <[email protected]>',
34
            'MAIL_USERNAME': 'paperboy',
35
            'MAIL_PASSWORD': 'secret!',
36
        }
37
    )
38
39
    actual = _get_config(app)
40
41
    assert actual == {
42
        'transport.use': 'smtp',
43
        'transport.host': 'mail.server.example',
44
        'transport.port': 2525,
45
        'transport.debug': True,
46
        'transport.username': 'paperboy',
47
        'transport.password': 'secret!',
48
        'message.author': 'Mailer <[email protected]>',
49
    }
50
51
52
def test_get_config_with_ssl():
53
    app = create_app()
54
    app.config['MAIL_USE_SSL'] = True
55
56
    actual = _get_config(app)
57
58
    assert actual['transport.tls'] == 'ssl'
59
60
61
def test_get_config_with_tls():
62
    app = create_app()
63
    app.config['MAIL_USE_TLS'] = True
64
65
    actual = _get_config(app)
66
67
    assert actual['transport.tls'] == 'required'
68
69
70
def test_get_config_with_ssl_and_tls():
71
    # Can only be set to SSL or TLS.
72
    # If both are requested, TLS wins.
73
74
    app = create_app()
75
    app.config['MAIL_USE_SSL'] = True
76
    app.config['MAIL_USE_TLS'] = True
77
78
    actual = _get_config(app)
79
80
    assert actual['transport.tls'] == 'required'
81
82
83
def create_app() -> Flask:
84
    app = Flask(__name__)
85
    app.config.from_object(config_defaults)
86
    return app
87