def test_editable_and_optional_can_be_empty(self): """ Test that it's possible to define editable="" or optional="", and that these are correctly passed to the API's pre_render() method as empty lists, not ['']. """ templ = Template('{% load contentious %}' '{% editable div "my_key" editable="" optional="" %}' '{% endeditable %}') def _pre_render(tag_spec, meta): self.assertEqual(meta['editables'], []) self.assertEqual(meta['optionals'], []) return tag_spec api = ConfigurableAPI() api.set_return_value('get_content_data', {}) api.set_return_value('in_edit_mode', False) api.pre_render = _pre_render with mock.patch('contentious.templatetags.contentious.api', new=api): templ.render(Context({}))
def test_pre_render(self): """ Test that if the API has a pre_render() method, that it can effectively modify the tag. """ templ = Template( '{% load contentious %}' '{% editable div "my_key" editable="content" title="cake" %}' 'badger' '{% endeditable %}') api = ConfigurableAPI() api.set_return_value('get_content_data', {}) api.set_return_value('in_edit_mode', False) with mock.patch('contentious.templatetags.contentious.api', new=api): #First test that things don't die if the API doesn't have a pre_render() #method, and that the output is as expected result = templ.render(Context({})) content, attrs = self._get_content_and_attrs(result, 'div') self.assertTrue('badger' in content) self.assertTrue('title="cake"' in attrs) #Now add a pre_render method to our API, and test that the tag_spec which #it returns is used to render the HTML tag new_tag_spec = { "tag_name": "span", "attrs": { "title": "pony", "onclick": "apocalypse('fast');" }, "content": "I am not a teapot", } api.pre_render = lambda tag_spec, meta: new_tag_spec with mock.patch('contentious.templatetags.contentious.api', new=api): #First test that things don't die if the API doesn't have a pre_render() #method, and that the output is as expected result = templ.render(Context({})) content, attrs = self._get_content_and_attrs(result, 'span') self.assertTrue('I am not a teapot' in content) self.assertTrue('title="pony"' in attrs) self.assertTrue('''onclick="apocalypse('fast');"''' in attrs)
def test_editable_and_optional_can_be_empty(self): """ Test that it's possible to define editable="" or optional="", and that these are correctly passed to the API's pre_render() method as empty lists, not ['']. """ templ = Template( '{% load contentious %}' '{% editable div "my_key" editable="" optional="" %}' '{% endeditable %}' ) def _pre_render(tag_spec, meta): self.assertEqual(meta['editables'], []) self.assertEqual(meta['optionals'], []) return tag_spec api = ConfigurableAPI() api.set_return_value('get_content_data', {}) api.set_return_value('in_edit_mode', False) api.pre_render = _pre_render with mock.patch('contentious.templatetags.contentious.api', new=api): templ.render(Context({}))
def test_pre_render(self): """ Test that if the API has a pre_render() method, that it can effectively modify the tag. """ templ = Template( '{% load contentious %}' '{% editable div "my_key" editable="content" title="cake" %}' 'badger' '{% endeditable %}' ) api = ConfigurableAPI() api.set_return_value('get_content_data', {}) api.set_return_value('in_edit_mode', False) with mock.patch('contentious.templatetags.contentious.api', new=api): #First test that things don't die if the API doesn't have a pre_render() #method, and that the output is as expected result = templ.render(Context({})) content, attrs = self._get_content_and_attrs(result, 'div') self.assertTrue('badger' in content) self.assertTrue('title="cake"' in attrs) #Now add a pre_render method to our API, and test that the tag_spec which #it returns is used to render the HTML tag new_tag_spec = { "tag_name": "span", "attrs": {"title": "pony", "onclick": "apocalypse('fast');"}, "content": "I am not a teapot", } api.pre_render = lambda tag_spec, meta: new_tag_spec with mock.patch('contentious.templatetags.contentious.api', new=api): #First test that things don't die if the API doesn't have a pre_render() #method, and that the output is as expected result = templ.render(Context({})) content, attrs = self._get_content_and_attrs(result, 'span') self.assertTrue('I am not a teapot' in content) self.assertTrue('title="pony"' in attrs) self.assertTrue('''onclick="apocalypse('fast');"''' in attrs)
#LIBRARIES from django.template import Context, Template from django.test import TestCase from django.utils.html import escape import mock #CONTENTIOUS from contentious.tests.mocks import ( ConfigurableAPI, EditModeNoOpAPI, NoOpAPI, ) no_op_api = NoOpAPI() edit_mode_no_op_api = EditModeNoOpAPI() configurable_api = ConfigurableAPI() class EditableTagTest(TestCase): """ Tests for the contentious template tag(s). """ templ = Template( '{% load contentious %}' '{% editable div "my_key" editable="content,title" optional="title" title=variable onclick="boogie()" %}' 'Default content' '{% endeditable %}') p_templ = Template( '{% load contentious %}' '{% editable p "my_key" editable="content,title" title=variable onclick="boogie()" %}' 'Default content' '{% endeditable %}')