1
|
|
|
""" |
2
|
|
|
:Copyright: 2006-2019 Jochen Kupperschmidt |
3
|
|
|
:License: Modified BSD, see LICENSE for details. |
4
|
|
|
""" |
5
|
|
|
|
6
|
|
|
import pytest |
7
|
|
|
|
8
|
|
|
from byceps.services.tourney import ( |
9
|
|
|
match_comment_service as comment_service, |
10
|
|
|
match_service, |
11
|
|
|
) |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
def test_update_comment(api_client, api_client_authz_header, comment, player): |
15
|
|
|
original_comment = comment_service.get_comment(comment.id) |
16
|
|
|
assert original_comment.body == 'Something stupid.' |
17
|
|
|
assert original_comment.last_edited_at is None |
18
|
|
|
assert original_comment.last_edited_by_id is None |
19
|
|
|
|
20
|
|
|
response = request_comment_update( |
21
|
|
|
api_client, api_client_authz_header, comment.id, player.id |
22
|
|
|
) |
23
|
|
|
|
24
|
|
|
assert response.status_code == 204 |
25
|
|
|
updated_comment = comment_service.get_comment(comment.id) |
26
|
|
|
assert updated_comment.body == 'This is better!' |
27
|
|
|
assert updated_comment.last_edited_at is not None |
28
|
|
|
assert updated_comment.last_edited_by_id == player.id |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
def test_update_nonexistant_comment( |
32
|
|
|
api_client, api_client_authz_header, player |
33
|
|
|
): |
34
|
|
|
unknown_comment_id = '00000000-0000-0000-0000-000000000000' |
35
|
|
|
|
36
|
|
|
response = request_comment_update( |
37
|
|
|
api_client, api_client_authz_header, unknown_comment_id, player.id |
38
|
|
|
) |
39
|
|
|
|
40
|
|
|
assert response.status_code == 404 |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
# helpers |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
@pytest.fixture(scope='module') |
47
|
|
|
def player(user): |
48
|
|
|
return user |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
@pytest.fixture |
52
|
|
|
def match(app): |
53
|
|
|
return match_service.create_match() |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
@pytest.fixture |
57
|
|
|
def comment(match, player): |
58
|
|
|
body = 'Something stupid.' |
59
|
|
|
|
60
|
|
|
return comment_service.create_comment(match.id, player.id, body) |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
def request_comment_update( |
64
|
|
|
api_client, api_client_authz_header, comment_id, editor_id |
65
|
|
|
): |
66
|
|
|
url = f'/api/tourney/match_comments/{comment_id}' |
67
|
|
|
|
68
|
|
|
headers = [api_client_authz_header] |
69
|
|
|
json_data = { |
70
|
|
|
'editor_id': editor_id, |
71
|
|
|
'body': 'This is better!', |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return api_client.patch(url, headers=headers, json=json_data) |
75
|
|
|
|