Skip to content

Commit

Permalink
Fix predicate tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan P Kilby committed Jun 25, 2018
1 parent 3dc34d7 commit 02252a8
Show file tree
Hide file tree
Showing 2 changed files with 426 additions and 456 deletions.
56 changes: 29 additions & 27 deletions tests/testsuite/contrib/test_predicates.py
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())
Loading

0 comments on commit 02252a8

Please sign in to comment.