Permalink
Browse files

Test make_decorator

  • Loading branch information...
jpic committed Feb 13, 2013
1 parent d6d3908 commit 4d35cdff73e70af0fdfdd42c080e63bdc11de714
Showing with 52 additions and 23 deletions.
  1. +1 −0 rules_light/tests/__init__.py
  2. +17 −23 rules_light/tests/decorators.py
  3. +34 −0 rules_light/tests/shortcuts.py
@@ -3,3 +3,4 @@
from autodiscover import AutodiscoverTestCase
from views import ViewsTestCase
from decorators import DecoratorsTestCase
from shortcuts import ShortcutsTestCase
@@ -1,34 +1,28 @@
import unittest
from django.contrib.auth.models import User
import rules_light
@rules_light.make_decorator
def return_true(*args):
return True
class DecoratorsTestCase(unittest.TestCase):
def setUp(self):
self.user, c = User.objects.get_or_create(username='foo')
self.admin, c = User.objects.get_or_create(username='bar',
is_staff=True)
def test_is_authenticated_decorator(self):
return_true = rules_light.is_authenticated(lambda u, r: True)
@rules_light.make_decorator
def return_false(*args):
return False
self.assertFalse(return_true(None, 'foo'))
self.assertTrue(return_true(self.user, 'foo'))
def test_is_authenticated_rule(self):
self.assertFalse(rules_light.is_authenticated(None, 'foo'))
self.assertTrue(rules_light.is_authenticated(self.user, 'foo'))
class DecoratorsTestCase(unittest.TestCase):
def test_decorator_return_true(self):
rule = return_true(lambda x, y: True)
self.assertTrue(rule('x', 'y'))
def test_is_staff_decorator(self):
return_true = rules_light.is_staff(lambda u, r: True)
rule = return_true(lambda x, y: False)
self.assertFalse(rule('x', 'y'))
self.assertFalse(return_true(None, 'foo'))
self.assertFalse(return_true(self.user, 'foo'))
self.assertTrue(return_true(self.admin, 'foo'))
def test_decorator_return_false(self):
rule = return_false(lambda x, y: True)
self.assertFalse(rule('x', 'y'))
def test_is_staff_rule(self):
self.assertFalse(rules_light.is_staff(None, 'foo'))
self.assertFalse(rules_light.is_staff(self.user, 'foo'))
self.assertTrue(rules_light.is_staff(self.admin, 'foo'))
rule = return_false(lambda x, y: False)
self.assertFalse(rule('x', 'y'))
@@ -0,0 +1,34 @@
import unittest
from django.contrib.auth.models import User
import rules_light
class ShortcutsTestCase(unittest.TestCase):
def setUp(self):
self.user, c = User.objects.get_or_create(username='foo')
self.admin, c = User.objects.get_or_create(username='bar',
is_staff=True)
def test_is_authenticated_decorator(self):
return_true = rules_light.is_authenticated(lambda u, r: True)
self.assertFalse(return_true(None, 'foo'))
self.assertTrue(return_true(self.user, 'foo'))
def test_is_authenticated_rule(self):
self.assertFalse(rules_light.is_authenticated(None, 'foo'))
self.assertTrue(rules_light.is_authenticated(self.user, 'foo'))
def test_is_staff_decorator(self):
return_true = rules_light.is_staff(lambda u, r: True)
self.assertFalse(return_true(None, 'foo'))
self.assertFalse(return_true(self.user, 'foo'))
self.assertTrue(return_true(self.admin, 'foo'))
def test_is_staff_rule(self):
self.assertFalse(rules_light.is_staff(None, 'foo'))
self.assertFalse(rules_light.is_staff(self.user, 'foo'))
self.assertTrue(rules_light.is_staff(self.admin, 'foo'))

0 comments on commit 4d35cdf

Please sign in to comment.