Passed
Push — master ( 6fa740...307301 )
by Jochen
02:39
created

comment()   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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