This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
2020-07-01 19:18:05 +00:00
|
|
|
"""evaluator tests"""
|
|
|
|
from django.test import TestCase
|
|
|
|
from guardian.shortcuts import get_anonymous_user
|
|
|
|
|
|
|
|
from passbook.core.models import Group
|
|
|
|
from passbook.policies.group_membership.models import GroupMembershipPolicy
|
|
|
|
from passbook.policies.types import PolicyRequest
|
|
|
|
|
|
|
|
|
|
|
|
class TestGroupMembershipPolicy(TestCase):
|
|
|
|
"""GroupMembershipPolicy tests"""
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.request = PolicyRequest(user=get_anonymous_user())
|
|
|
|
|
|
|
|
def test_invalid(self):
|
|
|
|
"""user not in group"""
|
|
|
|
group = Group.objects.create(name="test")
|
|
|
|
policy: GroupMembershipPolicy = GroupMembershipPolicy.objects.create(
|
|
|
|
group=group
|
|
|
|
)
|
|
|
|
self.assertFalse(policy.passes(self.request).passing)
|
|
|
|
|
|
|
|
def test_valid(self):
|
|
|
|
"""user in group"""
|
|
|
|
group = Group.objects.create(name="test")
|
2020-09-15 20:37:31 +00:00
|
|
|
group.users.add(get_anonymous_user())
|
2020-07-01 19:18:05 +00:00
|
|
|
group.save()
|
|
|
|
policy: GroupMembershipPolicy = GroupMembershipPolicy.objects.create(
|
|
|
|
group=group
|
|
|
|
)
|
|
|
|
self.assertTrue(policy.passes(self.request).passing)
|