Commit d48c53bc authored by Rafael Monnerat's avatar Rafael Monnerat

Added tests for SVG to PNG conversion using Web Page and File

It is expected that Web Page (TextDocument) and File also have the same
capabilities when convert SVG to PNG format them Image.
parent d966c357
...@@ -777,25 +777,24 @@ return True ...@@ -777,25 +777,24 @@ return True
self._test_document_publication_workflow('Web Page', self._test_document_publication_workflow('Web Page',
'share_alive_action') 'share_alive_action')
def test_ImageConversionFromSVGToPNG_embeeded_data(self): def _testImageConversionFromSVGToPNG(self, portal_type="Image",
""" Test Convert one SVG Image with an image with the data filename="user-TESTSVG-CASE-EMBEDDEDDATA"):
at the url of the image tag.ie: """ Test Convert one SVG Image (Image, TextDocument, File ...) to
<image xlink:href="data:...." > PNG and compare the generated image is well generated.
""" """
portal = self.portal portal = self.portal
image_reference = 'NXD-IMAGE' module = portal.getDefaultModule(portal_type=portal_type)
image_module = portal.getDefaultModule(portal_type='Image') upload_file = makeFileUpload('%s.svg' % filename)
upload_file = makeFileUpload('user-TESTSVG-CASE-EMBEDDEDDATA.svg') image = module.newContent(portal_type=portal_type,
image = image_module.newContent(portal_type='Image',
file=upload_file, file=upload_file,
reference=image_reference) reference="NXD-DOCUMENT")
image.publish() image.publish()
transaction.commit() transaction.commit()
self.tic() self.tic()
self.assertEquals(image.getContentType(), 'image/svg+xml') self.assertEquals(image.getContentType(), 'image/svg+xml')
mime, converted_data = image.convert("png") mime, converted_data = image.convert("png")
self.assertEquals(mime, 'image/png') self.assertEquals(mime, 'image/png')
expected_image = makeFileUpload('user-TESTSVG-CASE-EMBEDDEDDATA.png') expected_image = makeFileUpload('%s.png' % filename)
# Compare images and accept some minimal difference, # Compare images and accept some minimal difference,
difference_value = compare_image(StringIO(converted_data), expected_image) difference_value = compare_image(StringIO(converted_data), expected_image)
...@@ -803,33 +802,7 @@ return True ...@@ -803,33 +802,7 @@ return True
"Conversion from svg to png create one too small image, " + \ "Conversion from svg to png create one too small image, " + \
"so it failed to download the image. (%s >= 100)" % difference_value) "so it failed to download the image. (%s >= 100)" % difference_value)
def test_ImageConversionFromSVGToPNG_http_url(self): def _testImageConversionFromSVGToPNG_file_url(self, portal_type="Image"):
""" Test Convert one SVG Image with an image with a full
url at the url of the image tag. ie:
<image xlink:href="http://www.erp5.com/user-XXX-XXX"
"""
portal = self.portal
image_reference = 'NXD-IMAGE'
image_module = portal.getDefaultModule(portal_type='Image')
upload_file = makeFileUpload('user-TESTSVG-CASE-FULLURL.svg')
image = image_module.newContent(portal_type='Image',
file=upload_file,
reference=image_reference)
image.publish()
transaction.commit()
self.tic()
self.assertEquals(image.getContentType(), 'image/svg+xml')
mime, converted_data = image.convert("png")
self.assertEquals(mime, 'image/png')
expected_image = makeFileUpload('user-TESTSVG-CASE-FULLURL.png')
# Compare images and accept some minimal difference,
difference_value = compare_image(StringIO(converted_data), expected_image)
self.assertTrue(difference_value < 100,
"Conversion from svg to png create one too small image, " + \
"so it failed to download the image. (%s >= 100)" % difference_value)
def test_ImageConversionFromSVGToPNG_file_url(self):
""" Test Convert one SVG Image with an image using local path (file) """ Test Convert one SVG Image with an image using local path (file)
at the url of the image tag. ie: at the url of the image tag. ie:
<image xlink:href="file:///../../user-XXX-XXX" <image xlink:href="file:///../../user-XXX-XXX"
...@@ -838,19 +811,18 @@ return True ...@@ -838,19 +811,18 @@ return True
prooves that conversion from SVG to PNG can use external images. prooves that conversion from SVG to PNG can use external images.
""" """
portal = self.portal portal = self.portal
image_reference = 'NXD-IMAGE' module = portal.getDefaultModule(portal_type=portal_type)
image_module = portal.getDefaultModule(portal_type='Image')
upload_file = makeFileUpload('user-TESTSVG-CASE-FULLURL-TEMPLATE.svg') upload_file = makeFileUpload('user-TESTSVG-CASE-FULLURL-TEMPLATE.svg')
svg_content = upload_file.read().replace("REPLACE_THE_URL_HERE", svg_content = upload_file.read().replace("REPLACE_THE_URL_HERE",
makeFilePath("user-TESTSVG-BACKGROUND-IMAGE.png")) makeFilePath("user-TESTSVG-BACKGROUND-IMAGE.png"))
# Add image using data instead file this time as it is not the goal of # Add image using data instead file this time as it is not the goal of
# This test assert this topic. # This test assert this topic.
image = image_module.newContent(portal_type='Image', image = module.newContent(portal_type=portal_type,
data=svg_content, data=svg_content,
filename=upload_file.filename, filename=upload_file.filename,
content_type="image/svg+xml", content_type="image/svg+xml",
reference=image_reference) reference="NXD-DOCYMENT")
image.publish() image.publish()
transaction.commit() transaction.commit()
self.tic() self.tic()
...@@ -865,6 +837,83 @@ return True ...@@ -865,6 +837,83 @@ return True
"Conversion from svg to png create one too small image, " + \ "Conversion from svg to png create one too small image, " + \
"so it failed to download the image. (%s >= 100)" % difference_value) "so it failed to download the image. (%s >= 100)" % difference_value)
def test_ImageConversionFromSVGToPNG_embeeded_data(self):
""" Test Convert one SVG Image with an image with the data
at the url of the image tag.ie:
<image xlink:href="data:...." >
"""
self._testImageConversionFromSVGToPNG("Image")
def test_FileConversionFromSVGToPNG_embeeded_data(self):
""" Test Convert one SVG Image with an image with the data
at the url of the image tag.ie:
<image xlink:href="data:...." >
"""
self._testImageConversionFromSVGToPNG("File")
def test_WebPageConversionFromSVGToPNG_embeeded_data(self):
""" Test Convert one SVG Image with an image with the data
at the url of the image tag.ie:
<image xlink:href="data:...." >
"""
self._testImageConversionFromSVGToPNG("Web Page")
def test_ImageConversionFromSVGToPNG_file_url(self):
""" Test Convert one SVG Image with an image using local path (file)
at the url of the image tag. ie:
<image xlink:href="file:///../../user-XXX-XXX"
This is not used by ERP5 in production, but this is way that
prooves that conversion from SVG to PNG can use external images.
"""
self._testImageConversionFromSVGToPNG_file_url("Image")
def test_FileConversionFromSVGToPNG_file_url(self):
""" Test Convert one SVG Image with an image using local path (file)
at the url of the image tag. ie:
<image xlink:href="file:///../../user-XXX-XXX"
This is not used by ERP5 in production, but this is way that
prooves that conversion from SVG to PNG can use external images.
"""
self._testImageConversionFromSVGToPNG_file_url("File")
def test_WebPageConversionFromSVGToPNG_file_url(self):
""" Test Convert one SVG Image with an image using local path (file)
at the url of the image tag. ie:
<image xlink:href="file:///../../user-XXX-XXX"
This is not used by ERP5 in production, but this is way that
prooves that conversion from SVG to PNG can use external images.
"""
self._testImageConversionFromSVGToPNG_file_url("Web Page")
def test_ImageConversionFromSVGToPNG_http_url(self):
""" Test Convert one SVG Image with an image with a full
url at the url of the image tag. ie:
<image xlink:href="http://www.erp5.com/user-XXX-XXX"
"""
self._testImageConversionFromSVGToPNG(
"Image", "user-TESTSVG-CASE-FULLURL")
def test_FileConversionFromSVGToPNG_http_url(self):
""" Test Convert one SVG Image with an image with a full
url at the url of the image tag. ie:
<image xlink:href="http://www.erp5.com/user-XXX-XXX"
"""
self._testImageConversionFromSVGToPNG(
"File", "user-TESTSVG-CASE-FULLURL")
def test_WebPageConversionFromSVGToPNG_http_url(self):
""" Test Convert one SVG Image with an image with a full
url at the url of the image tag. ie:
<image xlink:href="http://www.erp5.com/user-XXX-XXX"
"""
self._testImageConversionFromSVGToPNG(
"Web Page", "user-TESTSVG-CASE-FULLURL")
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