# Path: contentious/tests/mocks.py
# class ConfigurableAPI(object):
#     """ Mock API which makes it easy to set what the return values are. """
# 
#     def __init__(self):
#         self.return_values = {}
# 
#     def set_return_value(self, method_name, value):
#         self.return_values[method_name] = value
# 
#     def _get_return_value(self, method_name):
#         return self.return_values[method_name]
# 
#     def in_edit_mode(self, context):
#         return self._get_return_value("in_edit_mode")
# 
#     def get_content_data(self, key, context):
#         return self._get_return_value("get_content_data")
# 
#     def save_content_data(self, key, data, context):
#         pass #irrelevant
# 
# class EditModeNoOpAPI(NoOpAPI):
#     """ Same as NoOpAPI but returns True for in_edit_mode. """
# 
#     def in_edit_mode(self, context):
#         return True
# 
# class NoOpAPI(object):
#     """ An implementation of the ContentiousInterface which just does nothing. """
# 
#     def in_edit_mode(self, context):
#         return False
# 
#     def get_content_data(self, key, context):
#         return {}
# 
#     def save_content_data(self, key, data, context):
#         pass


import re
import mock
from django.template import Context, Template
from django.test import TestCase
from django.utils.html import escape
from contentious.tests.mocks import (
    ConfigurableAPI,
    EditModeNoOpAPI,
    NoOpAPI,
)
        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


# Path: contentious/tests/mocks.py
# class ConfigurableAPI(object):
#     """ Mock API which makes it easy to set what the return values are. """
# 
#     def __init__(self):
#         self.return_values = {}
# 
#     def set_return_value(self, method_name, value):
#         self.return_values[method_name] = value
# 
#     def _get_return_value(self, method_name):
#         return self.return_values[method_name]
# 
#     def in_edit_mode(self, context):
#         return self._get_return_value("in_edit_mode")
# 
#     def get_content_data(self, key, context):
#         return self._get_return_value("get_content_data")
# 
#     def save_content_data(self, key, data, context):
#         pass #irrelevant
# 
# class EditModeNoOpAPI(NoOpAPI):
#     """ Same as NoOpAPI but returns True for in_edit_mode. """
# 
#     def in_edit_mode(self, context):
#         return True
# 
# class NoOpAPI(object):
#     """ An implementation of the ContentiousInterface which just does nothing. """
# 
#     def in_edit_mode(self, context):
#         return False
# 
#     def get_content_data(self, key, context):
#         return {}
# 
#     def save_content_data(self, key, data, context):
#         pass


# Path: contentious/tests/templatetags.py
import re
import mock
from django.template import Context, Template
from django.test import TestCase
from django.utils.html import escape
from contentious.tests.mocks import (
    ConfigurableAPI,
    EditModeNoOpAPI,
    NoOpAPI,
)

        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()