~homeworkprod/byceps

ref: 07761e715bf19496d75d7f4f69c494a80d57b8fd byceps/tests/integration/services/authentication/test_current_user.py -rw-r--r-- 1.5 KiB
07761e71 — Jochen Kupperschmidt Make permission, locale arguments to current user factories optional 11 months 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
"""
:Copyright: 2006-2021 Jochen Kupperschmidt
:License: Revised BSD (see `LICENSE` file for details)
"""

from uuid import UUID

from byceps.services.authentication.session import service as session_service
from byceps.util.authorization import create_permission_enum


def test_get_anonymous_current_user():
    locale = 'en'

    current_user = session_service.get_anonymous_current_user(locale=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 is None
    assert not current_user.is_orga
    assert not current_user.authenticated
    assert len(current_user.permissions) == 0
    assert current_user.locale == 'en'


def test_get_authenticated_current_user(user):
    permission_enum = create_permission_enum('example', ['do_this', 'do_that'])
    permissions = {
        permission_enum.do_this,
        permission_enum.do_that,
    }
    locale = 'de'

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

    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 is None
    assert not current_user.is_orga
    assert current_user.authenticated
    assert current_user.permissions == permissions
    assert current_user.locale == 'de'