mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-06 04:29:55 +02:00
See #152: added permission fields on user model and corresponding API permission
This commit is contained in:
parent
23e27e0dd9
commit
ff65a4b935
5 changed files with 159 additions and 17 deletions
|
@ -1,3 +1,7 @@
|
|||
import pytest
|
||||
|
||||
from funkwhale_api.users import models
|
||||
|
||||
|
||||
def test__str__(factories):
|
||||
user = factories['users.User'](username='hello')
|
||||
|
@ -16,3 +20,33 @@ def test_changing_password_updates_subsonic_api_token(factories):
|
|||
|
||||
assert user.subsonic_api_token is not None
|
||||
assert user.subsonic_api_token != 'test'
|
||||
|
||||
|
||||
def test_get_permissions_superuser(factories):
|
||||
user = factories['users.User'](is_superuser=True)
|
||||
|
||||
perms = user.get_permissions()
|
||||
for p in models.PERMISSIONS:
|
||||
assert perms[p] is True
|
||||
|
||||
|
||||
def test_get_permissions_regular(factories):
|
||||
user = factories['users.User'](permission_library=True)
|
||||
|
||||
perms = user.get_permissions()
|
||||
for p in models.PERMISSIONS:
|
||||
if p == 'library':
|
||||
assert perms[p] is True
|
||||
else:
|
||||
assert perms[p] is False
|
||||
|
||||
|
||||
@pytest.mark.parametrize('args,perms,expected', [
|
||||
({'is_superuser': True}, ['federation', 'library'], True),
|
||||
({'is_superuser': False}, ['federation'], False),
|
||||
({'permission_library': True}, ['library'], True),
|
||||
({'permission_library': True}, ['library', 'federation'], False),
|
||||
])
|
||||
def test_has_permissions(args, perms, expected, factories):
|
||||
user = factories['users.User'](**args)
|
||||
assert user.has_permissions(*perms) is expected
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue