Passed
Push — main ( 52c0ea...0cab68 )
by Jochen
04:36
created

orderer()   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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