~homeworkprod/byceps

ref: 9f63b62a2b4647a97ebd3b6356d937ffa1d88876 byceps/tests/services/ticketing/test_models.py -rw-r--r-- 3.0 KiB
9f63b62a — Jochen Kupperschmidt Note that Python 3.6 is a supported Python version 4 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
"""
:Copyright: 2006-2017 Jochen Kupperschmidt
:License: Modified BSD, see LICENSE for details.
"""

from uuid import UUID

from nose2.tools import params

from byceps.services.ticketing.models.ticket import Ticket

from testfixtures.user import create_user


ANY_BUNDLE_ID = UUID('4138fcfb-cc18-45c0-aede-d49a8e279885')


user1 = create_user('User1')
user2 = create_user('User2')
user3 = create_user('User3')


@params(
    (ANY_BUNDLE_ID, True ),
    (None,          False),
)
def test_belongs_to_bundle(bundle_id, expected):
    ticket = create_ticket(user1.id, bundle_id=bundle_id)

    assert ticket.belongs_to_bundle == expected


@params(
    (user1.id, None    , None    , user1.id, True ),
    (user1.id, user1.id, None    , user1.id, True ),
    (user1.id, None    , user1.id, user1.id, True ),
    (user1.id, user1.id, user1.id, user1.id, True ),

    (user1.id, user2.id, None    , user1.id, True ),
    (user1.id, None    , user2.id, user1.id, True ),
    (user1.id, user2.id, user2.id, user1.id, False),  # all management rights waived

    (user2.id, None    , None    , user1.id, False),
    (user2.id, user1.id, None    , user1.id, True ),
    (user2.id, None    , user1.id, user1.id, True ),
    (user2.id, user1.id, user1.id, user1.id, True ),
)
def test_is_managed_by(owned_by_id, seat_managed_by_id, user_managed_by_id, user_id, expected):
    ticket = create_ticket(owned_by_id,
                           seat_managed_by_id=seat_managed_by_id,
                           user_managed_by_id=user_managed_by_id)

    assert ticket.is_managed_by(user_id) == expected


@params(
    (user1.id, None    , user1.id, True ),
    (user1.id, user1.id, user1.id, True ),

    (user1.id, None    , user1.id, True ),
    (user1.id, user2.id, user1.id, False),  # management right waived

    (user2.id, None    , user1.id, False),
    (user2.id, user1.id, user1.id, True ),
)
def test_is_seat_managed_by(owned_by_id, seat_managed_by_id, user_id, expected):
    ticket = create_ticket(owned_by_id,
                           seat_managed_by_id=seat_managed_by_id)

    assert ticket.is_seat_managed_by(user_id) == expected


@params(
    (user1.id, None    , user1.id, True ),
    (user1.id, user1.id, user1.id, True ),

    (user1.id, None    , user1.id, True ),
    (user1.id, user2.id, user1.id, False),  # management right waived

    (user2.id, None    , user1.id, False),
    (user2.id, user1.id, user1.id, True ),
)
def test_is_user_managed_by(owned_by_id, user_managed_by_id, user_id, expected):
    ticket = create_ticket(owned_by_id,
                           user_managed_by_id=user_managed_by_id)

    assert ticket.is_user_managed_by(user_id) == expected


def create_ticket(owned_by_id, *, bundle_id=None, seat_managed_by_id=None,
                  user_managed_by_id=None):
    code = 'BRTZN'
    category_id = None

    ticket = Ticket(code, category_id, owned_by_id)
    ticket.bundle_id = bundle_id
    ticket.seat_managed_by_id = seat_managed_by_id
    ticket.user_managed_by_id = user_managed_by_id

    return ticket