def setUp(self): self.env = \ EnvironmentStub(enable=['trac.attachment.LegacyAttachmentPolicy', 'trac.perm.*', 'trac.wiki.web_ui.*']) self.env.config.set('trac', 'permission_policies', 'DefaultWikiPolicy,DefaultPermissionPolicy') self.policy = DefaultWikiPolicy(self.env) store = DefaultPermissionStore(self.env) store.grant_permission('user1', 'WIKI_ADMIN') store.grant_permission('user2', 'WIKI_DELETE') store.grant_permission('user2', 'WIKI_MODIFY') store.grant_permission('user2', 'WIKI_RENAME') self.page = WikiPage(self.env, 'SomePage') self.page.text = 'This is a readonly page.' self.page.readonly = 1 self.page.save('user', 'readonly page added')
class DefaultWikiPolicyTestCase(unittest.TestCase): def setUp(self): self.env = \ EnvironmentStub(enable=['trac.attachment.LegacyAttachmentPolicy', 'trac.perm.*', 'trac.wiki.web_ui.*']) self.env.config.set('trac', 'permission_policies', 'DefaultWikiPolicy,DefaultPermissionPolicy') self.policy = DefaultWikiPolicy(self.env) store = DefaultPermissionStore(self.env) store.grant_permission('user1', 'WIKI_ADMIN') store.grant_permission('user2', 'WIKI_DELETE') store.grant_permission('user2', 'WIKI_MODIFY') store.grant_permission('user2', 'WIKI_RENAME') self.page = WikiPage(self.env, 'SomePage') self.page.text = 'This is a readonly page.' self.page.readonly = 1 self.page.save('user', 'readonly page added') def test_user_with_wiki_admin_can_modify_readonly_page(self): """User with WIKI_ADMIN cannot modify a readonly page.""" perm_cache = PermissionCache(self.env, 'user1', self.page.resource) self.assertIn('WIKI_ADMIN', perm_cache) for perm in ('WIKI_DELETE', 'WIKI_MODIFY', 'WIKI_RENAME'): self.assertIn(perm, perm_cache) self.assertIsNone( self.policy.check_permission(perm, perm_cache.username, self.page.resource, perm_cache)) def test_user_without_wiki_admin_cannot_modify_readonly_page(self): """User without WIKI_ADMIN cannot modify a readonly page.""" perm_cache = PermissionCache(self.env, 'user2', self.page.resource) self.assertNotIn('WIKI_ADMIN', perm_cache) for perm in ('WIKI_DELETE', 'WIKI_MODIFY', 'WIKI_RENAME'): self.assertNotIn(perm, perm_cache) self.assertFalse( self.policy.check_permission(perm, perm_cache.username, self.page.resource, perm_cache))