def setUp(self): self.env = EnvironmentStub(default_data=True, enable=['trac.*', 'tractags.*']) self.env.path = tempfile.mkdtemp() self.perms = PermissionSystem(self.env) self.tag_s = TagSystem(self.env) self.tag_wp = WikiTagProvider(self.env) self.db = self.env.get_db_cnx() setup = TagSetup(self.env) # Current tractags schema is partially setup with enabled component. # Revert these changes for getting a clean setup. self._revert_tractags_schema_init() setup.upgrade_environment(self.db) cursor = self.db.cursor() # Populate table with initial test data. cursor.execute(""" INSERT INTO tags (tagspace, name, tag) VALUES ('wiki', 'WikiStart', 'tag1') """) self.req = Mock() # Mock an anonymous request. self.req.perm = PermissionCache(self.env) self.realm = 'wiki' self.tags = ['tag1']
def setUp(self): self.env = EnvironmentStub(default_data=True, enable=['trac.*', 'tractags.*']) self.env.path = tempfile.mkdtemp() self.db = self.env.get_db_cnx() setup = TagSetup(self.env) # Current tractags schema is partially setup with enabled component. # Revert these changes for getting a clean setup. self._revert_tractags_schema_init() setup.upgrade_environment(self.db) self.perms = PermissionSystem(self.env) self.tag_s = TagSystem(self.env) self.tag_wp = WikiTagProvider(self.env) cursor = self.db.cursor() # Populate table with initial test data. cursor.execute(""" INSERT INTO tags (tagspace, name, tag) VALUES ('wiki', 'WikiStart', 'tag1') """) self.req = Mock(authname='editor') # Mock an anonymous request. self.req.perm = PermissionCache(self.env) self.realm = 'wiki' self.tags = ['tag1']
def test_available_providers(self): # Standard implementations of DefaultTagProvider should be registered. seen = [] for provider in [TicketTagProvider(self.env), WikiTagProvider(self.env)]: self.failIf(provider not in self.tag_s.tag_providers) # Ensure unique provider references, a possible bug in Trac-0.11. self.failIf(provider in seen) seen.append(provider)
def setUp(self): self.env = EnvironmentStub(default_data=True, path=tempfile.mkdtemp(), enable=['trac.*', 'tractags.*']) setup = TagSetup(self.env) # Current tractags schema is partially setup with enabled component. # Revert these changes for getting a clean setup. self._revert_tractags_schema_init() setup.upgrade_environment() self.perms = PermissionSystem(self.env) self.tag_s = TagSystem(self.env) self.tag_wp = WikiTagProvider(self.env) # Populate table with initial test data. self.env.db_transaction(""" INSERT INTO tags (tagspace, name, tag) VALUES ('wiki', 'WikiStart', 'tag1') """) self.realm = 'wiki' self.tags = ['tag1']
def setUp(self): self.env = EnvironmentStub(default_data=True, enable=['trac.*', 'tractags.*']) self.env.path = tempfile.mkdtemp() self.perms = PermissionSystem(self.env) self.req = Mock(authname='editor') self.check_perm = WikiTagProvider(self.env).check_permission setup = TagSetup(self.env) # Current tractags schema is setup with enabled component anyway. # Revert these changes for getting default permissions inserted. self._revert_tractags_schema_init() setup.upgrade_environment() # Populate table with initial test data. self.env.db_transaction(""" INSERT INTO tags (tagspace, name, tag) VALUES ('wiki', 'WikiStart', 'tag1') """) self.realm = 'wiki'
class WikiTagProviderTestCase(unittest.TestCase): def setUp(self): self.env = EnvironmentStub(default_data=True, path=tempfile.mkdtemp(), enable=['trac.*', 'tractags.*']) setup = TagSetup(self.env) # Current tractags schema is partially setup with enabled component. # Revert these changes for getting a clean setup. self._revert_tractags_schema_init() setup.upgrade_environment() self.perms = PermissionSystem(self.env) self.tag_s = TagSystem(self.env) self.tag_wp = WikiTagProvider(self.env) # Populate table with initial test data. self.env.db_transaction(""" INSERT INTO tags (tagspace, name, tag) VALUES ('wiki', 'WikiStart', 'tag1') """) self.realm = 'wiki' self.tags = ['tag1'] def tearDown(self): self.env.shutdown() shutil.rmtree(self.env.path) # Helpers def _revert_tractags_schema_init(self): _revert_tractags_schema_init(self.env) # Tests def test_get_tags(self): resource = Resource('wiki', 'WikiStart') req = MockRequest(self.env, authname='editor') self.assertEquals([tag for tag in self.tag_wp.get_resource_tags(req, resource)], self.tags) def test_exclude_template_tags(self): # Populate table with more test data. req = MockRequest(self.env, authname='editor') self.env.db_transaction(""" INSERT INTO tags (tagspace, name, tag) VALUES ('wiki', 'PageTemplates/Template', 'tag2') """) tags = ['tag1', 'tag2'] self.assertEquals(self.tag_s.get_all_tags(req).keys(), self.tags) self.env.config.set('tags', 'query_exclude_wiki_templates', False) self.assertEquals(self.tag_s.get_all_tags(req).keys(), tags) def test_set_tags_no_perms(self): resource = Resource('wiki', 'TaggedPage') req = MockRequest(self.env, authname='anonymous') self.assertRaises(PermissionError, self.tag_wp.set_resource_tags, req, resource, self.tags) def test_set_tags(self): resource = Resource('wiki', 'TaggedPage') req = MockRequest(self.env, authname='editor') # Shouldn't raise an error with appropriate permission. self.tag_wp.set_resource_tags(req, resource, self.tags) self.tag_wp.set_resource_tags(req, resource, ['tag2']) # Check change records. rows = self.env.db_query(""" SELECT author,oldtags,newtags FROM tags_change WHERE tagspace=%s AND name=%s ORDER by time DESC """, ('wiki', 'TaggedPage')) self.assertEqual(rows[0], ('editor', 'tag1', 'tag2')) self.assertEqual(rows[1], ('editor', '', 'tag1'))
class WikiTagProviderTestCase(unittest.TestCase): def setUp(self): self.env = EnvironmentStub(default_data=True, enable=['trac.*', 'tractags.*']) self.env.path = tempfile.mkdtemp() self.db = self.env.get_db_cnx() setup = TagSetup(self.env) # Current tractags schema is partially setup with enabled component. # Revert these changes for getting a clean setup. self._revert_tractags_schema_init() setup.upgrade_environment(self.db) self.perms = PermissionSystem(self.env) self.tag_s = TagSystem(self.env) self.tag_wp = WikiTagProvider(self.env) cursor = self.db.cursor() # Populate table with initial test data. cursor.execute(""" INSERT INTO tags (tagspace, name, tag) VALUES ('wiki', 'WikiStart', 'tag1') """) self.req = Mock(authname='editor') # Mock an anonymous request. self.req.perm = PermissionCache(self.env) self.realm = 'wiki' self.tags = ['tag1'] def tearDown(self): self.db.close() # Really close db connections. self.env.shutdown() shutil.rmtree(self.env.path) # Helpers def _revert_tractags_schema_init(self): cursor = self.db.cursor() cursor.execute("DROP TABLE IF EXISTS tags") cursor.execute("DROP TABLE IF EXISTS tags_change") cursor.execute("DELETE FROM system WHERE name='tags_version'") cursor.execute("DELETE FROM permission WHERE action %s" % self.db.like(), ('TAGS_%',)) # Tests def test_get_tags(self): resource = Resource('wiki', 'WikiStart') self.assertEquals([tag for tag in self.tag_wp.get_resource_tags(self.req, resource)], self.tags) def test_exclude_template_tags(self): cursor = self.db.cursor() # Populate table with more test data. cursor.execute(""" INSERT INTO tags (tagspace, name, tag) VALUES ('wiki', 'PageTemplates/Template', 'tag2') """) tags = ['tag1', 'tag2'] self.assertEquals(self.tag_s.get_all_tags(self.req).keys(), self.tags) self.env.config.set('tags', 'query_exclude_wiki_templates', False) self.assertEquals(self.tag_s.get_all_tags(self.req).keys(), tags) def test_set_tags_no_perms(self): resource = Resource('wiki', 'TaggedPage') self.assertRaises(PermissionError, self.tag_wp.set_resource_tags, self.req, resource, self.tags) def test_set_tags(self): resource = Resource('wiki', 'TaggedPage') self.req.perm = PermissionCache(self.env, username='******') # Shouldn't raise an error with appropriate permission. self.tag_wp.set_resource_tags(self.req, resource, self.tags) self.tag_wp.set_resource_tags(self.req, resource, ['tag2']) cursor = self.db.cursor() # Check change records. cursor.execute(""" SELECT * FROM tags_change WHERE tagspace=%s AND name=%s ORDER by time DESC """, ('wiki', 'TaggedPage')) row = cursor.fetchone() self.assertEqual([v for v in row[-3:]], ['editor', 'tag1', 'tag2']) row = cursor.fetchone() self.assertEqual([v for v in row[-3:]], ['editor', '', 'tag1'])
class WikiTagProviderTestCase(unittest.TestCase): def setUp(self): self.env = EnvironmentStub(default_data=True, enable=['trac.*', 'tractags.*']) self.env.path = tempfile.mkdtemp() setup = TagSetup(self.env) # Current tractags schema is partially setup with enabled component. # Revert these changes for getting a clean setup. self._revert_tractags_schema_init() setup.upgrade_environment() self.perms = PermissionSystem(self.env) self.tag_s = TagSystem(self.env) self.tag_wp = WikiTagProvider(self.env) # Populate table with initial test data. self.env.db_transaction(""" INSERT INTO tags (tagspace, name, tag) VALUES ('wiki', 'WikiStart', 'tag1') """) self.req = Mock(authname='editor') # Mock an anonymous request. self.req.perm = PermissionCache(self.env) self.realm = 'wiki' self.tags = ['tag1'] def tearDown(self): self.env.shutdown() shutil.rmtree(self.env.path) # Helpers def _revert_tractags_schema_init(self): _revert_tractags_schema_init(self.env) # Tests def test_get_tags(self): resource = Resource('wiki', 'WikiStart') self.assertEquals([tag for tag in self.tag_wp.get_resource_tags(self.req, resource)], self.tags) def test_exclude_template_tags(self): # Populate table with more test data. self.env.db_transaction(""" INSERT INTO tags (tagspace, name, tag) VALUES ('wiki', 'PageTemplates/Template', 'tag2') """) tags = ['tag1', 'tag2'] self.assertEquals(self.tag_s.get_all_tags(self.req).keys(), self.tags) self.env.config.set('tags', 'query_exclude_wiki_templates', False) self.assertEquals(self.tag_s.get_all_tags(self.req).keys(), tags) def test_set_tags_no_perms(self): resource = Resource('wiki', 'TaggedPage') self.assertRaises(PermissionError, self.tag_wp.set_resource_tags, self.req, resource, self.tags) def test_set_tags(self): resource = Resource('wiki', 'TaggedPage') self.req.perm = PermissionCache(self.env, username='******') # Shouldn't raise an error with appropriate permission. self.tag_wp.set_resource_tags(self.req, resource, self.tags) self.tag_wp.set_resource_tags(self.req, resource, ['tag2']) # Check change records. rows = self.env.db_query(""" SELECT author,oldtags,newtags FROM tags_change WHERE tagspace=%s AND name=%s ORDER by time DESC """, ('wiki', 'TaggedPage')) self.assertEqual(rows[0], ('editor', 'tag1', 'tag2')) self.assertEqual(rows[1], ('editor', '', 'tag1'))
class WikiTagProviderTestCase(unittest.TestCase): def setUp(self): self.env = EnvironmentStub(default_data=True, enable=['trac.*', 'tractags.*']) self.env.path = tempfile.mkdtemp() self.perms = PermissionSystem(self.env) self.tag_s = TagSystem(self.env) self.tag_wp = WikiTagProvider(self.env) self.db = self.env.get_db_cnx() setup = TagSetup(self.env) # Current tractags schema is partially setup with enabled component. # Revert these changes for getting a clean setup. self._revert_tractags_schema_init() setup.upgrade_environment(self.db) cursor = self.db.cursor() # Populate table with initial test data. cursor.execute(""" INSERT INTO tags (tagspace, name, tag) VALUES ('wiki', 'WikiStart', 'tag1') """) self.req = Mock() # Mock an anonymous request. self.req.perm = PermissionCache(self.env) self.realm = 'wiki' self.tags = ['tag1'] def tearDown(self): self.db.close() # Really close db connections. self.env.shutdown() shutil.rmtree(self.env.path) # Helpers def _revert_tractags_schema_init(self): cursor = self.db.cursor() cursor.execute("DROP TABLE IF EXISTS tags") cursor.execute("DELETE FROM system WHERE name='tags_version'") cursor.execute( "DELETE FROM permission WHERE action %s" % self.db.like(), ('TAGS_%', )) # Tests def test_get_tags(self): resource = Resource('wiki', 'WikiStart') self.assertEquals( [tag for tag in self.tag_wp.get_resource_tags(self.req, resource)], self.tags) def test_exclude_template_tags(self): cursor = self.db.cursor() # Populate table with more test data. cursor.execute(""" INSERT INTO tags (tagspace, name, tag) VALUES ('wiki', 'PageTemplates/Template', 'tag2') """) tags = ['tag1', 'tag2'] # Previous workaround for regression in query parser still works, # but the query without argument works again as well. self.assertEquals( self.tag_s.get_all_tags(self.req, '-invalid').keys(), self.tags) self.assertEquals( self.tag_s.get_all_tags(self.req, '').keys(), self.tags) self.env.config.set('tags', 'query_exclude_wiki_templates', False) self.assertEquals( self.tag_s.get_all_tags(self.req, '-invalid').keys(), tags) self.assertEquals(self.tag_s.get_all_tags(self.req, '').keys(), tags) def test_set_tags_no_perms(self): resource = Resource('wiki', 'TaggedPage') self.assertRaises(PermissionError, self.tag_wp.set_resource_tags, self.req, resource, self.tags) def test_set_tags(self): resource = Resource('wiki', 'TaggedPage') self.req.perm = PermissionCache(self.env, username='******') # Shouldn't raise an error with appropriate permission. self.tag_wp.set_resource_tags(self.req, resource, self.tags)