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

tests.integration.services.shop.order.email.test_email_on_order_placed.create_email_footer_snippet()   A

Complexity

Conditions 1

Size

Total Lines 6
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nop 2
dl 0
loc 6
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 datetime import datetime
7
from decimal import Decimal
8
from typing import Iterator
9
from unittest.mock import patch
10
11
import pytest
12
13
from byceps.services.shop.article import service as article_service
14
from byceps.services.shop.order.email import service as order_email_service
15
from byceps.services.shop.order import (
16
    sequence_service as order_sequence_service,
17
    service as order_service,
18
)
19
from byceps.services.shop.storefront import service as storefront_service
20
from byceps.services.shop.storefront.transfer.models import Storefront
21
from byceps.services.snippet import service as snippet_service
22
23
from tests.helpers import current_user_set
24
from tests.integration.services.shop.helpers import (
25
    create_article as _create_article,
26
)
27
28
from .helpers import (
29
    assert_email,
30
    get_current_user_for_user,
31
    place_order_with_items,
32
)
33
34
35
@pytest.fixture(scope='module')
36
def customer(make_user):
37
    return make_user('Interessent', email_address='[email protected]')
38
39
40
@pytest.fixture
41
def storefront(
42
    make_order_number_sequence_id, make_storefront
43
) -> Iterator[Storefront]:
44
    order_number_sequence_id = make_order_number_sequence_id(252)
45
    storefront = make_storefront(order_number_sequence_id)
46
47
    yield storefront
48
49
    storefront_service.delete_storefront(storefront.id)
50
    order_sequence_service.delete_order_number_sequence(
51
        order_number_sequence_id
52
    )
53
54
55
@pytest.fixture
56
def article1(shop):
57
    article = create_article(
58
        shop.id,
59
        'AC-14-A00003',
60
        'Einzelticket, Kategorie Loge',
61
        Decimal('99.00'),
62
        123,
63
    )
64
    article_id = article.id
65
66
    yield article
67
68
    article_service.delete_article(article_id)
69
70
71
@pytest.fixture
72
def article2(shop):
73
    article = create_article(
74
        shop.id,
75
        'AC-14-A00007',
76
        'T-Shirt, Größe L',
77
        Decimal('14.95'),
78
        50,
79
    )
80
    article_id = article.id
81
82
    yield article
83
84
    article_service.delete_article(article_id)
85
86
87
@pytest.fixture
88
def order(
89
    storefront,
90
    article1,
91
    article2,
92
    customer,
93
    email_payment_instructions_snippet_id,
94
    email_footer_snippet_id,
95
):
96
    created_at = datetime(2014, 8, 15, 20, 7, 43)
97
98
    items_with_quantity = [
99
        (article1, 5),
100
        (article2, 2),
101
    ]
102
103
    order = place_order_with_items(
104
        storefront.id, customer, created_at, items_with_quantity
105
    )
106
107
    yield order
108
109
    snippet_service.delete_snippet(email_payment_instructions_snippet_id)
110
    snippet_service.delete_snippet(email_footer_snippet_id)
111
    order_service.delete_order(order.id)
112
113
114
@patch('byceps.email.send')
115
def test_email_on_order_placed(send_email_mock, site_app, customer, order):
116
    app = site_app
117
118
    current_user = get_current_user_for_user(customer)
119
    with current_user_set(app, current_user), app.app_context():
120
        order_email_service.send_email_for_incoming_order_to_orderer(order.id)
121
122
    expected_sender = '[email protected]'
123
    expected_recipients = ['[email protected]']
124
    expected_subject = 'Deine Bestellung (AC-14-B00253) ist eingegangen.'
125
    expected_body = '''
126
Hallo Interessent,
127
128
vielen Dank für deine Bestellung mit der Nummer AC-14-B00253 am 15.08.2014 über unsere Website.
129
130
Folgende Artikel hast du bestellt:
131
132
  Beschreibung: Einzelticket, Kategorie Loge
133
  Anzahl: 5
134
  Stückpreis: 99,00 €
135
136
  Beschreibung: T-Shirt, Größe L
137
  Anzahl: 2
138
  Stückpreis: 14,95 €
139
140
  Gesamtbetrag: 524,90 €
141
142
Bitte überweise den Gesamtbetrag auf folgendes Konto:
143
144
  Zahlungsempfänger: <Name>
145
  IBAN: <IBAN>
146
  BIC: <BIC>
147
  Bank: <Kreditinstitut>
148
  Verwendungszweck: AC-14-B00253
149
150
Wir werden dich informieren, sobald wir deine Zahlung erhalten haben.
151
152
Hier kannst du deine Bestellungen einsehen: https://www.acmecon.test/shop/orders
153
154
Für Fragen stehen wir gerne zur Verfügung.
155
156
Viele Grüße,
157
das Team der Acme Entertainment Convention
158
159
-- 
160
Acme Entertainment Convention
161
162
E-Mail: [email protected]
163
    '''.strip()
164
165
    assert_email(
166
        send_email_mock,
167
        expected_sender,
168
        expected_recipients,
169
        expected_subject,
170
        expected_body,
171
    )
172
173
174
# helpers
175
176
177
def create_article(shop_id, item_number, description, price, total_quantity):
178
    return _create_article(
179
        shop_id,
180
        item_number=item_number,
181
        description=description,
182
        price=price,
183
        total_quantity=total_quantity,
184
    )
185