|
|
|
@ -176,23 +176,6 @@ class TestTemplarTemplate(BaseTemplar, unittest.TestCase):
|
|
|
|
|
res = self.templar.template(unsafe_obj)
|
|
|
|
|
self.assertTrue(self.is_unsafe(res), 'returned value from template.template (%s) is not marked unsafe' % res)
|
|
|
|
|
|
|
|
|
|
# TODO: not sure what template is supposed to do it, but it currently throws attributeError
|
|
|
|
|
@patch('ansible.template.Templar._clean_data')
|
|
|
|
|
def test_template_unsafe_non_string_clean_data_exception(self, mock_clean_data):
|
|
|
|
|
msg = 'Error raised from _clean_data by test_template_unsafe_non_string_clean_data_exception'
|
|
|
|
|
mock_clean_data.side_effect = AnsibleError(msg)
|
|
|
|
|
unsafe_obj = AnsibleUnsafe()
|
|
|
|
|
res = self.templar.template(unsafe_obj)
|
|
|
|
|
self.assertTrue(self.is_unsafe(res), 'returned value from template.template (%s) is not marked unsafe' % res)
|
|
|
|
|
|
|
|
|
|
# TODO: not sure what template is supposed to do it, but it currently throws attributeError
|
|
|
|
|
@patch('ansible.template.Templar._clean_data', side_effect=AnsibleError)
|
|
|
|
|
def test_template_unsafe_non_string_subclass_clean_data_exception(self, mock_clean_data):
|
|
|
|
|
unsafe_obj = SomeUnsafeClass()
|
|
|
|
|
self.assertTrue(self.is_unsafe(unsafe_obj))
|
|
|
|
|
res = self.templar.template(unsafe_obj)
|
|
|
|
|
self.assertTrue(self.is_unsafe(res), 'returned value from template.template (%s) is not marked unsafe' % res)
|
|
|
|
|
|
|
|
|
|
def test_weird(self):
|
|
|
|
|
data = u'''1 2 #}huh{# %}ddfg{% }}dfdfg{{ {%what%} {{#foo#}} {%{bar}%} {#%blip%#} {{asdfsd%} 3 4 {{foo}} 5 6 7'''
|
|
|
|
|
self.assertRaisesRegexp(AnsibleError,
|
|
|
|
@ -201,48 +184,6 @@ class TestTemplarTemplate(BaseTemplar, unittest.TestCase):
|
|
|
|
|
data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestTemplarCleanData(BaseTemplar, unittest.TestCase):
|
|
|
|
|
def test_clean_data(self):
|
|
|
|
|
res = self.templar._clean_data(u'some string')
|
|
|
|
|
self.assertEqual(res, u'some string')
|
|
|
|
|
|
|
|
|
|
def test_clean_data_not_stringtype(self):
|
|
|
|
|
res = self.templar._clean_data(None)
|
|
|
|
|
# None vs NoneType
|
|
|
|
|
self.assertEqual(res, None)
|
|
|
|
|
|
|
|
|
|
def test_clean_data_jinja(self):
|
|
|
|
|
res = self.templar._clean_data(u'1 2 {what} 3 4 {{foo}} 5 6 7')
|
|
|
|
|
self.assertEqual(res, u'1 2 {what} 3 4 {#foo#} 5 6 7')
|
|
|
|
|
|
|
|
|
|
def test_clean_data_block(self):
|
|
|
|
|
res = self.templar._clean_data(u'1 2 {%what%} 3 4 {{foo}} 5 6 7')
|
|
|
|
|
self.assertEqual(res, u'1 2 {#what#} 3 4 {#foo#} 5 6 7')
|
|
|
|
|
|
|
|
|
|
# def test_clean_data_weird(self):
|
|
|
|
|
# res = self.templar._clean_data(u'1 2 #}huh{# %}ddfg{% }}dfdfg{{ {%what%} {{#foo#}} {%{bar}%} {#%blip%#} {{asdfsd%} 3 4 {{foo}} 5 6 7')
|
|
|
|
|
# print(res)
|
|
|
|
|
|
|
|
|
|
self.assertEqual(res, u'1 2 {#what#} 3 4 {#foo#} 5 6 7')
|
|
|
|
|
|
|
|
|
|
def test_clean_data_object(self):
|
|
|
|
|
obj = {u'foo': [1, 2, 3, u'bdasdf', u'{what}', u'{{foo}}', 5]}
|
|
|
|
|
clean_obj = {u'foo': [1, 2, 3, u'bdasdf', u'{what}', u'{#foo#}', 5]}
|
|
|
|
|
res = self.templar._clean_data(obj)
|
|
|
|
|
self.assertNotEqual(res, obj)
|
|
|
|
|
self.assertEqual(res, clean_obj)
|
|
|
|
|
|
|
|
|
|
def test_clean_data_bad_dict(self):
|
|
|
|
|
res = self.templar._clean_data(u'{{bad_dict}}')
|
|
|
|
|
self.assertEqual(res, u'{#bad_dict#}')
|
|
|
|
|
|
|
|
|
|
def test_clean_data_unsafe_obj(self):
|
|
|
|
|
some_obj = SomeClass()
|
|
|
|
|
unsafe_obj = wrap_var(some_obj)
|
|
|
|
|
res = self.templar._clean_data(unsafe_obj)
|
|
|
|
|
self.assertIsInstance(res, SomeClass)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestTemplarMisc(BaseTemplar, unittest.TestCase):
|
|
|
|
|
def test_templar_simple(self):
|
|
|
|
|
|
|
|
|
|