Skip to content

Commit

Permalink
#334 Test fixed amend template tag context
Browse files Browse the repository at this point in the history
  • Loading branch information
martinmacko47 committed Apr 3, 2022
1 parent 448ed87 commit 85f4573
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% load prepend from poleno.amend %}

<ul>
<li>aaa</li>
<li>bbb</li>
</ul>

{% prepend path=".//ul" %}<li>xxx</li>{% endprepend %}
{% prepend path=".//li" %}!{% endprepend %}
111 changes: 111 additions & 0 deletions poleno/utils/tests/test_templatetags.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,26 @@ def test_set_attributes_tag(self):
u'</ul>'
u'')

def test_amend_tag_with_operation_tags_before_content(self):
rendered = self._render(
u'{% load amend prepend from poleno.amend %}'
u'{% amend %}'
u' {% prepend path=".//ul" %}<li>xxx</li>{% endprepend %}'
u' {% prepend path=".//li" %}!{% endprepend %}'
u' <ul>'
u' <li>aaa</li>'
u' <li>bbb</li>'
u' </ul>'
u'{% endamend %}'
u'')
self.assertHTMLEqual(rendered,
u'<ul>'
u' <li>!xxx</li>'
u' <li>!aaa</li>'
u' <li>!bbb</li>'
u'</ul>'
u'')

def test_amend_tag_on_plain_text(self):
rendered = self._render(
u'{% load amend prepend append from poleno.amend %}'
Expand Down Expand Up @@ -481,6 +501,21 @@ def test_amend_tag_on_multiple_tags(self):
u'<p>yyy</p>'
u'')

def test_amend_tag_on_imported_content(self):
rendered = self._render(
u'{% load amend from poleno.amend %}'
u'{% amend %}'
u' {% include "utils/tests/amendtemplatetagtest/test_amend_tag_on_imported_content.html" %}'
u'{% endamend %}'
u'')
self.assertHTMLEqual(rendered,
u'<ul>'
u' <li>!xxx</li>'
u' <li>!aaa</li>'
u' <li>!bbb</li>'
u'</ul>'
u'')

def test_multiple_amend_tags(self):
rendered = self._render(
u'{% load amend prepend append from poleno.amend %}'
Expand Down Expand Up @@ -514,6 +549,82 @@ def test_multiple_amend_tags(self):
u'</ul>'
u'')

def test_nested_amend_tags(self):
rendered = self._render(
u'{% load amend prepend append from poleno.amend %}'
u'{% amend %}'
u' <ul>'
u' <li>aaa</li>'
u' <li>bbb</li>'
u' <li>'
u' {% amend %}'
u' <ul>'
u' <li>aaa</li>'
u' <li>bbb</li>'
u' </ul>'
u' {% append path=".//ul" %}<li>yyy</li>{% endappend %}'
u' {% append path=".//li" %}?{% endappend %}'
u' {% endamend %}'
u' </li>'
u' </ul>'
u' {% prepend path=".//ul" %}<li>xxx</li>{% endprepend %}'
u' {% prepend path=".//li" %}!{% endprepend %}'
u'{% endamend %}'
u'')
self.assertHTMLEqual(rendered,
u'<ul>'
u' <li>!xxx</li>'
u' <li>!aaa</li>'
u' <li>!bbb</li>'
u' <li>!'
u' <ul>'
u' <li>!xxx</li>'
u' <li>!aaa?</li>'
u' <li>!bbb?</li>'
u' <li>!yyy?</li>'
u' </ul>'
u' </li>'
u'</ul>'
u'')

def test_nested_amend_tags_with_operation_tags_before_content(self):
rendered = self._render(
u'{% load amend prepend append from poleno.amend %}'
u'{% amend %}'
u' {% prepend path=".//ul" %}<li>xxx</li>{% endprepend %}'
u' {% prepend path=".//li" %}!{% endprepend %}'
u' <ul>'
u' <li>aaa</li>'
u' <li>bbb</li>'
u' <li>'
u' {% amend %}'
u' {% append path=".//ul" %}<li>yyy</li>{% endappend %}'
u' {% append path=".//li" %}?{% endappend %}'
u' <ul>'
u' <li>aaa</li>'
u' <li>bbb</li>'
u' </ul>'
u' {% endamend %}'
u' </li>'
u' </ul>'
u'{% endamend %}'
u'')
self.assertHTMLEqual(rendered,
u'<ul>'
u' <li>!xxx</li>'
u' <li>!aaa</li>'
u' <li>!bbb</li>'
u' <li>!'
u' <ul>'
u' <li>!xxx</li>'
u' <li>!aaa?</li>'
u' <li>!bbb?</li>'
u' <li>!yyy?</li>'
u' </ul>'
u' </li>'
u'</ul>'
u'')

def test_without_amend_tag(self):
rendered = self._render(
u'{% load prepend append before after delete set_attributes from poleno.amend %}'
Expand Down

0 comments on commit 85f4573

Please sign in to comment.