~homeworkprod/byceps

ref: 1cdb0af44cb0d150869fcffa538240b44be740aa byceps/tests/blueprints/user_message/test_address_formatting.py -rw-r--r-- 1.5 KiB
1cdb0af4 — Jochen Kupperschmidt Obtain website contact e-mail address for user message template from site's e-mail config rather than from brand 2 years 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
"""
:Copyright: 2006-2019 Jochen Kupperschmidt
:License: Modified BSD, see LICENSE for details.
"""

from unittest.mock import patch

import pytest

from byceps.services.email import service as email_service
from byceps.services.user_message import service as user_message_service

from tests.conftest import database_recreated
from tests.helpers import app_context, create_brand, create_party, \
    create_site, create_user


def test_recipient_formatting(application, params):
    screen_name, email_address, expected = params

    brand = create_brand()
    party = create_party(brand.id)

    email_config_id = brand.id
    sender_address = f'{brand.id}@example.com'
    email_service.set_config(email_config_id, sender_address,
                             sender_name=brand.title)

    site = create_site(party.id)

    user = create_user(screen_name, email_address=email_address)

    message = user_message_service.create_message(user.id, user.id, '', '',
                                                  site.id)

    assert message.recipients == [expected]


@pytest.fixture(params=[
    ('Alice', 'alice@example.com', 'Alice <alice@example.com>'),
    ('<AngleInvestor>', 'angleinvestor@example.com', '"<AngleInvestor>" <angleinvestor@example.com>'),
    ('-=]YOLO[=-', 'yolo@example.com', '"-=]YOLO[=-" <yolo@example.com>'),
])
def params(request):
    yield request.param


@pytest.fixture
def application(db):
    with app_context():
        with database_recreated(db):
            yield