1
|
|
|
""" |
2
|
|
|
:Copyright: 2006-2019 Jochen Kupperschmidt |
3
|
|
|
:License: Modified BSD, see LICENSE for details. |
4
|
|
|
""" |
5
|
|
|
|
6
|
|
|
from byceps.services.ticketing import attendance_service |
7
|
|
|
|
8
|
|
|
from tests.helpers import create_user |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
def test_create_archived_attendance( |
12
|
|
|
api_client, api_client_authz_header, party, user |
13
|
|
|
): |
14
|
|
|
before = attendance_service.get_attended_parties(user.id) |
15
|
|
|
assert before == [] |
16
|
|
|
|
17
|
|
|
response = _send_request( |
18
|
|
|
api_client, api_client_authz_header, user.id, party.id |
19
|
|
|
) |
20
|
|
|
assert response.status_code == 204 |
21
|
|
|
|
22
|
|
|
_assert_attended_party_ids(user.id, [party.id]) |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
def test_create_archived_attendance_idempotency( |
26
|
|
|
api_client, api_client_authz_header, party |
27
|
|
|
): |
28
|
|
|
user = create_user('AnotherUser') |
29
|
|
|
|
30
|
|
|
before = attendance_service.get_attended_parties(user.id) |
31
|
|
|
assert before == [] |
32
|
|
|
|
33
|
|
|
# First addition. Should add the party. |
34
|
|
|
response = _send_request( |
35
|
|
|
api_client, api_client_authz_header, user.id, party.id |
36
|
|
|
) |
37
|
|
|
assert response.status_code == 204 |
38
|
|
|
_assert_attended_party_ids(user.id, [party.id]) |
39
|
|
|
|
40
|
|
|
# Second addition for same user and party. Should be ignored. |
41
|
|
|
response = _send_request( |
42
|
|
|
api_client, api_client_authz_header, user.id, party.id |
43
|
|
|
) |
44
|
|
|
assert response.status_code == 204 |
45
|
|
|
_assert_attended_party_ids(user.id, [party.id]) |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
def _send_request(api_client, api_client_authz_header, user_id, party_id): |
49
|
|
|
url = f'/api/attendances/archived_attendances' |
50
|
|
|
headers = [api_client_authz_header] |
51
|
|
|
form_data = { |
52
|
|
|
'user_id': str(user_id), |
53
|
|
|
'party_id': str(party_id), |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return api_client.post(url, headers=headers, data=form_data) |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
def _assert_attended_party_ids(user_id, expected): |
60
|
|
|
parties = attendance_service.get_attended_parties(user_id) |
61
|
|
|
actual = [party.id for party in parties] |
62
|
|
|
assert actual == expected |
63
|
|
|
|