Commits

Anonymous committed 7b3ddd0

operators

  • Participants
  • Parent commits fb9ac97

Comments (0)

Files changed (3)

File flaskext/principal.py

     def __nonzero__(self):
         return bool(self.can())
 
+    def __and__(self, other):
+        return self.union(other)
+
+    def __contains__(self, other):
+        return other.issubset(self)
+
     def require(self, http_exception=None):
         """Create a principal for this permission.
 
     install_requires=[
         'Flask', 'blinker'
     ],
+    tests_require=[
+        'py', 
+    ],
+    test_suite='nose.collector',
     classifiers=[
         'Development Status :: 4 - Beta',
         'Environment :: Web Environment',

File tests/test_principal.py

     response = client.open("/k")
     assert response.status_code == 200
 
+def test_permission_and():
+
+    p1 = Permission(RoleNeed('boss'))
+    p2 = Permission(RoleNeed('lackey'))
+
+    p3 = p1 & p2
+    p4 = p1.union(p2)
+
+    assert p3.needs == p4.needs
+
+def test_contains():
+
+    p1 = Permission(RoleNeed('boss'), RoleNeed('lackey'))
+    p2 = Permission(RoleNeed('lackey'))
+
+    assert p2.issubset(p1)
+    assert p2 in p1
+
 def test_permission_bool():
 
     client = mkapp().test_client()