changeset 4880:5d8fbada35fc

tests: cleanup of fixture.anon_access
author Mads Kiilerich <madski@unity3d.com>
date Thu, 26 Feb 2015 17:32:34 +0100
parents 599fba9967a4
children afddaa53ab8a
files kallithea/tests/fixture.py
diffstat 1 files changed, 8 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/tests/fixture.py	Fri Feb 27 15:37:46 2015 +0100
+++ b/kallithea/tests/fixture.py	Thu Feb 26 17:32:34 2015 +0100
@@ -43,17 +43,20 @@
 
     def anon_access(self, status):
         """
-        Context process for disabling anonymous access. use like:
+        Context manager for controlling anonymous access.
+        Anon access will be set and committed, but restored again when exiting the block.
+
+        Usage:
+
         fixture = Fixture()
         with fixture.anon_access(False):
-            #tests
-
-        after this block anon access will be set to `not status`
+            stuff
         """
 
         class context(object):
             def __enter__(self):
                 anon = User.get_default_user()
+                self._before = anon.active
                 anon.active = status
                 Session().add(anon)
                 Session().commit()
@@ -61,7 +64,7 @@
 
             def __exit__(self, exc_type, exc_val, exc_tb):
                 anon = User.get_default_user()
-                anon.active = not status
+                anon.active = self._before
                 Session().add(anon)
                 Session().commit()