# Path: contentious/utils.py
# def recursive_make_safe(obj):
#     """ Given any object (usually a dict, list or tuple), recursively dig through
#         it and make sure that all strings in it are HTML safe.  Dict keys are ignored.
#     """
#     if isinstance(obj, basestring) and not isinstance(obj, SafeData):
#         return escape(obj)
#     elif isinstance(obj, (list, tuple)):
#             new = [] #don't modify the original while iterating over it
#             for value in obj:
#                 new.append(recursive_make_safe(value))
#     elif isinstance(obj, dict):
#         new = {} #don't modify the original while iterating over it
#         for key, value in obj.items():
#             new[key] = recursive_make_safe(value)
#     else:
#         return obj
#     return new


from django.test import TestCase
from django.utils.safestring import mark_safe
from contentious.utils import recursive_make_safe

class UtilsTest(TestCase):
    """ Tests for functions in utils.py. """

    def test_recursive_make_safe(self):
        """ Test the recursive_make_safe() function. """
        tests = (
            #input, expected_output
            (
                '<script>bad();</script>',
                '&lt;script&gt;bad();&lt;/script&gt;'
            ),
            (
                mark_safe('<script>bad();</script>'),
                '<script>bad();</script>'
            ),
            (
                ['<script>bad();</script>', 'hello'],
                ['&lt;script&gt;bad();&lt;/script&gt;', 'hello']
            ),
            (
                {'a': 'sausage', 'b': '<blink>HELLO</blink>'},
                {'a': 'sausage', 'b': '&lt;blink&gt;HELLO&lt;/blink&gt;'}
            ),
            (
                {'a': ['<p>hello</p>', 'something', {'b': '<blink>HELLO</blink>'}]},
                {'a': ['&lt;p&gt;hello&lt;/p&gt;', 'something', {'b': '&lt;blink&gt;HELLO&lt;/blink&gt;'}]},
            ),
        )
        for inp, expected in tests:

# Path: contentious/utils.py
# def recursive_make_safe(obj):
#     """ Given any object (usually a dict, list or tuple), recursively dig through
#         it and make sure that all strings in it are HTML safe.  Dict keys are ignored.
#     """
#     if isinstance(obj, basestring) and not isinstance(obj, SafeData):
#         return escape(obj)
#     elif isinstance(obj, (list, tuple)):
#             new = [] #don't modify the original while iterating over it
#             for value in obj:
#                 new.append(recursive_make_safe(value))
#     elif isinstance(obj, dict):
#         new = {} #don't modify the original while iterating over it
#         for key, value in obj.items():
#             new[key] = recursive_make_safe(value)
#     else:
#         return obj
#     return new


# Path: contentious/tests/utils.py
from django.test import TestCase
from django.utils.safestring import mark_safe
from contentious.utils import recursive_make_safe


class UtilsTest(TestCase):
    """ Tests for functions in utils.py. """

    def test_recursive_make_safe(self):
        """ Test the recursive_make_safe() function. """
        tests = (
            #input, expected_output
            (
                '<script>bad();</script>',
                '&lt;script&gt;bad();&lt;/script&gt;'
            ),
            (
                mark_safe('<script>bad();</script>'),
                '<script>bad();</script>'
            ),
            (
                ['<script>bad();</script>', 'hello'],
                ['&lt;script&gt;bad();&lt;/script&gt;', 'hello']
            ),
            (
                {'a': 'sausage', 'b': '<blink>HELLO</blink>'},
                {'a': 'sausage', 'b': '&lt;blink&gt;HELLO&lt;/blink&gt;'}
            ),
            (
                {'a': ['<p>hello</p>', 'something', {'b': '<blink>HELLO</blink>'}]},
                {'a': ['&lt;p&gt;hello&lt;/p&gt;', 'something', {'b': '&lt;blink&gt;HELLO&lt;/blink&gt;'}]},
            ),
        )
        for inp, expected in tests:

            self.assertEqual(recursive_make_safe(inp), expected)