示例#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 = Item.create(item_name)
     item._save(meta, empty_html)
     item = Item.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.content, 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.content, 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.content, 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)
示例#2
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 = Item.create(item_name)
     item._save(meta, empty_html)
     item = Item.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.content, 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.content, 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.content, 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)
示例#3
0
 def test_data_conversion(self):
     item_name = u'Text_Item'
     item = Item.create(item_name, ITEMTYPE_DEFAULT, u'text/plain;charset=utf-8')
     test_text = u'This \n is \n a \n Test'
     # test for data_internal_to_form
     result = Text.data_internal_to_form(item.content, 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.content, test_text)
     expected = test_text
     assert result == expected
     # test for data_internal_to_storage
     result = Text.data_internal_to_storage(item.content, 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.content, data_storage)
     expected = test_text
     assert result == expected
示例#4
0
 def test_data_conversion(self):
     item_name = u'Text_Item'
     item = Item.create(item_name, ITEMTYPE_DEFAULT, u'text/plain;charset=utf-8')
     test_text = u'This \n is \n a \n Test'
     # test for data_internal_to_form
     result = Text.data_internal_to_form(item.content, 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.content, test_text)
     expected = test_text
     assert result == expected
     # test for data_internal_to_storage
     result = Text.data_internal_to_storage(item.content, 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.content, data_storage)
     expected = test_text
     assert result == expected
示例#5
0
 def test__render_data_highlight(self):
     item_name = u'Text_Item'
     item = Item.create(item_name)
     contenttype = u'text/plain;charset=utf-8'
     meta = {CONTENTTYPE: contenttype}
     item._save(meta)
     item1 = Item.create(item_name)
     data = 'test_data\nnext line'
     comment = u'next revision'
     item1._save(meta, data, comment=comment)
     item2 = Item.create(item_name)
     result = Text._render_data_highlight(item2.content)
     assert u'<pre class="highlight">test_data\n' in result
     assert item2.content.data == ''
示例#6
0
 def test__render_data_highlight(self):
     item_name = u'Text_Item'
     item = Item.create(item_name)
     contenttype = u'text/plain;charset=utf-8'
     meta = {CONTENTTYPE: contenttype}
     item._save(meta)
     item1 = Item.create(item_name)
     data = 'test_data\nnext line'
     comment = u'next revision'
     item1._save(meta, data, comment=comment)
     item2 = Item.create(item_name)
     result = Text._render_data_highlight(item2.content)
     assert u'<pre class="highlight">test_data\n' in result
     assert item2.content.data == ''
示例#7
0
 def test__render_data_diff_text(self):
     item_name = u'Text_Item'
     item = Item.create(item_name)
     contenttype = u'text/plain;charset=utf-8'
     meta = {CONTENTTYPE: contenttype}
     data1 = "old_data"
     item._save(meta, data1)
     item1 = Item.create(item_name)
     data2 = 'new_data'
     comment = u'next revision'
     item1._save(meta, data2, comment=comment)
     item2 = Item.create(item_name)
     result = Text._render_data_diff_text(item1.content, item1.rev, item2.rev)
     expected = u'- old_data\n+ new_data'
     assert result == expected
     assert item2.content.data == ''
示例#8
0
 def test__render_data_diff_text(self):
     item_name = u'Text_Item'
     item = Item.create(item_name)
     contenttype = u'text/plain;charset=utf-8'
     meta = {CONTENTTYPE: contenttype}
     data1 = "old_data"
     item._save(meta, data1)
     item1 = Item.create(item_name)
     data2 = 'new_data'
     comment = u'next revision'
     item1._save(meta, data2, comment=comment)
     item2 = Item.create(item_name)
     result = Text._render_data_diff_text(item1.content, item1.rev, item2.rev)
     expected = u'- old_data\n+ new_data'
     assert result == expected
     assert item2.content.data == ''