disagreement/tests/test_permissions.py
Slipstream a222dec661
Some checks failed
Deploy MkDocs / deploy (push) Has been cancelled
Add Permissions.all convenience (#107)
2025-06-15 18:49:43 -06:00

43 lines
1.2 KiB
Python

import pytest
from disagreement.permissions import (
Permissions,
has_permissions,
missing_permissions,
permissions_value,
)
def test_permissions_value_combination():
perm = permissions_value(Permissions.SEND_MESSAGES, Permissions.MANAGE_MESSAGES)
assert perm == (Permissions.SEND_MESSAGES | Permissions.MANAGE_MESSAGES)
def test_has_permissions_true():
current = Permissions.SEND_MESSAGES | Permissions.MANAGE_MESSAGES
assert has_permissions(current, Permissions.SEND_MESSAGES)
assert has_permissions(
current, Permissions.MANAGE_MESSAGES, Permissions.SEND_MESSAGES
)
def test_has_permissions_false():
current = Permissions.SEND_MESSAGES
assert not has_permissions(current, Permissions.MANAGE_MESSAGES)
def test_missing_permissions():
current = Permissions.SEND_MESSAGES
missing = missing_permissions(
current, Permissions.SEND_MESSAGES, Permissions.MANAGE_MESSAGES
)
assert missing == [Permissions.MANAGE_MESSAGES]
def test_permissions_all():
all_value = Permissions.all()
union = Permissions(0)
for perm in Permissions:
union |= perm
assert all_value == union