Ejemplo n.º 1
0
 def test__render_data_diff(self):
     item_name = u'Html_Item'
     empty_html = u'<span></span>'
     html = u'<span>\ud55c</span>'
     meta = {CONTENTTYPE: u'text/html;charset=utf-8'}
     item = Text.create(item_name)
     item._save(meta, empty_html)
     item = Text.create(item_name)
     # Unicode test, html escaping
     rev1 = update_item(item_name, meta, html)
     rev2 = update_item(item_name, {}, u'     ')
     result = Text._render_data_diff(item, rev1, rev2)
     assert escape(html) in result
     # Unicode test, whitespace
     rev1 = update_item(item_name, {}, u'\n\n')
     rev2 = update_item(item_name, {}, u'\n     \n')
     result = Text._render_data_diff(item, rev1, rev2)
     assert '<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>' in result
     # If fairly similar diffs are correctly spanned or not, also check indent
     rev1 = update_item(item_name, {}, u'One Two Three Four\nSix\n\ud55c')
     rev2 = update_item(item_name, {}, u'Two Three Seven Four\nSix\n\ud55c')
     result = Text._render_data_diff(item, rev1, rev2)
     assert '<span>One </span>Two Three Four' in result
     assert 'Two Three <span>Seven </span>Four' in result
     # Check for diff_html.diff return types
     assert reduce(lambda x, y: x and y, [isinstance(i[1], unicode) and isinstance(i[3], unicode) for i in diff_html.diff(u'One Two Three Four\nSix\n', u'Two Three Seven Four\nSix Seven\n')], True)
Ejemplo n.º 2
0
 def test__render_data_highlight(self):
     item_name = u'Text_Item'
     item = Text.create(item_name)
     contenttype = u'text/plain'
     meta = {CONTENTTYPE: contenttype}
     item._save(meta)
     item1 = Text.create(item_name)
     data = 'test_data\nnext line'
     comment = u'next revision'
     item1._save(meta, data, comment=comment)
     item2 = Text.create(item_name)
     result = Text._render_data_highlight(item2)
     assert u'<pre class="highlight">test_data\n' in result
     assert item2.data == ''
Ejemplo n.º 3
0
 def test__render_data_diff_text(self):
     item_name = u'Text_Item'
     item = Text.create(item_name)
     contenttype = u'text/plain'
     meta = {CONTENTTYPE: contenttype}
     item._save(meta)
     item1 = Text.create(item_name)
     data = 'test_data'
     comment = u'next revision'
     item1._save(meta, data, comment=comment)
     item2 = Text.create(item_name)
     result = Text._render_data_diff_text(item1, item1.rev, item2.rev)
     expected = u'- \n+ test_data'
     assert result == expected
     assert item2.data == ''
Ejemplo n.º 4
0
 def test_data_conversion(self):
     item_name = u'Text_Item'
     item = Text.create(item_name, u'text/plain')
     test_text = u'This \n is \n a \n Test'
     # test for data_internal_to_form
     result = Text.data_internal_to_form(item, test_text)
     expected = u'This \r\n is \r\n a \r\n Test'
     assert result == expected
     # test for data_form_to_internal
     test_form = u'This \r\n is \r\n a \r\n Test'
     result = Text.data_form_to_internal(item, test_text)
     expected = test_text
     assert result == expected
     # test for data_internal_to_storage
     result = Text.data_internal_to_storage(item, test_text)
     expected = 'This \r\n is \r\n a \r\n Test'
     assert result == expected
     # test for data_storage_to_internal
     data_storage = 'This \r\n is \r\n a \r\n Test'
     result = Text.data_storage_to_internal(item, data_storage)
     expected = test_text
     assert result == expected