1
|
|
|
""" |
2
|
|
|
:Copyright: 2006-2020 Jochen Kupperschmidt |
3
|
|
|
:License: Modified BSD, see LICENSE for details. |
4
|
|
|
""" |
5
|
|
|
|
6
|
|
|
import pytest |
7
|
|
|
|
8
|
|
|
from byceps.services.news import ( |
9
|
|
|
channel_service as news_channel_service, |
10
|
|
|
service as news_service, |
11
|
|
|
) |
12
|
|
|
from byceps.services.site import service as site_service |
13
|
|
|
|
14
|
|
|
from tests.helpers import create_site, http_client |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
@pytest.fixture(scope='module') |
18
|
|
|
def editor(make_user): |
19
|
|
|
return make_user('Journalist') |
20
|
|
|
|
21
|
|
|
|
22
|
|
|
@pytest.fixture(scope='module') |
23
|
|
|
def news_channel(brand): |
24
|
|
|
channel_id = f'{brand.id}-public' |
25
|
|
|
url_prefix = 'https://www.acmecon.test/news/' |
26
|
|
|
|
27
|
|
|
channel = news_channel_service.create_channel(brand.id, channel_id, url_prefix) |
28
|
|
|
|
29
|
|
|
yield channel |
30
|
|
|
|
31
|
|
|
news_channel_service.delete_channel(channel_id) |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
@pytest.fixture(scope='module') |
35
|
|
|
def unpublished_news_item(news_channel, editor): |
36
|
|
|
slug = 'top-article' |
37
|
|
|
title = 'You will not believe this! [WIP]' |
38
|
|
|
body = 'Well, …' |
39
|
|
|
item = news_service.create_item(news_channel.id, slug, editor.id, title, body) |
40
|
|
|
|
41
|
|
|
yield item |
42
|
|
|
|
43
|
|
|
news_service.delete_item(item.id) |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
@pytest.fixture(scope='module') |
47
|
|
|
def published_news_item(news_channel, editor): |
48
|
|
|
slug = 'first-post' |
49
|
|
|
title = 'First Post!' |
50
|
|
|
body = 'Kann losgehen.' |
51
|
|
|
item = news_service.create_item(news_channel.id, slug, editor.id, title, body) |
52
|
|
|
news_service.publish_item(item.id) |
53
|
|
|
|
54
|
|
|
yield item |
55
|
|
|
|
56
|
|
|
news_service.delete_item(item.id) |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
@pytest.fixture(scope='module') |
60
|
|
|
def news_site(email_config, news_channel): |
61
|
|
|
site = create_site( |
62
|
|
|
'newsflash', |
63
|
|
|
news_channel.brand_id, |
64
|
|
|
news_channel_id=news_channel.id, |
65
|
|
|
) |
66
|
|
|
|
67
|
|
|
yield site |
68
|
|
|
|
69
|
|
|
site_service.delete_site(site.id) |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
@pytest.fixture(scope='module') |
73
|
|
|
def news_site_app(make_site_app, news_site): |
74
|
|
|
return make_site_app(SITE_ID=news_site.id) |
75
|
|
|
|
76
|
|
|
|
77
|
|
|
def test_view_news_frontpage(news_site_app): |
78
|
|
|
with http_client(news_site_app) as client: |
79
|
|
|
response = client.get('/news/') |
80
|
|
|
|
81
|
|
|
assert response.status_code == 200 |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
def test_view_single_published_news_item(news_site_app, published_news_item): |
85
|
|
|
with http_client(news_site_app) as client: |
86
|
|
|
response = client.get(f'/news/{published_news_item.slug}') |
87
|
|
|
|
88
|
|
|
assert response.status_code == 200 |
89
|
|
|
|
90
|
|
|
|
91
|
|
|
def test_view_single_unpublished_news_item(news_site_app, unpublished_news_item): |
92
|
|
|
with http_client(news_site_app) as client: |
93
|
|
|
response = client.get(f'/news/{unpublished_news_item.slug}') |
94
|
|
|
|
95
|
|
|
assert response.status_code == 404 |
96
|
|
|
|