Python django.test.tag() Examples
The following are 7
code examples of django.test.tag().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.test
, or try the search function
.

Example #1
Source File: utils.py From resolwe with Apache License 2.0 | 6 votes |
def generate_process_tag(slug): """Generate test tag for a given process.""" return "{}.{}".format(TAG_PROCESS, slug)
Example #2
Source File: utils.py From resolwe with Apache License 2.0 | 5 votes |
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)
Example #3
Source File: test_variable_tags.py From pasportaservo with GNU Affero General Public License v3.0 | 5 votes |
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))
Example #4
Source File: test_variable_tags.py From pasportaservo with GNU Affero General Public License v3.0 | 5 votes |
def test_incorrect_syntax(self): with self.assertRaises(TemplateSyntaxError) as cm: Template("{% load variable %}{% delvar %}") self.assertIn("At least one 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 %}{% delvar $CONTENT %}").substitute(CONTENT=content)) self.assertIn("Syntax is {% delvar", str(cm.exception)) with self.assertRaises(TemplateSyntaxError) as cm: Template("{% load variable %}{% delvar test %}{% enddelvar %}") self.assertIn("Invalid block tag on line 1: 'enddelvar'", str(cm.exception))
Example #5
Source File: test_misc_tags.py From pasportaservo with GNU Affero General Public License v3.0 | 5 votes |
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])
Example #6
Source File: test_misc_tags.py From pasportaservo with GNU Affero General Public License v3.0 | 5 votes |
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])
Example #7
Source File: apps.py From iguana with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
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))