Passed
Push — main ( b77d07...0a4857 )
by Jochen
07:55
created

test_create()   A

Complexity

Conditions 1

Size

Total Lines 26
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 19
nop 4
dl 0
loc 26
rs 9.45
c 0
b 0
f 0
1
"""
2
:Copyright: 2006-2021 Jochen Kupperschmidt
3
:License: Revised BSD (see `LICENSE` file for details)
4
"""
5
6
from byceps.services.snippet import (
7
    mountpoint_service,
8
    service as snippet_service,
9
)
10
11
12
def test_index(snippet_admin_client, site):
13
    url = f'/admin/snippets/mountpoints/for_site/{site.id}'
14
    response = snippet_admin_client.get(url)
15
    assert response.status_code == 200
16
17
18
def test_site_select_form(snippet_admin_client, global_scope, snippet_admin):
19
    _, event = snippet_service.create_fragment(
20
        global_scope, 'fragment1', snippet_admin.id, 'Body v1'
21
    )
22
    snippet_id = event.snippet_id
23
24
    url = f'/admin/snippets/mountpoints/for_snippet/{snippet_id}/select_site'
25
    response = snippet_admin_client.get(url)
26
    assert response.status_code == 200
27
28
    # Clean up.
29
    snippet_service.delete_snippet(snippet_id)
30
31
32
def test_create_form(snippet_admin_client, site, global_scope, snippet_admin):
33
    _, event = snippet_service.create_fragment(
34
        global_scope, 'fragment1', snippet_admin.id, 'Body v1'
35
    )
36
    snippet_id = event.snippet_id
37
38
    url = f'/admin/snippets/mountpoints/for_snippet/{snippet_id}/for_site/{site.id}/create'
39
    response = snippet_admin_client.get(url)
40
    assert response.status_code == 200
41
42
    # Clean up.
43
    snippet_service.delete_snippet(snippet_id)
44
45
46
def test_create(snippet_admin_client, site, global_scope, snippet_admin):
47
    _, event = snippet_service.create_fragment(
48
        global_scope, 'snippet1', snippet_admin.id, 'Body'
49
    )
50
    snippet_id = event.snippet_id
51
52
    url = f'/admin/snippets/mountpoints/for_snippet/{snippet_id}/for_site/{site.id}'
53
    form_data = {
54
        'endpoint_suffix': 'test_suffix',
55
        'url_path': '/test',
56
    }
57
    response = snippet_admin_client.post(url, data=form_data)
58
    assert response.status_code == 302
59
60
    mountpoints = mountpoint_service.get_mountpoints_for_site(site.id)
61
    assert len(mountpoints) == 1
62
63
    mountpoint = list(mountpoints)[0]
64
    assert mountpoint.site_id == site.id
65
    assert mountpoint.endpoint_suffix == 'test_suffix'
66
    assert mountpoint.url_path == '/test'
67
    assert mountpoint.snippet_id == snippet_id
68
69
    # Clean up.
70
    mountpoint_service.delete_mountpoint(mountpoint.id)
71
    snippet_service.delete_snippet(snippet_id)
72
73
74
def test_delete(snippet_admin_client, site, global_scope, snippet_admin):
75
    _, event = snippet_service.create_fragment(
76
        global_scope, 'snippet2', snippet_admin.id, 'Body'
77
    )
78
    snippet_id = event.snippet_id
79
80
    mountpoint = mountpoint_service.create_mountpoint(
81
        site.id, 'test', '/test', snippet_id
82
    )
83
    assert mountpoint_service.find_mountpoint(mountpoint.id) is not None
84
85
    url = f'/admin/snippets/mountpoints/mountpoints/{mountpoint.id}'
86
    response = snippet_admin_client.delete(url)
87
    assert response.status_code == 204
88
89
    assert mountpoint_service.find_mountpoint(mountpoint.id) is None
90