Test Failed
Push — main ( e3918a...309543 )
by Jochen
04:24
created

shop/order/email/test_email_on_order_paid.py (1 issue)

1
"""
2
:Copyright: 2006-2021 Jochen Kupperschmidt
3
:License: Revised BSD (see `LICENSE` file for details)
4
"""
5
6
from datetime import datetime
7
from typing import Iterator
8
from unittest.mock import patch
9
10
import pytest
11
12
from byceps.services.shop.order.email import service as order_email_service
13
from byceps.services.shop.order import (
14
    sequence_service as order_sequence_service,
15
    service as order_service,
16
)
17
from byceps.services.shop.storefront import service as storefront_service
18
from byceps.services.shop.storefront.transfer.models import Storefront
19
from byceps.services.snippet import service as snippet_service
20
21
from tests.helpers import current_user_set
22
23
from .helpers import (
24
    assert_email,
25
    get_current_user_for_user,
26
    place_order_with_items,
27
)
28
29
30
@pytest.fixture
31
def customer(make_user):
32
    return make_user('Vorbild', email_address='[email protected]')
33
34
35
@pytest.fixture
36
def storefront(
37
    make_order_number_sequence_id, make_storefront
38
) -> Iterator[Storefront]:
39
    order_number_sequence_id = make_order_number_sequence_id(21)
40
    storefront = make_storefront(order_number_sequence_id)
41
42
    yield storefront
43
44
    storefront_service.delete_storefront(storefront.id)
45
    order_sequence_service.delete_order_number_sequence(
46
        order_number_sequence_id
47
    )
48
49
50 View Code Duplication
@pytest.fixture
1 ignored issue
show
This code seems to be duplicated in your project.
Loading history...
51
def order(storefront, customer, email_footer_snippet_id):
52
    created_at = datetime(2014, 9, 23, 18, 40, 53)
53
54
    order = place_order_with_items(storefront.id, customer, created_at, [])
55
56
    yield order
57
58
    snippet_service.delete_snippet(email_footer_snippet_id)
59
    order_service.delete_order(order.id)
60
61
62
@patch('byceps.email.send')
63
def test_email_on_order_paid(
64
    send_email_mock, site_app, customer, order_admin, order
65
):
66
    app = site_app
67
68
    order_service.mark_order_as_paid(order.id, 'bank_transfer', order_admin.id)
69
70
    current_user = get_current_user_for_user(customer)
71
    with current_user_set(app, current_user), app.app_context():
72
        order_email_service.send_email_for_paid_order_to_orderer(order.id)
73
74
    expected_sender = '[email protected]'
75
    expected_recipients = ['[email protected]']
76
    expected_subject = (
77
        '\u2705 Deine Bestellung (AC-14-B00022) ist bezahlt worden.'
78
    )
79
    expected_body = '''
80
Hallo Vorbild,
81
82
vielen Dank für deine Bestellung mit der Nummer AC-14-B00022 am 23.09.2014 über unsere Website.
83
84
Wir haben deine Zahlung erhalten und deine Bestellung als bezahlt markiert.
85
86
Für Fragen stehen wir gerne zur Verfügung.
87
88
Viele Grüße,
89
das Team der Acme Entertainment Convention
90
91
-- 
92
Acme Entertainment Convention
93
94
E-Mail: [email protected]
95
    '''.strip()
96
97
    assert_email(
98
        send_email_mock,
99
        expected_sender,
100
        expected_recipients,
101
        expected_subject,
102
        expected_body,
103
    )
104