Commit f24b9247 authored by Jérome Perrin's avatar Jérome Perrin

Tests html preview of an OOo document with images as extensible content.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@38448 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 4c1a2247
...@@ -30,6 +30,9 @@ ...@@ -30,6 +30,9 @@
import unittest import unittest
import os import os
import transaction import transaction
from lxml import etree
from StringIO import StringIO
from AccessControl import Unauthorized from AccessControl import Unauthorized
from AccessControl.SecurityManagement import newSecurityManager from AccessControl.SecurityManagement import newSecurityManager
from Testing import ZopeTestCase from Testing import ZopeTestCase
...@@ -561,6 +564,76 @@ class TestERP5WebWithDms(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -561,6 +564,76 @@ class TestERP5WebWithDms(ERP5TypeTestCase, ZopeTestCase.Functional):
self.assertEquals(response.getHeader('content-type'), self.assertEquals(response.getHeader('content-type'),
'text/html; charset=utf-8') 'text/html; charset=utf-8')
def test_PreviewOOoDocumentWithEmbeddedImage(self):
"""Tests html preview of an OOo document with images as extensible content.
"""
portal = self.portal
request = portal.REQUEST
request['PARENTS'] = [self.app]
website = self.setupWebSite()
web_section_portal_type = 'Web Section'
web_section = website.newContent(portal_type=web_section_portal_type)
document_reference = 'tiolive-ERP5.Freedom.TioLive'
upload_file = makeFileUpload('tiolive-ERP5.Freedom.TioLive-001-en.odp')
document = self.portal.document_module.newContent(
portal_type='Presentation',
reference=document_reference,
file=upload_file)
transaction.commit()
self.tic()
credential = 'ERP5TypeTestCase:'
# first, preview the draft in its physical location (in document module)
response = self.publish('%s/asEntireHTML' % document.absolute_url_path(),
credential)
self.assertEquals(response.getHeader('content-type'), 'text/html')
html = response.getBody()
self.assertTrue('<img' in html, html)
# find the img src
parser = etree.HTMLParser()
tree = etree.parse(StringIO(html), parser)
img_list = tree.findall('//img')
self.assertEquals(1, len(img_list))
src = img_list[0].get('src')
# and make another query for this img
response = self.publish('%s/%s' % ( document.absolute_url_path(), src),
credential)
self.assertEquals(response.getHeader('content-type'), 'image/png')
png = response.getBody()
self.assertTrue(png.startswith('\x89PNG'))
# then publish the document and access it anonymously by reference through
# the web site
document.publish()
transaction.commit()
self.tic()
response = self.publish('%s/%s/asEntireHTML' % (
website.absolute_url_path(), document_reference))
self.assertEquals(response.getHeader('content-type'), 'text/html')
html = response.getBody()
self.assertTrue('<img' in html, html)
# find the img src
parser = etree.HTMLParser()
tree = etree.parse(StringIO(html), parser)
img_list = tree.findall('//img')
self.assertEquals(1, len(img_list))
src = img_list[0].get('src')
# and make another query for this img
response = self.publish('%s/%s/%s' % (
website.absolute_url_path(), document_reference, src))
self.assertEquals(response.getHeader('content-type'), 'image/png')
png = response.getBody()
self.assertTrue(png.startswith('\x89PNG'))
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestERP5WebWithDms)) suite.addTest(unittest.makeSuite(TestERP5WebWithDms))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment