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
  • /
  • authn
  • /
  • test_current_user.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:1d873c5f79ab784413f9a7ecb9732613d22905c7
directory badge
swh:1:dir:a72b764f60c497e0075d250825c01c696a00dfd5

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

from uuid import UUID

from babel import Locale
from flask_babel import lazy_gettext

from byceps.services.authn.session import authn_session_service
from byceps.util.authz import register_permissions


def test_get_anonymous_current_user():
    locale = Locale('en')

    current_user = authn_session_service.get_anonymous_current_user(locale)

    assert current_user.id == UUID('00000000-0000-0000-0000-000000000000')
    assert current_user.screen_name is None
    assert not current_user.suspended
    assert not current_user.deleted
    assert current_user.avatar_url == '/static/user_avatar_fallback.svg'
    assert not current_user.authenticated
    assert len(current_user.permissions) == 0
    assert current_user.locale == locale


def test_get_authenticated_current_user(user):
    locale = Locale('de')

    register_permissions(
        'example',
        [
            ('do_this', lazy_gettext('Do this')),
            ('do_that', lazy_gettext('Do that')),
        ],
    )
    permissions = frozenset(
        [
            'example.do_this',
            'example.do_that',
        ]
    )

    current_user = authn_session_service.get_authenticated_current_user(
        user, locale, permissions
    )

    assert current_user.id == user.id
    assert current_user.screen_name == user.screen_name
    assert not current_user.suspended
    assert not current_user.deleted
    assert current_user.avatar_url == '/static/user_avatar_fallback.svg'
    assert current_user.authenticated
    assert current_user.permissions == permissions
    assert current_user.locale == locale

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