Passed
Push — master ( 307301...a898f8 )
by Jochen
02:51
created

test_get_comment()   A

Complexity

Conditions 1

Size

Total Lines 26
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 24
nop 3
dl 0
loc 26
rs 9.304
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_get_comment(api_client, api_client_authz_header, comment):
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
15
    url = f'/api/tourney/match_comments/{comment.id}'
16
    headers = [api_client_authz_header]
17
18
    response = api_client.get(url, headers=headers)
19
    assert response.status_code == 200
20
    assert response.content_type == 'application/json'
21
    assert response.get_json() == {
22
        'comment_id': str(comment.id),
23
        'match_id': str(comment.match_id),
24
        'created_at': comment.created_at.isoformat(),
25
        'creator': {
26
            'user_id': str(comment.created_by.id),
27
            'screen_name': comment.created_by.screen_name,
28
            'suspended': False,
29
            'deleted': False,
30
            'avatar_url': None,
31
            'is_orga': False,
32
        },
33
        'body_text': 'Denn man tau.',
34
        'body_html': 'Denn man tau.',
35
        'last_edited_at': None,
36
        'last_editor': None,
37
        'hidden': False,
38
        'hidden_at': None,
39
        'hidden_by_id': None,
40
    }
41
42
43
def test_get_comment_with_edited_comment(
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
44
    api_client, api_client_authz_header, edited_comment
45
):
46
    comment = edited_comment
47
48
    url = f'/api/tourney/match_comments/{comment.id}'
49
    headers = [api_client_authz_header]
50
51
    response = api_client.get(url, headers=headers)
52
    assert response.status_code == 200
53
    assert response.content_type == 'application/json'
54
    assert response.get_json() == {
55
        'comment_id': str(comment.id),
56
        'match_id': str(comment.match_id),
57
        'created_at': comment.created_at.isoformat(),
58
        'creator': {
59
            'user_id': str(comment.created_by.id),
60
            'screen_name': comment.created_by.screen_name,
61
            'suspended': False,
62
            'deleted': False,
63
            'avatar_url': None,
64
            'is_orga': False,
65
        },
66
        'body_text': '[b]So nicht[/b], Freundchen!',
67
        'body_html': '<strong>So nicht</strong>, Freundchen!',
68
        'last_edited_at': comment.last_edited_at.isoformat(),
69
        'last_editor': {
70
            'user_id': str(comment.last_edited_by.id),
71
            'screen_name': comment.last_edited_by.screen_name,
72
            'suspended': False,
73
            'deleted': False,
74
            'avatar_url': None,
75
            'is_orga': False,
76
        },
77
        'hidden': False,
78
        'hidden_at': None,
79
        'hidden_by_id': None,
80
    }
81
82
83
# helpers
84
85
86
@pytest.fixture
87
def match(app):
88
    return match_service.create_match()
89
90
91
@pytest.fixture
92
def comment(app, match, user):
93
    return comment_service.create_comment(match.id, user.id, 'Denn man tau.')
94
95
96
@pytest.fixture
97
def edited_comment(app, comment, admin):
98
    comment_service.update_comment(
99
        comment.id, admin.id, '[b]So nicht[/b], Freundchen!'
100
    )
101
    return comment_service.get_comment(comment.id)
102