Skip to content

Commit 497f270

Browse files
committed
Partially fix access control test for Win
1 parent 974cc35 commit 497f270

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

tests/src/python/test_qgsserver_accesscontrol.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from PyQt4.QtCore import QSize
2828
import tempfile
2929
import urllib
30+
import base64
3031

3132

3233
XML_NS = \
@@ -1029,7 +1030,8 @@ def _post_restricted(self, data, query_string=None):
10291030

10301031
def _img_diff(self, image, control_image, max_diff, max_size_diff=QSize()):
10311032
temp_image = path.join(tempfile.gettempdir(), "%s_result.png" % control_image)
1032-
with open(temp_image, "w") as f:
1033+
1034+
with open(temp_image, "wb") as f:
10331035
f.write(image)
10341036

10351037
control = QgsRenderChecker()
@@ -1046,21 +1048,22 @@ def _img_diff_error(self, response, headers, image, max_diff=10, max_size_diff=Q
10461048
"Content type is wrong: %s" % headers.get("Content-Type"))
10471049
test, report = self._img_diff(response, image, max_diff, max_size_diff)
10481050

1049-
result_img = check_output(["base64", path.join(tempfile.gettempdir(), image + "_result.png")])
1050-
message = "Image is wrong\n%s\nImage:\necho '%s' | base64 -d >%s/%s_result.png" % (
1051-
report, result_img.strip(), tempfile.gettempdir(), image
1052-
)
1051+
with open(path.join(tempfile.gettempdir(), image + "_result.png"), "rb") as rendered_file:
1052+
encoded_rendered_file = base64.b64encode(rendered_file.read())
1053+
message = "Image is wrong\n%s\nImage:\necho '%s' | base64 -d >%s/%s_result.png" % (
1054+
report, encoded_rendered_file.strip(), tempfile.gettempdir(), image
1055+
)
10531056

1054-
if path.isfile(path.join(tempfile.gettempdir(), image + "_result_diff.png")):
1055-
diff_img = check_output(["base64", path.join(tempfile.gettempdir(), image + "_result_diff.png")])
1057+
with open(path.join(tempfile.gettempdir(), image + "_result_diff.png"), "rb") as diff_file:
1058+
encoded_diff_file = base64.b64encode(diff_file.read())
10561059
message += "\nDiff:\necho '%s' | base64 -d > %s/%s_result_diff.png" % (
1057-
diff_img.strip(), tempfile.gettempdir(), image
1060+
encoded_diff_file.strip(), tempfile.gettempdir(), image
10581061
)
1062+
10591063
self.assertTrue(test, message)
10601064

10611065
def _geo_img_diff(self, image_1, image_2):
1062-
1063-
with open(path.join(tempfile.gettempdir(), image_2), "w") as f:
1066+
with open(path.join(tempfile.gettempdir(), image_2), "wb") as f:
10641067
f.write(image_1)
10651068
image_1 = gdal.Open(path.join(tempfile.gettempdir(), image_2), GA_ReadOnly)
10661069
assert image_1, "No output image written: " + image_2

0 commit comments

Comments
 (0)