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
  • /
  • util
  • /
  • test_authz.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:5c9247703d84927f4f1737261ac2e8612ff45dfa
directory badge
swh:1:dir:2eededab69c74d4ca4babfcbd72f2692e2f1ca9b

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_authz.py
"""
:Copyright: 2014-2025 Jochen Kupperschmidt
:License: Revised BSD (see `LICENSE` file for details)
"""

from flask import g
from flask_babel import lazy_gettext
import pytest

from byceps.util.authz import (
    has_current_user_any_permission,
    has_current_user_permission,
    register_permissions,
)


register_permissions(
    'chill',
    [
        ('browse_the_web', lazy_gettext('Browse the web')),
        ('play_video_games', lazy_gettext('Play video games')),
        ('watch_movies', lazy_gettext('Watch movies')),
    ],
)


class CurrentUserMock:
    def __init__(self, permissions: set[str]) -> None:
        self.permissions = permissions


@pytest.mark.parametrize(
    ('permissions_assigned', 'permission_requested', 'expected'),
    [
        (
            {},
            'chill.browse_the_web',
            False,
        ),
        (
            {'chill.watch_movies'},
            'chill.play_video_games',
            False,
        ),
        (
            {'chill.watch_movies'},
            'chill.watch_movies',
            True,
        ),
        (
            {
                'chill.browse_the_web',
                'chill.play_video_games',
            },
            'chill.watch_movies',
            False,
        ),
        (
            {
                'chill.browse_the_web',
                'chill.play_video_games',
            },
            'chill.play_video_games',
            True,
        ),
    ],
)
def test_has_current_user_permission(
    site_app, permissions_assigned, permission_requested, expected
):
    g.user = CurrentUserMock(permissions_assigned)
    assert has_current_user_permission(permission_requested) == expected


@pytest.mark.parametrize(
    ('permissions_assigned', 'permissions_requested', 'expected'),
    [
        (
            {},
            {
                'chill.browse_the_web',
            },
            False,
        ),
        (
            {'chill.watch_movies'},
            {
                'chill.browse_the_web',
                'chill.play_video_games',
            },
            False,
        ),
        (
            {'chill.watch_movies'},
            {
                'chill.play_video_games',
                'chill.watch_movies',
            },
            True,
        ),
    ],
)
def test_has_current_user_any_permission(
    site_app, permissions_assigned, permissions_requested, expected
):
    g.user = CurrentUserMock(permissions_assigned)
    assert has_current_user_any_permission(*permissions_requested) == expected

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