# HG changeset patch # User Mads Kiilerich # Date 1424968354 -3600 # Node ID 5d8fbada35fcb040b3df46dc86fe557b1b8dec1c # Parent 599fba9967a4981e8c401c39521a52635dd93380 tests: cleanup of fixture.anon_access diff -r 599fba9967a4 -r 5d8fbada35fc kallithea/tests/fixture.py --- 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()