Completed
Push — master ( cd0c61...ee130d )
by Jochen
05:47
created

scope()   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 1
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.snippet import service as snippet_service
9
from byceps.services.snippet.transfer.models import Scope
10
11
12
CONTENT_TYPE_JSON = 'application/json'
13
14
15
def test_get_snippet_document_by_name(scope, admin, api_client):
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
16
    snippet_version, _ = snippet_service.create_document(
17
        scope, 'colophon', admin.id, 'Colophon', 'Made with BYCEPS.'
18
    )
19
    snippet_name = snippet_version.snippet.name
20
21
    response = api_client.get(
22
        f'/api/snippets/by_name/{scope.type_}/{scope.name}/{snippet_name}'
23
    )
24
25
    assert response.status_code == 200
26
    assert response.content_type == CONTENT_TYPE_JSON
27
    assert response.mimetype == CONTENT_TYPE_JSON
28
29
    response_data = response.json
30
    assert response_data['content'] == {
31
        'title': 'Colophon',
32
        'head': None,
33
        'body': 'Made with BYCEPS.',
34
    }
35
    assert response_data['type'] == 'document'
36
    assert response_data['version'] == str(snippet_version.id)
37
38
39
def test_get_snippet_fragment_by_name(scope, admin, api_client):
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
40
    snippet_version, _ = snippet_service.create_fragment(
41
        scope, 'infos', admin.id, 'TBD'
42
    )
43
    snippet_name = snippet_version.snippet.name
44
45
    response = api_client.get(
46
        f'/api/snippets/by_name/{scope.type_}/{scope.name}/{snippet_name}'
47
    )
48
49
    assert response.status_code == 200
50
    assert response.content_type == CONTENT_TYPE_JSON
51
    assert response.mimetype == CONTENT_TYPE_JSON
52
53
    response_data = response.json
54
    assert response_data['content'] == {
55
        'body': 'TBD',
56
    }
57
    assert response_data['type'] == 'fragment'
58
    assert response_data['version'] == str(snippet_version.id)
59
60
61
def test_get_unknown_snippet_by_name(scope, api_client):
62
    snippet_name = 'unknown-af'
63
64
    response = api_client.get(
65
        f'/api/snippets/by_name/{scope.type_}/{scope.name}/{snippet_name}'
66
    )
67
68
    assert response.status_code == 404
69
    assert response.content_type == CONTENT_TYPE_JSON
70
    assert response.mimetype == CONTENT_TYPE_JSON
71
    assert response.json == {}
72
73
74
@pytest.fixture(scope='module')
75
def scope(site):
76
    return Scope.for_site(site.id)
77