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_get_comments_for_match( |
|
|
|
|
15
|
|
|
api_client, api_client_authz_header, match, comment |
16
|
|
|
): |
17
|
|
|
url = f'/api/tourney/matches/{match.id}/comments' |
18
|
|
|
headers = [api_client_authz_header] |
19
|
|
|
|
20
|
|
|
response = api_client.get(url, headers=headers) |
21
|
|
|
assert response.status_code == 200 |
22
|
|
|
assert response.content_type == 'application/json' |
23
|
|
|
assert response.get_json() == { |
24
|
|
|
'comments': [ |
25
|
|
|
{ |
26
|
|
|
'comment_id': str(comment.id), |
27
|
|
|
'match_id': str(comment.match_id), |
28
|
|
|
'created_at': comment.created_at.isoformat(), |
29
|
|
|
'creator': { |
30
|
|
|
'user_id': str(comment.created_by.id), |
31
|
|
|
'screen_name': comment.created_by.screen_name, |
32
|
|
|
'suspended': False, |
33
|
|
|
'deleted': False, |
34
|
|
|
'avatar_url': None, |
35
|
|
|
'is_orga': False, |
36
|
|
|
}, |
37
|
|
|
'body_text': 'Denn man tau.', |
38
|
|
|
'body_html': 'Denn man tau.', |
39
|
|
|
'last_edited_at': None, |
40
|
|
|
'last_editor': None, |
41
|
|
|
'hidden': False, |
42
|
|
|
'hidden_at': None, |
43
|
|
|
'hidden_by_id': None, |
44
|
|
|
} |
45
|
|
|
] |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
def test_get_comments_for_match_with_edited_comment( |
|
|
|
|
50
|
|
|
api_client, api_client_authz_header, match, edited_comment |
51
|
|
|
): |
52
|
|
|
url = f'/api/tourney/matches/{match.id}/comments' |
53
|
|
|
headers = [api_client_authz_header] |
54
|
|
|
|
55
|
|
|
response = api_client.get(url, headers=headers) |
56
|
|
|
assert response.status_code == 200 |
57
|
|
|
assert response.content_type == 'application/json' |
58
|
|
|
assert response.get_json() == { |
59
|
|
|
'comments': [ |
60
|
|
|
{ |
61
|
|
|
'comment_id': str(edited_comment.id), |
62
|
|
|
'match_id': str(edited_comment.match_id), |
63
|
|
|
'created_at': edited_comment.created_at.isoformat(), |
64
|
|
|
'creator': { |
65
|
|
|
'user_id': str(edited_comment.created_by.id), |
66
|
|
|
'screen_name': edited_comment.created_by.screen_name, |
67
|
|
|
'suspended': False, |
68
|
|
|
'deleted': False, |
69
|
|
|
'avatar_url': None, |
70
|
|
|
'is_orga': False, |
71
|
|
|
}, |
72
|
|
|
'body_text': '[b]So nicht[/b], Freundchen!', |
73
|
|
|
'body_html': '<strong>So nicht</strong>, Freundchen!', |
74
|
|
|
'last_edited_at': edited_comment.last_edited_at.isoformat(), |
75
|
|
|
'last_editor': { |
76
|
|
|
'user_id': str(edited_comment.last_edited_by.id), |
77
|
|
|
'screen_name': edited_comment.last_edited_by.screen_name, |
78
|
|
|
'suspended': False, |
79
|
|
|
'deleted': False, |
80
|
|
|
'avatar_url': None, |
81
|
|
|
'is_orga': False, |
82
|
|
|
}, |
83
|
|
|
'hidden': False, |
84
|
|
|
'hidden_at': None, |
85
|
|
|
'hidden_by_id': None, |
86
|
|
|
} |
87
|
|
|
] |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
|
91
|
|
|
# helpers |
92
|
|
|
|
93
|
|
|
|
94
|
|
|
@pytest.fixture |
95
|
|
|
def match(app): |
96
|
|
|
return match_service.create_match() |
97
|
|
|
|
98
|
|
|
|
99
|
|
|
@pytest.fixture |
100
|
|
|
def comment(app, match, user): |
101
|
|
|
return comment_service.create_comment(match.id, user.id, 'Denn man tau.') |
102
|
|
|
|
103
|
|
|
|
104
|
|
|
@pytest.fixture |
105
|
|
|
def edited_comment(app, comment, admin): |
106
|
|
|
comment_service.update_comment( |
107
|
|
|
comment.id, admin.id, '[b]So nicht[/b], Freundchen!' |
108
|
|
|
) |
109
|
|
|
return comment_service.get_comment(comment.id) |
110
|
|
|
|