Commit c467bd28 authored by Sven Franck's avatar Sven Franck

erp5_corporate_identity: convert bmp data to compressed base64 png to view more easily

parent f096830e
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
<div class="ci-slideshow-container-right"> <div class="ci-slideshow-container-right">
&copy; &copy;
<span>2017</span>&nbsp; <span>2017</span>&nbsp;
<span></span><br /> <span>Test Organisation</span><br />
<span>Test Author, Test Recipient</span>&nbsp; <span>Test Author, Test Recipient</span>&nbsp;
<span class="page"></span> | <span class="topage"></span> <span class="page"></span> | <span class="topage"></span>
</div> </div>
......
...@@ -34,6 +34,8 @@ import functools ...@@ -34,6 +34,8 @@ import functools
import cStringIO import cStringIO
import math import math
import re import re
import io
import base64
host_url = r"https?://localhost(?::[0-9]+)?/[^/]+/" host_url = r"https?://localhost(?::[0-9]+)?/[^/]+/"
test_url = "https://softinst73908.host.vifib.net/erp5/" test_url = "https://softinst73908.host.vifib.net/erp5/"
...@@ -150,14 +152,21 @@ class TestCorporateIdentityTemplates(ERP5TypeTestCase): ...@@ -150,14 +152,21 @@ class TestCorporateIdentityTemplates(ERP5TypeTestCase):
def isImageRenderingEqual(self, image_data_1, image_data_2, max_rms=10.0): def isImageRenderingEqual(self, image_data_1, image_data_2, max_rms=10.0):
return self.computeImageRenderingRootMeanSquare(image_data_1, image_data_2) <= max_rms return self.computeImageRenderingRootMeanSquare(image_data_1, image_data_2) <= max_rms
def convertToPng(self, img_data):
bmp_file = Image.open(io.BytesIO(img_data))
img_buff = cStringIO.StringIO()
bmp_file.save(img_buff, format='PNG', optimize=True, quality=75)
img_data = img_buff.getvalue()
return ''.join(['data:image/png;base64,', base64.encodestring(img_data)])
def assertImageRenderingEquals(self, test_image_data, expected_image_data, message="Images rendering differs", max_rms=10.0): def assertImageRenderingEquals(self, test_image_data, expected_image_data, message="Images rendering differs", max_rms=10.0):
rms = self.computeImageRenderingRootMeanSquare(test_image_data, expected_image_data) rms = self.computeImageRenderingRootMeanSquare(test_image_data, expected_image_data)
if rms <= max_rms: if rms <= max_rms:
return return
raise AssertionError("%(message)s\nComparing image:\n%(base64_1)s\nWith image:\n%(base64_2)s\nRMS: %(rms)s > %(max_rms)s\nAssertionError: %(message)s" % { raise AssertionError("%(message)s\nComparing image:\n%(base64_1)s\nWith image:\n%(base64_2)s\nRMS: %(rms)s > %(max_rms)s\nAssertionError: %(message)s" % {
"message": message, "message": message,
"base64_1": "pfff", #base64.encodestring(test_image_data), "base64_1": self.convertToPng(test_image_data),
"base64_2": "pfff", #base64.encodestring(expected_image_data), "base64_2": self.convertToPng(expected_image_data),
"rms": rms, "rms": rms,
"max_rms": max_rms, "max_rms": max_rms,
}) })
...@@ -1122,4 +1131,3 @@ class TestCorporateIdentityTemplates(ERP5TypeTestCase): ...@@ -1122,4 +1131,3 @@ class TestCorporateIdentityTemplates(ERP5TypeTestCase):
) )
) )
\ No newline at end of file
\ No newline at end of file
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