本文整理汇总了Python中reviewboard.extensions.hooks.NavigationBarHook类的典型用法代码示例。如果您正苦于以下问题:Python NavigationBarHook类的具体用法?Python NavigationBarHook怎么用?Python NavigationBarHook使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NavigationBarHook类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_navigation_bar_hooks_with_is_enabled_for_legacy
def test_navigation_bar_hooks_with_is_enabled_for_legacy(self):
"""Testing NavigationBarHook.is_enabled_for and legacy argument
format
"""
def is_enabled_for(user):
self.assertEqual(user, request.user)
return True
entry = {
'label': 'Test Nav Entry',
'url': 'foo-url',
}
hook = NavigationBarHook(extension=self.extension, entries=[entry],
is_enabled_for=is_enabled_for)
request = self.client.request()
request.user = User(username='text')
context = Context({
'request': request,
'local_site_name': 'test-site',
})
entries = hook.get_entries(context)
self.assertEqual(len(entries), 1)
self.assertEqual(entries[0], entry)
t = Template(
'{% load rb_extensions %}'
'{% navigation_bar_hooks %}')
self.assertEqual(t.render(context).strip(),
'<li><a href="%(url)s">%(label)s</a></li>' % entry)
示例2: test_navigation_bar_hooks_with_url_name
def test_navigation_bar_hooks_with_url_name(self):
"Testing navigation entry extension hooks with url names"""
entry = {
'label': 'Test Nav Entry',
'url_name': 'dashboard',
}
hook = NavigationBarHook(extension=self.extension, entries=[entry])
request = self.client.request()
request.user = User(username='text')
context = Context({
'request': request,
'local_site_name': 'test-site',
})
entries = hook.get_entries(context)
self.assertEqual(len(entries), 1)
self.assertEqual(entries[0], entry)
t = Template(
'{% load rb_extensions %}'
'{% navigation_bar_hooks %}')
self.assertEqual(
t.render(context).strip(),
'<li><a href="%(url)s">%(label)s</a></li>' % {
'label': entry['label'],
'url': '/dashboard/',
})
示例3: test_navigation_bar_hooks_with_is_enabled_for_false
def test_navigation_bar_hooks_with_is_enabled_for_false(self):
"""Testing NavigationBarHook.is_enabled_for and returns false"""
def is_enabled_for(**kwargs):
self.assertEqual(kwargs['user'], request.user)
self.assertEqual(kwargs['request'], request)
self.assertEqual(kwargs['local_site_name'], 'test-site')
return False
entry = {
'label': 'Test Nav Entry',
'url': 'foo-url',
}
hook = NavigationBarHook(extension=self.extension, entries=[entry],
is_enabled_for=is_enabled_for)
request = self.client.request()
request.user = User(username='text')
context = Context({
'request': request,
'local_site_name': 'test-site',
})
entries = hook.get_entries(context)
self.assertEqual(len(entries), 0)
t = Template(
'{% load rb_extensions %}'
'{% navigation_bar_hooks %}')
self.assertEqual(t.render(context).strip(), '')
示例4: test_navigation_bar_hooks
def test_navigation_bar_hooks(self):
"""Testing navigation entry extension hooks"""
entry = {
'label': 'Test Nav Entry',
'url': 'foo-url',
}
hook = NavigationBarHook(extension=self.extension, entries=[entry])
context = Context({})
entries = hook.get_entries(context)
self.assertEqual(len(entries), 1)
self.assertEqual(entries[0], entry)
t = Template(
"{% load rb_extensions %}"
"{% navigation_bar_hooks %}")
self.assertEqual(t.render(context).strip(),
'<li><a href="%(url)s">%(label)s</a></li>' % entry)
示例5: test_navigation_bar_hooks_with_url_name
def test_navigation_bar_hooks_with_url_name(self):
"Testing navigation entry extension hooks with url names"""
entry = {
'label': 'Test Nav Entry',
'url_name': 'dashboard',
}
hook = NavigationBarHook(extension=self.extension, entries=[entry])
context = Context({})
entries = hook.get_entries(context)
self.assertEqual(len(entries), 1)
self.assertEqual(entries[0], entry)
t = Template(
"{% load rb_extensions %}"
"{% navigation_bar_hooks %}")
self.assertEqual(t.render(context).strip(),
'<li><a href="%(url)s">%(label)s</a></li>' % {
'label': entry['label'],
'url': '/dashboard/',
})