Completed
Push — main ( cd54d0...3ec8de )
by Jochen
03:28
created

ticket_quantity()   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 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
"""
2
:Copyright: 2006-2020 Jochen Kupperschmidt
3
:License: Modified BSD, see LICENSE for details.
4
"""
5
6
import pytest
7
8
from byceps.services.shop.order import action_service, action_registry_service
9
from byceps.services.shop.order import event_service as order_event_service
10
from byceps.services.shop.order import service as order_service
11
from byceps.services.ticketing import ticket_service
12
13
from .helpers import get_tickets_for_order, mark_order_as_paid, place_order
14
15
16
@pytest.fixture(scope='module')
17
def ticket_quantity():
18
    return 4
19
20
21
@pytest.fixture
22
def order(article, ticket_quantity, storefront, orderer):
23
    articles_with_quantity = [(article, ticket_quantity)]
24
    order = place_order(storefront.id, orderer, articles_with_quantity)
25
26
    yield order
27
28
    order_service.delete_order(order.id)
29
30
31
@pytest.fixture
32
def order_action(article, ticket_category):
33
    action_registry_service.register_tickets_creation(
34
        article.item_number, ticket_category.id
35
    )
36
37
    yield
38
39
    action_service.delete_actions(article.item_number)
40
41
42 View Code Duplication
def test_create_tickets(
1 ignored issue
show
Duplication introduced by Jochen Kupperschmidt
This code seems to be duplicated in your project.
Loading history...
43
    admin_app,
44
    article,
45
    ticket_category,
46
    ticket_quantity,
47
    admin_user,
48
    orderer,
49
    order,
50
    order_action,
51
):
52
    tickets_before_paid = get_tickets_for_order(order)
53
    assert len(tickets_before_paid) == 0
54
55
    mark_order_as_paid(order.id, admin_user.id)
56
57
    tickets_after_paid = get_tickets_for_order(order)
58
    assert len(tickets_after_paid) == ticket_quantity
59
60
    for ticket in tickets_after_paid:
61
        assert ticket.owned_by_id == orderer.user_id
62
        assert ticket.used_by_id == orderer.user_id
63
64
    events = order_event_service.get_events_for_order(order.id)
65
    ticket_created_events = {
66
        event for event in events if event.event_type == 'ticket-created'
67
    }
68
    assert len(ticket_created_events) == ticket_quantity
69
70
    # Clean up.
71
    for ticket in tickets_after_paid:
72
        ticket_service.delete_ticket(ticket.id)
73