Completed
Push — main ( dc9c2e...80557c )
by Jochen
05:20
created

test_view()   A

Complexity

Conditions 1

Size

Total Lines 4
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
"""
2
:Copyright: 2006-2020 Jochen Kupperschmidt
3
:License: Modified BSD, see LICENSE for details.
4
"""
5
6
from byceps.services.news import service as item_service
7
8
9
def test_view(news_admin_client, item):
10
    url = f'/admin/news/items/{item.id}'
11
    response = news_admin_client.get(url)
12
    assert response.status_code == 200
13
14
15
def test_view_version(news_admin_client, item):
16
    version = item_service.get_current_item_version(item.id)
17
    url = f'/admin/news/versions/{version.id}'
18
    response = news_admin_client.get(url)
19
    assert response.status_code == 200
20
21
22
def test_list_versions(news_admin_client, item):
23
    url = f'/admin/news/items/{item.id}/versions'
24
    response = news_admin_client.get(url)
25
    assert response.status_code == 200
26
27
28
def test_compare_versions(news_admin_client, item):
29
    version = item_service.get_current_item_version(item.id)
30
    url = f'/admin/news/items/{version.id}/compare_to/{version.id}'
31
    response = news_admin_client.get(url)
32
    assert response.status_code == 200
33
34
35
def test_create_form(news_admin_client, channel):
36
    url = f'/admin/news/for_channel/{channel.id}/create'
37
    response = news_admin_client.get(url)
38
    assert response.status_code == 200
39
40
41
def test_create(news_admin_client, channel, news_admin):
42
    slug = 'what-a-blast'
43
    title = 'Wow, That Party was a Blast!'
44
    body = 'So many cool memories.'
45
    image_url_path = 'party-action.jpeg'
46
47
    url = f'/admin/news/for_channel/{channel.id}'
48
    form_data = {
49
        'slug': slug,
50
        'title': title,
51
        'body': body,
52
        'image_url_path': image_url_path,
53
    }
54
    response = news_admin_client.post(url, data=form_data)
55
56
    location = response.headers['Location']
57
    item_id = location.rpartition('/')[-1]
58
59
    item = item_service.find_item(item_id)
60
    assert item is not None
61
    assert item.id is not None
62
    assert item.channel.id == channel.id
63
    assert item.slug == slug
64
    assert item.published_at is None
65
    assert not item.published
66
    assert item.title == title
67
    assert item.body == body
68
    assert item.external_url == 'https://newssite.example/posts/what-a-blast'
69
    assert (
70
        item.image_url_path
71
        == '/data/global/news_channels/test-channel-1/party-action.jpeg'
72
    )
73
    assert item.images == []
74
75
    # Clean up.
76
    item_service.delete_item(item.id)
77
78
79
def test_update_form(news_admin_client, item):
80
    url = f'/admin/news/items/{item.id}/update'
81
    response = news_admin_client.get(url)
82
    assert response.status_code == 200
83
84
85
def test_publish(news_admin_client, item):
86
    item_before = item_service.find_item(item.id)
87
    assert item_before.published_at is None
88
    assert not item_before.published
89
90
    url = f'/admin/news/items/{item.id}/publish'
91
    response = news_admin_client.post(url)
92
93
    item_after = item_service.find_item(item.id)
94
    assert item_after.published_at is not None
95
    assert item_after.published
96