Passed
Push — main ( 0a4857...063608 )
by Jochen
04:48
created

test_multiple_tickets_sold()   A

Complexity

Conditions 2

Size

Total Lines 28
Code Lines 19

Duplication

Lines 28
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 19
nop 4
dl 28
loc 28
rs 9.45
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 unittest.mock import patch
7
8
import byceps.announce.connections  # Connect signal handlers.
9
from byceps.events.ticketing import TicketCheckedIn, TicketsSold
10
from byceps.services.ticketing.transfer.models import TicketSaleStats
11
from byceps.signals import ticketing as ticketing_signals
12
13
from .helpers import (
14
    assert_submitted_data,
15
    CHANNEL_ORGA_LOG,
16
    mocked_irc_bot,
17
    now,
18
)
19
20
21
EXPECTED_CHANNEL = CHANNEL_ORGA_LOG
22
23
24
def test_ticket_checked_in(app, make_user, admin_user):
25
    expected_text = (
26
        'Admin hat Ticket "GTFIN", genutzt von Einchecker, eingecheckt.'
27
    )
28
29
    user = make_user('Einchecker')
30
31
    event = TicketCheckedIn(
32
        occurred_at=now(),
33
        initiator_id=admin_user.id,
34
        initiator_screen_name=admin_user.screen_name,
35
        ticket_id=None,
36
        ticket_code='GTFIN',
37
        occupied_seat_id=None,
38
        user_id=user.id,
39
        user_screen_name=user.screen_name,
40
    )
41
42
    with mocked_irc_bot() as mock:
43
        ticketing_signals.ticket_checked_in.send(None, event=event)
44
45
    assert_submitted_data(mock, EXPECTED_CHANNEL, expected_text)
46
47
48 View Code Duplication
@patch('byceps.services.ticketing.ticket_service.get_ticket_sale_stats')
1 ignored issue
show
Duplication introduced by Jochen Kupperschmidt
This code seems to be duplicated in your project.
Loading history...
49
def test_single_ticket_sold(get_ticket_sale_stats_mock, app, make_user, admin_user):
50
    expected_text = (
51
        'Neuling hat 1 Ticket bezahlt. '
52
        'Aktuell sind 772 von 1001 Tickets bezahlt.'
53
    )
54
55
    get_ticket_sale_stats_mock.return_value = TicketSaleStats(
56
        tickets_max=1001,
57
        tickets_sold=772,
58
    )
59
60
    user = make_user('Neuling')
61
62
    event = TicketsSold(
63
        occurred_at=now(),
64
        initiator_id=admin_user.id,
65
        initiator_screen_name=admin_user.screen_name,
66
        party_id='popular-party',
67
        owner_id=user.id,
68
        owner_screen_name=user.screen_name,
69
        quantity=1,
70
    )
71
72
    with mocked_irc_bot() as mock:
73
        ticketing_signals.tickets_sold.send(None, event=event)
74
75
    assert_submitted_data(mock, EXPECTED_CHANNEL, expected_text)
76
77
78 View Code Duplication
@patch('byceps.services.ticketing.ticket_service.get_ticket_sale_stats')
1 ignored issue
show
Duplication introduced by Jochen Kupperschmidt
This code seems to be duplicated in your project.
Loading history...
79
def test_multiple_tickets_sold(get_ticket_sale_stats_mock, app, make_user, admin_user):
80
    expected_text = (
81
        'TreuerKäufer hat 3 Tickets bezahlt. '
82
        'Aktuell sind 775 von 1001 Tickets bezahlt.'
83
    )
84
85
    get_ticket_sale_stats_mock.return_value = TicketSaleStats(
86
        tickets_max=1001,
87
        tickets_sold=775,
88
    )
89
90
    user = make_user('TreuerKäufer')
91
92
    event = TicketsSold(
93
        occurred_at=now(),
94
        initiator_id=admin_user.id,
95
        initiator_screen_name=admin_user.screen_name,
96
        party_id='popular-party',
97
        owner_id=user.id,
98
        owner_screen_name=user.screen_name,
99
        quantity=3,
100
    )
101
102
    with mocked_irc_bot() as mock:
103
        ticketing_signals.tickets_sold.send(None, event=event)
104
105
    assert_submitted_data(mock, EXPECTED_CHANNEL, expected_text)
106