本文整理汇总了Python中django.test.tag方法的典型用法代码示例。如果您正苦于以下问题:Python test.tag方法的具体用法?Python test.tag怎么用?Python test.tag使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.test
的用法示例。
在下文中一共展示了test.tag方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_process_tag
# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import tag [as 别名]
def generate_process_tag(slug):
"""Generate test tag for a given process."""
return "{}.{}".format(TAG_PROCESS, slug)
示例2: tag_process
# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import tag [as 别名]
def tag_process(*slugs):
"""Decorate unit test to tag it for a specific process."""
slugs = [generate_process_tag(slug) for slug in slugs]
slugs.append(TAG_PROCESS) # Also tag with a general process tag.
return tag(*slugs)
示例3: test_incorrect_syntax
# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import tag [as 别名]
def test_incorrect_syntax(self):
with self.assertRaises(TemplateSyntaxError) as cm:
Template("{% load variable %}{% asvar %}")
self.assertIn("Variable name is required", str(cm.exception))
for content in ("view.public_key", "42 + 24", "global ^X", "~~~ trimmed", "trimmed global"):
with self.subTest(tag_content=content):
with self.assertRaises(TemplateSyntaxError) as cm:
Template(string.Template("{% load variable %}{% asvar $CONTENT %}").substitute(CONTENT=content))
self.assertIn("Syntax is {% asvar", str(cm.exception))
with self.assertRaises(TemplateSyntaxError) as cm:
Template("{% load variable %}{% asvar test %}")
self.assertIn("Unclosed tag on line 1: 'asvar'", str(cm.exception))
示例4: test_list_result
# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import tag [as 别名]
def test_list_result(self):
# A list of parameters is expected to result in a list containing those parameters.
# When parameters are safe, they are expected to not be encoded on output.
page = Template("""
{% load list from utils %}
{% list 'a<a' +2 'b>b' -2 'c&c' as L %}
{% for x in L %}[{{ x }}],{% endfor %}
""").render(Context())
self.assertEqual(page.strip(), "[a<a],[2],[b>b],[-2],[c&c],")
# A list of parameters is expected to result in a list containing those parameters.
# When parameters are not safe, they are expected to be encoded on output depending
# on the 'autoescape' tag.
template_string = string.Template("""
{% load list from utils %}
{% autoescape $SWITCH %}
{% list AA +2 BB -2 CC as L %}
{% for x in L %}[{{ x }}],{% endfor %}
{% endautoescape %}
""")
expected_value = {
'on': "[A<a],[2],[b>B],[-2],[C&c],",
'off': "[A<a],[2],[b>B],[-2],[C&c],",
}
for switch in ('on', 'off'):
with self.subTest(autoescape=switch):
template = Template(template_string.substitute(SWITCH=switch))
page = template.render(Context({'CC': "C&c", 'BB': "b>B", 'AA': "A<a"}))
self.assertEqual(page.strip(), expected_value[switch])
示例5: test_dict_result
# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import tag [as 别名]
def test_dict_result(self):
# A list of parameters is expected to result in a dict containing those keys and values.
# When values are safe, they are expected to not be encoded on output.
page = Template("""
{% load dict from utils %}
{% dict a='+2' b='-2' c='33' as D %}
{% for x in D %}[{{ x }}],{% endfor %};
{% for x, y in D.items %}[{{ x }}={{ y }}],{% endfor %}.
""").render(Context())
self.assertEqual(page.strip(), "[a],[b],[c],;\n{}[a=+2],[b=-2],[c=33],.".format(' '*12))
# A list of parameters is expected to result in a dict containing those keys and values.
# When values are not safe, they are expected to be encoded on output depending on the
# 'autoescape' tag.
template_string = string.Template("""
{% load dict from utils %}
{% autoescape $SWITCH %}
{% dict a=AA b=BB c=CC as D %}
{% for x in D %}[{{ x }}],{% endfor %};
{% for x, y in D.items %}[{{ forloop.counter }}:{{ x }}={{ y }}],{% endfor %}.
{% endautoescape %}
""")
expected_value = {
'on': "[a],[b],[c],;\n{}[1:a=A<a],[2:b=b>B],[3:c=C&c],.".format(' '*16),
'off': "[a],[b],[c],;\n{}[1:a=A<a],[2:b=b>B],[3:c=C&c],.".format(' '*16),
}
for switch in ('on', 'off'):
with self.subTest(autoescape=switch):
template = Template(template_string.substitute(SWITCH=switch))
page = template.render(Context({'CC': "C&c", 'BB': "b>B", 'AA': "A<a"}))
self.assertEqual(page.strip(), expected_value[switch])
示例6: ready
# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import tag [as 别名]
def ready(self):
# tag all functional tests with 'functional'
# collect all modules of this package
modules = getModules(sys.modules[self.name])
# iterate over the moules
for module in modules:
# get the classes of the module
clsmembers = inspect.getmembers(module, inspect.isclass)
for clsName, cls in clsmembers:
# check if it's a selenium test case
if cls.__module__ == module.__name__ and \
issubclass(cls, SeleniumTestCase):
# tag it
setattr(module, clsName, tag("functional")(cls))