def test_it(self): from kotti.util import clear_cache called = [] @self.cache_decorator(lambda a, b: (a, b)) def my_fun(a, b): called.append((a, b)) my_fun(1, 2) my_fun(1, 2) self.assertEqual(len(called), 1) my_fun(2, 1) self.assertEqual(len(called), 2) clear_cache() my_fun(1, 2) self.assertEqual(len(called), 3)
def test_it(self, dummy_request): from kotti.util import clear_cache called = [] @self.cache_decorator(lambda a, b: (a, b)) def my_fun(a, b): called.append((a, b)) my_fun(1, 2) my_fun(1, 2) assert len(called) == 1 my_fun(2, 1) assert len(called) == 2 clear_cache() my_fun(1, 2) assert len(called) == 3
def test_owner(self, root, db_session, events, dummy_request): from kotti.resources import Content from kotti.security import list_groups from kotti.security import list_groups_raw from kotti.util import clear_cache child = root[u'child'] = Content() db_session.flush() assert child.owner == u'bob' assert list_groups(u'bob', child) == [u'role:owner'] clear_cache() # The event listener does not set the role again for subitems: grandchild = child[u'grandchild'] = Content() db_session.flush() assert grandchild.owner == u'bob' assert list_groups(u'bob', grandchild) == [u'role:owner'] assert len(list_groups_raw(u'bob', grandchild)) == 0
def test_owner(self, root, db_session, events, dummy_request): from kotti.resources import Content from kotti.security import list_groups from kotti.security import list_groups_raw from kotti.util import clear_cache child = root['child'] = Content() db_session.flush() assert child.owner == 'bob' assert list_groups('bob', child) == ['role:owner'] clear_cache() # The event listener does not set the role again for subitems: grandchild = child['grandchild'] = Content() db_session.flush() assert grandchild.owner == 'bob' assert list_groups('bob', grandchild) == ['role:owner'] assert len(list_groups_raw('bob', grandchild)) == 0
def test_owner(self, root, db_session, events, dummy_request): from kotti.resources import Content from kotti.security import list_groups from kotti.security import list_groups_raw from kotti.util import clear_cache with patch('kotti.events.authenticated_userid', return_value='bob'): child = root[u'child'] = Content() db_session.flush() assert child.owner == u'bob' assert list_groups(u'bob', child) == [u'role:owner'] clear_cache() # The event listener does not set the role again for subitems: with patch('kotti.events.authenticated_userid', return_value='bob'): grandchild = child[u'grandchild'] = Content() db_session.flush() assert grandchild.owner == u'bob' assert list_groups(u'bob', grandchild) == [u'role:owner'] assert len(list_groups_raw(u'bob', grandchild)) == 0
def test_owner(self, get_current_request, authenticated_userid): from kotti import DBSession from kotti.resources import get_root from kotti.resources import Content from kotti.security import list_groups from kotti.security import list_groups_raw from kotti.util import clear_cache get_current_request.return_value = not None authenticated_userid.return_value = 'bob' root = get_root() child = root[u'child'] = Content() DBSession.flush() self.assertEqual(child.owner, u'bob') self.assertEqual(list_groups(u'bob', child), [u'role:owner']) clear_cache() # The event listener does not set the role again for subitems: grandchild = child[u'grandchild'] = Content() DBSession.flush() self.assertEqual(grandchild.owner, u'bob') self.assertEqual(list_groups(u'bob', grandchild), [u'role:owner']) self.assertEqual(len(list_groups_raw(u'bob', grandchild)), 0)
def test_owner(self): from kotti import DBSession from kotti.resources import get_root from kotti.resources import Content from kotti.security import list_groups from kotti.security import list_groups_raw from kotti.util import clear_cache session = DBSession() self.config.testing_securitypolicy(userid='bob') root = get_root() child = root[u'child'] = Content() session.flush() self.assertEqual(child.owner, u'bob') self.assertEqual(list_groups(u'bob', child), [u'role:owner']) clear_cache() # The event listener does not set the role again for subitems: grandchild = child[u'grandchild'] = Content() session.flush() self.assertEqual(grandchild.owner, u'bob') self.assertEqual(list_groups(u'bob', grandchild), [u'role:owner']) self.assertEqual(len(list_groups_raw(u'bob', grandchild)), 0)
def test_owner(self, db_session, events, dummy_request): from kotti import DBSession from kotti.resources import get_root from kotti.resources import Content from kotti.security import list_groups from kotti.security import list_groups_raw from kotti.util import clear_cache root = get_root() with patch('kotti.events.authenticated_userid', return_value='bob'): child = root[u'child'] = Content() DBSession.flush() assert child.owner == u'bob' assert list_groups(u'bob', child) == [u'role:owner'] clear_cache() # The event listener does not set the role again for subitems: with patch('kotti.events.authenticated_userid', return_value='bob'): grandchild = child[u'grandchild'] = Content() DBSession.flush() assert grandchild.owner == u'bob' assert list_groups(u'bob', grandchild) == [u'role:owner'] assert len(list_groups_raw(u'bob', grandchild)) == 0