Commits

"danjac"  committed fb9ac97

fixed bool

  • Participants
  • Parent commits 627edf3

Comments (0)

Files changed (2)

File flaskext/principal.py

         access.
         """
 
-    def __bool__(self):
-
-        return self.can()
+    def __nonzero__(self):
+        return bool(self.can())
 
     def require(self, http_exception=None):
         """Create a principal for this permission.
 
         The principal may be used as a context manager, or a decroator.
+
+        If ``http_exception`` is passed then ``abort()`` will be called
+        with the HTTP exception code. Otherwise a ``PermissionDenied``
+        exception will be raised.
+
+        :param http_exception: the HTTP exception code (403, 401 etc)
         """
         return IdentityContext(self, http_exception)
 

File tests/test_principal.py

     def k():
         return Response('hello')
 
+
+    @app.route('/l')
+    def l():
+        s = []
+        if not admin_or_editor:
+            s.append("not admin")
+
+        i = Identity('ali')
+        identity_changed.send(app, identity=i)
+        if admin_or_editor:
+            s.append("now admin")  
+        return Response('\n'.join(s))
+
     return app
 
 def mkadmin():
     response = client.open("/k")
     assert response.status_code == 200
 
+def test_permission_bool():
+
+    client = mkapp().test_client()
+    response = client.open('/l')
+    print response.data
+    assert response.status_code == 200
+    assert 'not admin' in response.data
+    assert 'now admin' in response.data