Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • cde5674
  • /
  • services
  • /
  • news
  • /
  • test_models.py
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge
swh:1:cnt:c176242e8e326189eea7257560f9a129188515e2
directory badge
swh:1:dir:831adbfa51c393fc9166496b427017a03687cc01

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
test_models.py
"""
:Copyright: 2014-2025 Jochen Kupperschmidt
:License: Revised BSD (see `LICENSE` file for details)
"""

from io import BytesIO

import pytest

from byceps.services.news import news_image_service, news_item_service
from byceps.services.news.models import BodyFormat, NewsChannel, NewsItem
from byceps.services.user.models.user import User

from tests.helpers import generate_token


def test_image_url_with_featured_image(news_item_with_featured_image):
    item = news_item_with_featured_image

    filename = item.featured_image.filename
    expected = f'/data/global/news_channels/{item.channel.id}/{filename}'

    assert item.featured_image.url_path == expected


# helpers


@pytest.fixture(scope='module')
def editor(make_user):
    return make_user()


@pytest.fixture(scope='module')
def brand(make_brand):
    return make_brand()


@pytest.fixture()
def channel(brand, make_news_channel) -> NewsChannel:
    return make_news_channel(brand)


@pytest.fixture()
def news_item_with_featured_image(
    channel: NewsChannel, editor: User
) -> NewsItem:
    item = create_item(channel, editor)

    image_bytes = BytesIO(b'<svg/')
    image = news_image_service.create_image(editor, item, image_bytes).unwrap()

    news_item_service.set_featured_image(item.id, image.id)

    found_item = news_item_service.find_item(item.id)
    if found_item is None:
        raise Exception('News item not found')

    return found_item


def create_item(channel: NewsChannel, editor: User) -> NewsItem:
    slug = generate_token()
    title = 'the title'
    body = 'the body'
    body_format = BodyFormat.html

    return news_item_service.create_item(
        channel,
        slug,
        editor,
        title,
        body,
        body_format,
    )

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API