~homeworkprod/byceps

ref: 9f63b62a2b4647a97ebd3b6356d937ffa1d88876 byceps/tests/services/news/test_models.py -rw-r--r-- 1.5 KiB
9f63b62a — Jochen Kupperschmidt Note that Python 3.6 is a supported Python version 4 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""
:Copyright: 2006-2017 Jochen Kupperschmidt
:License: Modified BSD, see LICENSE for details.
"""

from nose2.tools import params

from testfixtures.news import create_current_version_association, \
    create_item, create_item_version

from tests.base import AbstractAppTestCase
from tests.helpers import current_party_set


class ItemTestCase(AbstractAppTestCase):

    def setUp(self):
        super().setUp()

        self.editor = self.create_user()

        self.create_brand_and_party()

    @params(
        ('without-image', None          , None                                        ),
        ('with-image'   , 'breaking.png', 'http://example.com/brand/news/breaking.png'),
    )
    def test_image_url(self, slug, image_url_path, expected):
        item = self.create_item_with_version(slug, image_url_path)

        with current_party_set(self.app, self.party), self.app.app_context():
            self.assertEqual(item.image_url, expected)

    # -------------------------------------------------------------------- #
    # helpers

    def create_item_with_version(self, slug, image_url_path):
        item = create_item(self.brand.id, slug=slug)
        self.db.session.add(item)

        version = create_item_version(item, self.editor.id,
                                      image_url_path=image_url_path)
        self.db.session.add(version)

        current_version_association = create_current_version_association(item, version)
        self.db.session.add(current_version_association)

        self.db.session.commit()

        return item