Skip to content

Commit

Permalink
Fix PyQgsServerAccessControl on Ubuntu
Browse files Browse the repository at this point in the history
Add size tolerance to legend images, add masks for legend images
  • Loading branch information
nyalldawson committed Nov 23, 2015
1 parent f145843 commit 675da0c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions tests/src/python/test_qgsserver_accesscontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from osgeo.gdalconst import GA_ReadOnly
from qgis.server import QgsServer, QgsAccessControlFilter
from qgis.core import QgsRenderChecker
from PyQt4.QtCore import QSize
import tempfile


Expand Down Expand Up @@ -238,10 +239,10 @@ def test_wms_getlegendgraphic_hello(self):
}.items()])

response, headers = self._get_fullaccess(query_string)
self._img_diff_error(response, headers, "WMS_GetLegendGraphic_Hello", 250)
self._img_diff_error(response, headers, "WMS_GetLegendGraphic_Hello", 250, QSize(10, 10))

response, headers = self._get_restricted(query_string)
self._img_diff_error(response, headers, "WMS_GetLegendGraphic_Hello", 250)
self._img_diff_error(response, headers, "WMS_GetLegendGraphic_Hello", 250, QSize(10, 10))

def test_wms_getlegendgraphic_country(self):
query_string = "&".join(["%s=%s" % i for i in {
Expand All @@ -253,7 +254,7 @@ def test_wms_getlegendgraphic_country(self):
}.items()])

response, headers = self._get_fullaccess(query_string)
self._img_diff_error(response, headers, "WMS_GetLegendGraphic_Country", 250)
self._img_diff_error(response, headers, "WMS_GetLegendGraphic_Country", 250, QSize(10, 10))

response, headers = self._get_restricted(query_string)
self.assertEquals(
Expand Down Expand Up @@ -990,7 +991,7 @@ def _post_restricted(self, data, query_string=None):
del environ["REQUEST_BODY"]
return result

def _img_diff(self, image, control_image, max_diff):
def _img_diff(self, image, control_image, max_diff, max_size_diff=QSize()):
temp_image = path.join(tempfile.gettempdir(), "%s_result.png" % control_image)
with open(temp_image, "w") as f:
f.write(image)
Expand All @@ -999,13 +1000,15 @@ def _img_diff(self, image, control_image, max_diff):
control.setControlPathPrefix("qgis_server_accesscontrol")
control.setControlName(control_image)
control.setRenderedImage(temp_image)
if max_size_diff.isValid():
control.setSizeTolerance(max_size_diff.width(), max_size_diff.height())
return control.compareImages(control_image), control.report()

def _img_diff_error(self, response, headers, image, max_diff=10):
def _img_diff_error(self, response, headers, image, max_diff=10, max_size_diff=QSize()):
self.assertEquals(
headers.get("Content-Type"), "image/png",
"Content type is wrong: %s" % headers.get("Content-Type"))
test, report = self._img_diff(response, image, max_diff)
test, report = self._img_diff(response, image, max_diff, max_size_diff)

result_img = check_output(["base64", path.join(tempfile.gettempdir(), image + "_result.png")])
message = "Image is wrong\n%s\nImage:\necho '%s' | base64 -d >%s/%s_result.png" % (
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 675da0c

Please sign in to comment.