本文整理汇总了Python中tractags.api.TagEngine.upgrade_environment方法的典型用法代码示例。如果您正苦于以下问题:Python TagEngine.upgrade_environment方法的具体用法?Python TagEngine.upgrade_environment怎么用?Python TagEngine.upgrade_environment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tractags.api.TagEngine
的用法示例。
在下文中一共展示了TagEngine.upgrade_environment方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TagApiTestCase
# 需要导入模块: from tractags.api import TagEngine [as 别名]
# 或者: from tractags.api.TagEngine import upgrade_environment [as 别名]
class TagApiTestCase(unittest.TestCase):
test_data = (('wiki', 'WikiStart', ('foo', 'bar')),
('wiki', 'SandBox', ('bar', 'war')),
('ticket', 1, ('war', 'death')),
('ticket', 2, ('death', 'destruction')),
('ticket', 3, ('foo', 'bar', 'destruction'))
)
req = Mock(perm=Mock(assert_permission=lambda x: True),
authname='anonymous')
def _populate_tags(self, ts):
for tagspace, target, tags in self.test_data:
tagspace = ts.tagspace(tagspace)
tagspace.add_tags(self.req, target, tags)
yield tagspace, target, tags
def setUp(self):
self.env = EnvironmentStub(default_data=True)
self.env.path = '/'
self.tag_engine = TagEngine(self.env)
self.tag_engine.upgrade_environment(self.env.get_db_cnx())
# Insert some test tickets
from trac.ticket.model import Ticket
for id in (1, 2, 3):
ticket = Ticket(self.env)
ticket['summary'] = 'Test ticket %i' % id
ticket['description'] = 'Test ticket %i description' % id
ticket.insert()
def test_tagspaces(self):
tagspaces = set(self.tag_engine.tagspaces)
self.assertEqual(tagspaces, set(('ticket', 'wiki')))
def test_insert(self):
ts = self.tag_engine.tagspace
for tagspace, target, tags in self._populate_tags(ts):
found_tags = tagspace.get_tags([target])
self.assertEqual(found_tags, set(tags))
def test_remove(self):
ts = self.tag_engine.tagspace
for tagspace, target, tags in self._populate_tags(ts):
target_tags = tagspace.get_name_tags(target)
tag = iter(target_tags).next()
tagspace.remove_tags(self.req, target, (tag,))
target_tags.discard(tag)
self.assertEqual(tagspace.get_name_tags(target), target_tags)
def test_remove_all(self):
ts = self.tag_engine.tagspace
for tagspace, target, tags in self._populate_tags(ts):
tagspace.remove_all_tags(self.req, target)
def test_replace(self):
ts = self.tag_engine.tagspace
test_set = set(('foozle', 'stick'))
for tagspace, target, tags in self._populate_tags(ts):
found_tags = tagspace.get_tags([target])
tagspace.replace_tags(self.req, target, test_set)
self.assertEqual(test_set, tagspace.get_name_tags(target))
def test_add(self):
ts = self.tag_engine.tagspace
test_set = set(('foozle', 'stick'))
for tagspace, target, tags in self._populate_tags(ts):
found_tags = tagspace.get_tags([target])
tagspace.add_tags(self.req, target, test_set)
self.assertEqual(test_set.union(found_tags), tagspace.get_name_tags(target))
def test_walk(self):
engine = self.tag_engine
compare_data = {}
for tagspace, target, tags in self._populate_tags(engine.tagspace):
compare_data.setdefault(tagspace.tagspace, {})[target] = set(tags)
tag_data = {}
for tagspace, name, tags in engine.walk_tagged_names():
tag_data.setdefault(tagspace, {})[name] = tags
self.assertEqual(compare_data, tag_data)
def test_get_tagged_union(self):
ts = self.tag_engine.tagspace
for tagspace, target, tags in self._populate_tags(ts): pass
self.assertEqual(self.tag_engine.get_tagged_names(tags=('foo', 'bar'), operation='union'),
{'wiki': set([u'WikiStart', u'SandBox']), 'ticket': set([3])})
def test_get_tagged_intersection(self):
ts = self.tag_engine.tagspace
for tagspace, target, tags in self._populate_tags(ts): pass
self.assertEqual(self.tag_engine.get_tagged_names(tags=('foo', 'bar'), operation='intersection'),
{'wiki': set(['WikiStart']), 'ticket': set([3])})
def test_get_tags_union(self):
ts = self.tag_engine.tagspace
for tagspace, target, tags in self._populate_tags(ts): pass
self.assertEqual(self.tag_engine.get_tags(names=('WikiStart', 1), operation='union'),
set(['death', 'bar', 'war', 'foo']))
def test_get_tags_intersection(self):
ts = self.tag_engine.tagspace
#.........这里部分代码省略.........
示例2: TagsXmlRpcTestCase
# 需要导入模块: from tractags.api import TagEngine [as 别名]
# 或者: from tractags.api.TagEngine import upgrade_environment [as 别名]
class TagsXmlRpcTestCase(unittest.TestCase):
test_data = (('wiki', 'WikiStart', ('foo', 'bar')),
('wiki', 'SandBox', ('bar', 'war')),
('ticket', 1, ('war', 'death')),
('ticket', 2, ('death', 'destruction')),
('ticket', 3, ('foo', 'bar', 'destruction'))
)
perm=Mock(assert_permission=lambda x: True,has_permission=lambda x: True)
req = Mock(perm=perm, authname='anonymous')
def _populate_tags(self,ts):
for tagspace, target, tags in self.test_data:
tagspace = ts.tagspace(tagspace)
tagspace.add_tags(self.req, target, tags)
yield tagspace, target, tags
def setUp(self):
self.env = EnvironmentStub(default_data=True)
from trac.log import logger_factory
self.env.log =logger_factory(logtype='syslog', logfile=None, level='DEBUG', logid='Trac', format=None)
self.env.path = '/'
self.wiki_tag_rpc_engine = WikiTagRPCSystem(self.env)
self.ticket_tag_rpc_engine = TicketTagRPCSystem(self.env)
self.tag_engine = TagEngine(self.env)
self.tag_engine.upgrade_environment(self.env.get_db_cnx())
self.xml_rpc_system = XMLRPCSystem(self.env)
# Insert some test tickets
from trac.ticket.model import Ticket
for id in (1, 2, 3):
ticket = Ticket(self.env)
ticket['summary'] = 'Test ticket %i' % id
ticket['description'] = 'Test ticket %i description' % id
ticket.insert()
def test_insert(self):
ts = self.tag_engine.tagspace
for tagspace, target, tags in self._populate_tags(ts):
found_tags = tagspace.get_tags([target])
self.assertEqual(found_tags, set(tags))
def test_wiki_tagspace(self):
self.assertEqual(self.wiki_tag_rpc_engine.namespace, 'wiki')
def test_ticket_tagspace(self):
self.assertEqual(self.ticket_tag_rpc_engine.namespace, 'ticket')
def test_wiki_xmlrpc_methods(self):
self.failUnless(set(self.wiki_tag_rpc_engine.xmlrpc_methods()) != None, "No xmlrpc methods for wiki namespace")
def test_ticket_xmlrpc_methods(self):
self.failUnless(set(self.ticket_tag_rpc_engine.xmlrpc_methods()) != None, "No xmlrpc methods for ticket namespace")
def test_wiki_xmlrpc_namespace(self):
self.assertEqual(self.wiki_tag_rpc_engine.xmlrpc_namespace(), "tags.wiki")
def test_ticket_xmlrpc_namespace(self):
self.assertEqual(self.ticket_tag_rpc_engine.xmlrpc_namespace(), "tags.ticket")
def test_wiki_get_name_tags (self):
wiki_start_tags = self.wiki_tag_rpc_engine.getTags(self.req,"WikiStart")
self.failUnless( wiki_start_tags!= None, "Can not find any tags for mock page WikiStart")
def test_xmlrpc_listMethods(self):
for method in self.xml_rpc_system.all_methods(self.req):
namespace = method.namespace.replace('.', '_')
namespaces = {}
if namespace not in namespaces:
namespaces[namespace] = {
'description' : wiki_to_oneliner(method.namespace_description, self.env),
'methods' : [],
'namespace' : method.namespace,
}
try:
namespaces[namespace]['methods'].append((method.signature, wiki_to_oneliner(method.description, self.env), method.permission))
except Exception, e:
self.fail('%s: %s\n' % (method.name, str(e)))