Passed
Push — main ( a0d2b9...52c0ea )
by Jochen
04:32
created

test_published_news_item_announced_with_url()   A

Complexity

Conditions 2

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 13
nop 2
dl 0
loc 18
rs 9.75
c 0
b 0
f 0
1
"""
2
:Copyright: 2006-2022 Jochen Kupperschmidt
3
:License: Revised BSD (see `LICENSE` file for details)
4
"""
5
6
from flask import Flask
7
import pytest
8
9
import byceps.announce.connections  # Connect signal handlers.
10
from byceps.services.brand.transfer.models import Brand
11
from byceps.services.news import service as news_service
12
from byceps.services.news.transfer.models import BodyFormat, Channel, Item
13
from byceps.services.site.transfer.models import Site
14
from byceps.signals import news as news_signals
15
16
from tests.integration.services.news.conftest import make_channel
17
18
from .helpers import (
19
    assert_request_data,
20
    CHANNEL_INTERNAL,
21
    CHANNEL_PUBLIC,
22
    get_submitted_json,
23
    mocked_irc_bot,
24
)
25
26
27
def test_published_news_item_announced_with_url(
28
    app: Flask, item_with_url: Item
29
) -> None:
30
    expected_channel1 = CHANNEL_PUBLIC
31
    expected_channel2 = CHANNEL_INTERNAL
32
    expected_text = (
33
        'Die News "Zieh dir das mal rein!" wurde veröffentlicht. '
34
        + 'https://www.acmecon.test/news/zieh-dir-das-mal-rein'
35
    )
36
37
    event = news_service.publish_item(item_with_url.id)
38
39
    with mocked_irc_bot() as mock:
40
        news_signals.item_published.send(None, event=event)
41
42
    actual1, actual2 = get_submitted_json(mock, 2)
43
    assert_request_data(actual1, expected_channel1, expected_text)
44
    assert_request_data(actual2, expected_channel2, expected_text)
45
46
47
def test_published_news_item_announced_without_url(
48
    app: Flask, item_without_url: Item
49
) -> None:
50
    expected_channel1 = CHANNEL_PUBLIC
51
    expected_channel2 = CHANNEL_INTERNAL
52
    expected_text = (
53
        'Die News "Zieh dir auch das mal rein!" wurde veröffentlicht.'
54
    )
55
56
    event = news_service.publish_item(item_without_url.id)
57
58
    with mocked_irc_bot() as mock:
59
        news_signals.item_published.send(None, event=event)
60
61
    actual1, actual2 = get_submitted_json(mock, 2)
62
    assert_request_data(actual1, expected_channel1, expected_text)
63
    assert_request_data(actual2, expected_channel2, expected_text)
64
65
66
# helpers
67
68
69
@pytest.fixture
70
def channel_with_site(brand: Brand, site: Site, make_channel) -> Channel:
71
    return make_channel(brand.id, announcement_site_id=site.id)
72
73
74
@pytest.fixture
75
def channel_without_site(brand: Brand, make_channel) -> Channel:
76
    return make_channel(brand.id)
77
78
79 View Code Duplication
@pytest.fixture
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
80
def make_item(make_user):
81
    def _wrapper(channel: Channel, slug: str, title: str) -> Item:
82
        editor = make_user()
83
        body = 'any body'
84
        body_format = BodyFormat.html
85
86
        return news_service.create_item(
87
            channel.id, slug, editor.id, title, body, body_format
88
        )
89
90
    return _wrapper
91
92
93
@pytest.fixture
94
def item_with_url(make_item, channel_with_site: Channel) -> Item:
95
    slug = 'zieh-dir-das-mal-rein'
96
    title = 'Zieh dir das mal rein!'
97
98
    return make_item(channel_with_site, slug, title)
99
100
101
@pytest.fixture
102
def item_without_url(make_item, channel_without_site: Channel) -> Item:
103
    slug = 'zieh-dir-auch-das-mal-rein'
104
    title = 'Zieh dir auch das mal rein!'
105
106
    return make_item(channel_without_site, slug, title)
107