2016-07-03 14:19:06 +00:00
|
|
|
from django.template import TemplateSyntaxError
|
|
|
|
from django.test import SimpleTestCase
|
|
|
|
|
|
|
|
from ..utils import setup
|
|
|
|
|
|
|
|
|
|
|
|
class ResetCycleTagTests(SimpleTestCase):
|
|
|
|
@setup({"resetcycle01": "{% resetcycle %}"})
|
|
|
|
def test_resetcycle01(self):
|
|
|
|
with self.assertRaisesMessage(TemplateSyntaxError, "No cycles in template."):
|
|
|
|
self.engine.get_template("resetcycle01")
|
|
|
|
|
|
|
|
@setup({"resetcycle02": "{% resetcycle undefinedcycle %}"})
|
|
|
|
def test_resetcycle02(self):
|
|
|
|
with self.assertRaisesMessage(
|
|
|
|
TemplateSyntaxError, "Named cycle 'undefinedcycle' does not exist."
|
|
|
|
):
|
|
|
|
self.engine.get_template("resetcycle02")
|
|
|
|
|
|
|
|
@setup({"resetcycle03": "{% cycle 'a' 'b' %}{% resetcycle undefinedcycle %}"})
|
|
|
|
def test_resetcycle03(self):
|
|
|
|
with self.assertRaisesMessage(
|
|
|
|
TemplateSyntaxError, "Named cycle 'undefinedcycle' does not exist."
|
|
|
|
):
|
|
|
|
self.engine.get_template("resetcycle03")
|
|
|
|
|
|
|
|
@setup({"resetcycle04": "{% cycle 'a' 'b' as ab %}{% resetcycle undefinedcycle %}"})
|
|
|
|
def test_resetcycle04(self):
|
|
|
|
with self.assertRaisesMessage(
|
|
|
|
TemplateSyntaxError, "Named cycle 'undefinedcycle' does not exist."
|
|
|
|
):
|
|
|
|
self.engine.get_template("resetcycle04")
|
|
|
|
|
|
|
|
@setup(
|
2022-02-03 19:24:19 +00:00
|
|
|
{
|
2016-07-03 14:19:06 +00:00
|
|
|
"resetcycle05": (
|
|
|
|
"{% for i in test %}{% cycle 'a' 'b' %}{% resetcycle %}{% endfor %}"
|
2022-02-04 07:08:27 +00:00
|
|
|
)
|
2022-02-03 19:24:19 +00:00
|
|
|
}
|
2016-07-03 14:19:06 +00:00
|
|
|
)
|
|
|
|
def test_resetcycle05(self):
|
|
|
|
output = self.engine.render_to_string("resetcycle05", {"test": list(range(5))})
|
|
|
|
self.assertEqual(output, "aaaaa")
|
|
|
|
|
|
|
|
@setup(
|
2022-02-03 19:24:19 +00:00
|
|
|
{
|
2016-07-03 14:19:06 +00:00
|
|
|
"resetcycle06": "{% cycle 'a' 'b' 'c' as abc %}"
|
|
|
|
"{% for i in test %}"
|
|
|
|
"{% cycle abc %}"
|
|
|
|
"{% cycle '-' '+' %}"
|
|
|
|
"{% resetcycle %}"
|
|
|
|
"{% endfor %}"
|
2022-02-03 19:24:19 +00:00
|
|
|
}
|
2016-07-03 14:19:06 +00:00
|
|
|
)
|
|
|
|
def test_resetcycle06(self):
|
|
|
|
output = self.engine.render_to_string("resetcycle06", {"test": list(range(5))})
|
|
|
|
self.assertEqual(output, "ab-c-a-b-c-")
|
|
|
|
|
|
|
|
@setup(
|
2022-02-03 19:24:19 +00:00
|
|
|
{
|
2016-07-03 14:19:06 +00:00
|
|
|
"resetcycle07": "{% cycle 'a' 'b' 'c' as abc %}"
|
|
|
|
"{% for i in test %}"
|
|
|
|
"{% resetcycle abc %}"
|
|
|
|
"{% cycle abc %}"
|
|
|
|
"{% cycle '-' '+' %}"
|
|
|
|
"{% endfor %}"
|
2022-02-03 19:24:19 +00:00
|
|
|
}
|
2016-07-03 14:19:06 +00:00
|
|
|
)
|
|
|
|
def test_resetcycle07(self):
|
|
|
|
output = self.engine.render_to_string("resetcycle07", {"test": list(range(5))})
|
|
|
|
self.assertEqual(output, "aa-a+a-a+a-")
|
|
|
|
|
|
|
|
@setup(
|
2022-02-03 19:24:19 +00:00
|
|
|
{
|
2016-07-03 14:19:06 +00:00
|
|
|
"resetcycle08": "{% for i in outer %}"
|
|
|
|
"{% for j in inner %}"
|
|
|
|
"{% cycle 'a' 'b' %}"
|
|
|
|
"{% endfor %}"
|
|
|
|
"{% resetcycle %}"
|
|
|
|
"{% endfor %}"
|
2022-02-03 19:24:19 +00:00
|
|
|
}
|
2016-07-03 14:19:06 +00:00
|
|
|
)
|
|
|
|
def test_resetcycle08(self):
|
|
|
|
output = self.engine.render_to_string(
|
|
|
|
"resetcycle08", {"outer": list(range(2)), "inner": list(range(3))}
|
|
|
|
)
|
|
|
|
self.assertEqual(output, "abaaba")
|
|
|
|
|
|
|
|
@setup(
|
2022-02-03 19:24:19 +00:00
|
|
|
{
|
2016-07-03 14:19:06 +00:00
|
|
|
"resetcycle09": "{% for i in outer %}"
|
|
|
|
"{% cycle 'a' 'b' %}"
|
|
|
|
"{% for j in inner %}"
|
|
|
|
"{% cycle 'X' 'Y' %}"
|
|
|
|
"{% endfor %}"
|
|
|
|
"{% resetcycle %}"
|
|
|
|
"{% endfor %}"
|
2022-02-03 19:24:19 +00:00
|
|
|
}
|
2016-07-03 14:19:06 +00:00
|
|
|
)
|
|
|
|
def test_resetcycle09(self):
|
|
|
|
output = self.engine.render_to_string(
|
|
|
|
"resetcycle09", {"outer": list(range(2)), "inner": list(range(3))}
|
|
|
|
)
|
|
|
|
self.assertEqual(output, "aXYXbXYX")
|
|
|
|
|
|
|
|
@setup(
|
2022-02-03 19:24:19 +00:00
|
|
|
{
|
2016-07-03 14:19:06 +00:00
|
|
|
"resetcycle10": "{% for i in test %}"
|
|
|
|
"{% cycle 'X' 'Y' 'Z' as XYZ %}"
|
|
|
|
"{% cycle 'a' 'b' 'c' as abc %}"
|
2020-05-03 01:04:51 +00:00
|
|
|
"{% if i == 1 %}"
|
2016-07-03 14:19:06 +00:00
|
|
|
"{% resetcycle abc %}"
|
2020-05-03 01:04:51 +00:00
|
|
|
"{% endif %}"
|
2016-07-03 14:19:06 +00:00
|
|
|
"{% endfor %}"
|
2022-02-03 19:24:19 +00:00
|
|
|
}
|
2016-07-03 14:19:06 +00:00
|
|
|
)
|
|
|
|
def test_resetcycle10(self):
|
|
|
|
output = self.engine.render_to_string("resetcycle10", {"test": list(range(5))})
|
|
|
|
self.assertEqual(output, "XaYbZaXbYc")
|
|
|
|
|
|
|
|
@setup(
|
2022-02-03 19:24:19 +00:00
|
|
|
{
|
2016-07-03 14:19:06 +00:00
|
|
|
"resetcycle11": "{% for i in test %}"
|
|
|
|
"{% cycle 'X' 'Y' 'Z' as XYZ %}"
|
|
|
|
"{% cycle 'a' 'b' 'c' as abc %}"
|
2020-05-03 01:04:51 +00:00
|
|
|
"{% if i == 1 %}"
|
2016-07-03 14:19:06 +00:00
|
|
|
"{% resetcycle XYZ %}"
|
2020-05-03 01:04:51 +00:00
|
|
|
"{% endif %}"
|
2016-07-03 14:19:06 +00:00
|
|
|
"{% endfor %}"
|
2022-02-03 19:24:19 +00:00
|
|
|
}
|
2016-07-03 14:19:06 +00:00
|
|
|
)
|
|
|
|
def test_resetcycle11(self):
|
|
|
|
output = self.engine.render_to_string("resetcycle11", {"test": list(range(5))})
|
|
|
|
self.assertEqual(output, "XaYbXcYaZb")
|