-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ryan P Kilby
committed
Jun 25, 2018
1 parent
3dc34d7
commit 02252a8
Showing
2 changed files
with
426 additions
and
456 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,46 @@ | ||
from django.contrib.auth.models import User | ||
from django.test import TestCase | ||
|
||
from rules.predicates import (is_authenticated, is_superuser, is_staff, | ||
is_active, is_group_member) | ||
|
||
from . import TestData | ||
|
||
|
||
class SwappedUser(object): | ||
pass | ||
|
||
|
||
def test_is_authenticated(): | ||
assert is_authenticated(User.objects.get(username='adrian')) | ||
assert not is_authenticated(SwappedUser()) | ||
|
||
|
||
def test_is_superuser(): | ||
assert is_superuser(User.objects.get(username='adrian')) | ||
assert not is_superuser(SwappedUser()) | ||
|
||
class PredicateTests(TestData, TestCase): | ||
|
||
def test_is_staff(): | ||
assert is_staff(User.objects.get(username='adrian')) | ||
assert not is_staff(SwappedUser()) | ||
def test_is_authenticated(self): | ||
assert is_authenticated(User.objects.get(username='adrian')) | ||
assert not is_authenticated(SwappedUser()) | ||
|
||
def test_is_superuser(self): | ||
assert is_superuser(User.objects.get(username='adrian')) | ||
assert not is_superuser(SwappedUser()) | ||
|
||
def test_is_active(): | ||
assert is_active(User.objects.get(username='adrian')) | ||
assert not is_active(SwappedUser()) | ||
def test_is_staff(self): | ||
assert is_staff(User.objects.get(username='adrian')) | ||
assert not is_staff(SwappedUser()) | ||
|
||
def test_is_active(self): | ||
assert is_active(User.objects.get(username='adrian')) | ||
assert not is_active(SwappedUser()) | ||
|
||
def test_is_group_member(): | ||
p1 = is_group_member('somegroup') | ||
assert p1.name == 'is_group_member:somegroup' | ||
assert p1.num_args == 1 | ||
def test_is_group_member(self): | ||
p1 = is_group_member('somegroup') | ||
assert p1.name == 'is_group_member:somegroup' | ||
assert p1.num_args == 1 | ||
|
||
p2 = is_group_member('g1', 'g2', 'g3', 'g4') | ||
assert p2.name == 'is_group_member:g1,g2,g3,...' | ||
p2 = is_group_member('g1', 'g2', 'g3', 'g4') | ||
assert p2.name == 'is_group_member:g1,g2,g3,...' | ||
|
||
p = is_group_member('editors') | ||
assert p(User.objects.get(username='martin')) | ||
assert not p(SwappedUser()) | ||
p = is_group_member('editors') | ||
assert p(User.objects.get(username='martin')) | ||
assert not p(SwappedUser()) | ||
|
||
p = is_group_member('editors', 'staff') | ||
assert not p(User.objects.get(username='martin')) | ||
assert not p(SwappedUser()) | ||
p = is_group_member('editors', 'staff') | ||
assert not p(User.objects.get(username='martin')) | ||
assert not p(SwappedUser()) |
Oops, something went wrong.