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 match_comment_service, match_service |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
def test_hide_comment(api_client, api_client_authz_header, admin, comment): |
|
|
|
|
12
|
|
|
comment_before = match_comment_service.find_comment(comment.id) |
13
|
|
|
assert not comment_before.hidden |
14
|
|
|
assert comment_before.hidden_at is None |
15
|
|
|
assert comment_before.hidden_by_id is None |
16
|
|
|
|
17
|
|
|
url = f'/api/tourney/match_comments/{comment.id}/flags/hidden' |
18
|
|
|
headers = [api_client_authz_header] |
19
|
|
|
json_data = {'initiator_id': str(admin.id)} |
20
|
|
|
|
21
|
|
|
response = api_client.post(url, headers=headers, json=json_data) |
22
|
|
|
assert response.status_code == 204 |
23
|
|
|
|
24
|
|
|
comment_after = match_comment_service.find_comment(comment.id) |
25
|
|
|
assert comment_after.hidden |
26
|
|
|
assert comment_after.hidden_at is not None |
27
|
|
|
assert comment_after.hidden_by_id == admin.id |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
def test_unhide_comment(api_client, api_client_authz_header, admin, comment): |
|
|
|
|
31
|
|
|
match_comment_service.hide_comment(comment.id, admin.id) |
32
|
|
|
|
33
|
|
|
comment_before = match_comment_service.find_comment(comment.id) |
34
|
|
|
assert comment_before.hidden |
35
|
|
|
assert comment_before.hidden_at is not None |
36
|
|
|
assert comment_before.hidden_by_id is not None |
37
|
|
|
|
38
|
|
|
url = f'/api/tourney/match_comments/{comment.id}/flags/hidden' |
39
|
|
|
headers = [api_client_authz_header] |
40
|
|
|
json_data = {'initiator_id': str(admin.id)} |
41
|
|
|
|
42
|
|
|
response = api_client.delete(url, headers=headers, json=json_data) |
43
|
|
|
assert response.status_code == 204 |
44
|
|
|
|
45
|
|
|
comment_after = match_comment_service.find_comment(comment.id) |
46
|
|
|
assert not comment_after.hidden |
47
|
|
|
assert comment_after.hidden_at is None |
48
|
|
|
assert comment_after.hidden_by_id is None |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
# helpers |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
@pytest.fixture |
55
|
|
|
def match(app, scope='module'): |
56
|
|
|
return match_service.create_match() |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
@pytest.fixture |
60
|
|
|
def comment(app, match, user): |
61
|
|
|
return match_comment_service.create_comment(match.id, user.id, '¡Vámonos!') |
62
|
|
|
|