Commit e8e484bc authored by Rafael Monnerat's avatar Rafael Monnerat

Make tests more accurate with simpler images

The image comparation isn't advanced enough to identify minor color
 changes when convert to grey scale. So use simpler images to make
sure we do not get false positives.

The goal of image comparation is only for make sure background is
placed at the figures.
parent ca4bfbc6
......@@ -809,19 +809,14 @@ return True
"Conversion from svg to png create one too small image, " + \
"so it failed to download the image. (%s >= 100)" % difference_value)
def _testImageConversionFromSVGToPNG_file_url(self, portal_type="Image"):
""" 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.
def _testImageConversionFromSVGToPNG_url(self, image_url, portal_type="Image"):
""" Test Convert one SVG Image with an image url. ie:
<image xlink:href="xxx:///../../user-XXX-XXX"
"""
portal = self.portal
module = portal.getDefaultModule(portal_type=portal_type)
upload_file = makeFileUpload('user-TESTSVG-CASE-FULLURL-TEMPLATE.svg')
svg_content = upload_file.read().replace("REPLACE_THE_URL_HERE",
"file://" + makeFilePath("user-TESTSVG-BACKGROUND-IMAGE.png"))
upload_file = makeFileUpload('user-TESTSVG-CASE-URL-TEMPLATE.svg')
svg_content = upload_file.read().replace("REPLACE_THE_URL_HERE", image_url)
# Add image using data instead file this time as it is not the goal of
# This test assert this topic.
......@@ -836,7 +831,7 @@ return True
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')
expected_image = makeFileUpload('user-TESTSVG-CASE-URL.png')
# Compare images and accept some minimal difference,
difference_value = compare_image(StringIO(converted_data), expected_image)
......@@ -844,6 +839,35 @@ return True
"Conversion from svg to png create one too small image, " + \
"so it failed to download the image. (%s >= 100)" % difference_value)
def _testImageConversionFromSVGToPNG_file_url(self, portal_type="Image"):
""" 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.
"""
image_url = "file://" + makeFilePath("user-TESTSVG-BACKGROUND-IMAGE.png")
self._testImageConversionFromSVGToPNG_url(image_url, portal_type)
def _testImageConversionFromSVGToPNG_http_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
module = portal.getDefaultModule(portal_type=portal_type)
upload_file = makeFileUpload('user-TESTSVG-BACKGROUND-IMAGE.png')
background_image = module.newContent(portal_type=portal_type,
file=upload_file,
reference="NXD-BACKGROUND")
background_image.publish()
transaction.commit()
self.tic()
image_url = background_image.absolute_url() + "?format="
self._testImageConversionFromSVGToPNG_url(image_url, portal_type)
def _testImageConversionFromSVGToPNG_broken_url(self, portal_type="Image"):
""" Test Convert one broken SVG into PNG. The expected outcome is a
conversion error when an SVG contains one unreacheble xlink:href like.
......@@ -855,11 +879,11 @@ return True
"""
portal = self.portal
module = portal.getDefaultModule(portal_type=portal_type)
upload_file = makeFileUpload('user-TESTSVG-CASE-FULLURL-TEMPLATE.svg')
upload_file = makeFileUpload('user-TESTSVG-CASE-URL-TEMPLATE.svg')
svg_content = upload_file.read().replace("REPLACE_THE_URL_HERE",
"http://soidjsoidjqsoijdqsoidjqsdoijsqd.idjsijds/../user-XXX-XXX")
upload_file = makeFileUpload('user-TESTSVG-CASE-FULLURL-TEMPLATE.svg')
upload_file = makeFileUpload('user-TESTSVG-CASE-URL-TEMPLATE.svg')
svg2_content = upload_file.read().replace("REPLACE_THE_URL_HERE",
"https://www.erp5.com/usXXX-XXX")
......@@ -988,24 +1012,21 @@ return True
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")
self._testImageConversionFromSVGToPNG_http_url("Image")
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")
self._testImageConversionFromSVGToPNG_http_url("File")
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")
self._testImageConversionFromSVGToPNG_http_url("Web Page")
def test_suite():
suite = unittest.TestSuite()
......
This source diff could not be displayed because it is too large. You can view the blob instead.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
id="svg2"
version="1.1"
inkscape:version="0.48.2 r9819"
width="524.40942"
height="372.04724"
sodipodi:docname="user-howto.manage.support.requests.assign.event.to.ticket.create.follow.up.ticket-002-en.svg">
<metadata
id="metadata8">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs6" />
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1024"
inkscape:window-height="718"
id="namedview4"
showgrid="false"
inkscape:zoom="1.3707937"
inkscape:cx="270.63548"
inkscape:cy="273.56415"
inkscape:window-x="-3"
inkscape:window-y="-3"
inkscape:window-maximized="1"
inkscape:current-layer="svg2" />
<image
y="0.99838382"
x="0.11206181"
id="image3065"
xlink:href="http://www.erp5.com/user-howto.manage.support.requests.assign.event.to.ticket.create.follow.up.ticket.screenshot?format=png"
height="369.32098"
width="523.56" />
<rect
style="fill:none;stroke:#ff0000;stroke-width:2.696;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0"
id="rect2987"
width="81.987816"
height="11.938368"
x="64.116737"
y="43.860283"
rx="2.5779424"
ry="0.29129499" />
<rect
style="fill:none;stroke:#ff0000;stroke-width:2.81803679;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0"
id="rect2989"
width="82.598396"
height="9.534873"
x="64.417244"
y="68.28804"
rx="2.4387791"
ry="0.28804284" />
<path
sodipodi:type="arc"
style="fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
id="path3898"
sodipodi:cx="303.51724"
sodipodi:cy="155.48277"
sodipodi:rx="25.13793"
sodipodi:ry="25.13793"
d="m 328.65517,155.48277 a 25.13793,25.13793 0 1 1 -50.27586,0 25.13793,25.13793 0 1 1 50.27586,0 z"
transform="matrix(0.63956863,0,0,0.63956863,-19.039052,-62.99123)" />
<text
xml:space="preserve"
style="font-size:23px;font-style:normal;font-weight:bold;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#ff0000;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans Bold"
x="166.65985"
y="45.086403"
id="text3900"
sodipodi:linespacing="125%"
transform="scale(1.0034798,0.99653226)"><tspan
sodipodi:role="line"
id="tspan3902"
x="166.65985"
y="45.086403">1</tspan></text>
<path
sodipodi:type="arc"
style="fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
id="path3898-3"
sodipodi:cx="303.51724"
sodipodi:cy="155.48277"
sodipodi:rx="25.13793"
sodipodi:ry="25.13793"
d="m 328.65517,155.48277 a 25.13793,25.13793 0 1 1 -50.27586,0 25.13793,25.13793 0 1 1 50.27586,0 z"
transform="matrix(0.63956863,0,0,0.63956863,-17.252115,-25.057001)" />
<text
xml:space="preserve"
style="font-size:23px;font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;text-align:start;line-height:125%;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#0000ff;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans Bold"
x="168.57806"
y="83.152695"
id="text3900-2"
sodipodi:linespacing="125%"
transform="scale(1.0034798,0.99653226)"><tspan
sodipodi:role="line"
id="tspan3902-0"
x="168.57806"
y="83.152695">2</tspan></text>
</svg>
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