changeset 3934:be75172aaf9b

security tests: convert to iterators
author Johannes Berg <johannes AT sipsolutions DOT net>
date Wed, 06 Aug 2008 10:44:55 +0200
parents b48dbb4a46ff
children 799ba4cd0526 ade975944b0d
files MoinMoin/security/_tests/test_security.py
diffstat 1 files changed, 14 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/security/_tests/test_security.py	Tue Aug 05 17:51:08 2008 +0200
+++ b/MoinMoin/security/_tests/test_security.py	Wed Aug 06 10:44:55 2008 +0200
@@ -319,12 +319,11 @@
         ]
 
         for hierarchic, pagename, username, may in tests:
-            self.request.cfg.acl_hierarchic = hierarchic
             u = User(self.request, auth_username=username)
             u.valid = True
 
-            # User should have these rights...
-            for right in may:
+            def _have_right(u, right, pagename, hierarchic):
+                self.request.cfg.acl_hierarchic = hierarchic
                 can_access = u.may.__getattr__(right)(pagename)
                 if can_access:
                     print "page %s: %s test if %s may %s (success)" % (
@@ -334,10 +333,12 @@
                         pagename, ['normal', 'hierarchic'][hierarchic], username, right)
                 assert can_access
 
-            # User should NOT have these rights:
-            mayNot = [right for right in self.request.cfg.acl_rights_valid
-                      if right not in may]
-            for right in mayNot:
+            # User should have these rights...
+            for right in may:
+                yield _have_right, u, right, pagename, hierarchic
+
+            def _not_have_right(u, right, pagename, hierarchic):
+                self.request.cfg.acl_hierarchic = hierarchic
                 can_access = u.may.__getattr__(right)(pagename)
                 if can_access:
                     print "page %s: %s test if %s may not %s (failure)" % (
@@ -347,4 +348,10 @@
                         pagename, ['normal', 'hierarchic'][hierarchic], username, right)
                 assert not can_access
 
+            # User should NOT have these rights:
+            mayNot = [right for right in self.request.cfg.acl_rights_valid
+                      if right not in may]
+            for right in mayNot:
+                yield _not_have_right, u, right, pagename, hierarchic
+
 coverage_modules = ['MoinMoin.security']