Changeset - 5d8fbada35fc
[Not reviewed]
default
0 1 0
Mads Kiilerich - 11 years ago 2015-02-26 17:32:34
madski@unity3d.com
tests: cleanup of fixture.anon_access
1 file changed with 8 insertions and 5 deletions:
0 comments (0 inline, 0 general)
kallithea/tests/fixture.py
Show inline comments
 
@@ -43,17 +43,20 @@ class Fixture(object):
 

	
 
    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 @@ class Fixture(object):
 

	
 
            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()
 

	
0 comments (0 inline, 0 general)