Skip to content

Commit

Permalink
Add unfiltered test case to prove that filters are not persistent
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Mar 1, 2021
1 parent b6ddbb5 commit b4f8fa3
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 17 deletions.
Expand Up @@ -143,13 +143,16 @@ def setUpClass(cls):
cls._accesscontrol = RestrictedAccessControl(cls._server_iface)
cls._server_iface.registerAccessControl(cls._accesscontrol, 100)

def setUp(self):
super().setUp()
def _clear_contraints(self):
self._accesscontrol.active['authorizedLayerAttributes'] = False
self._accesscontrol.active['layerFilterExpression'] = False
self._accesscontrol.active['layerFilterSubsetString'] = False
self._accesscontrol.active['layerPermissions'] = False

def setUp(self):
super().setUp()
self._clear_contraints()

def _check_exception(self, qs, exception_text):
"""Check that server throws"""

Expand Down Expand Up @@ -195,22 +198,26 @@ def test_wms_getprint_postgres(self):
'map0:EXTENT': '45.70487804878048621,7.67926829268292099,46.22987804878049189,8.42479674796748235',
}.items())])

req = QgsBufferServerRequest('http://my_server/' + qs)
res = QgsBufferServerResponse()
self._server.handleRequest(req, res, self.test_project)
self.assertEqual(res.statusCode(), 200)
def _check_red():

result_path = os.path.join(self.temp_dir.path(), 'red.png')
with open(result_path, 'wb+') as f:
f.write(res.body())
req = QgsBufferServerRequest('http://my_server/' + qs)
res = QgsBufferServerResponse()
self._server.handleRequest(req, res, self.test_project)
self.assertEqual(res.statusCode(), 200)

# A full red image is expected
image = QImage(result_path)
self.assertFalse(image.isGrayscale())
color = image.pixelColor(100, 100)
self.assertEqual(color.red(), 255)
self.assertEqual(color.green(), 0)
self.assertEqual(color.blue(), 0)
result_path = os.path.join(self.temp_dir.path(), 'red.png')
with open(result_path, 'wb+') as f:
f.write(res.body())

# A full red image is expected
image = QImage(result_path)
self.assertFalse(image.isGrayscale())
color = image.pixelColor(100, 100)
self.assertEqual(color.red(), 255)
self.assertEqual(color.green(), 0)
self.assertEqual(color.blue(), 0)

_check_red()

# Now activate the rule to exclude the feature where pk1 = 1, pk2 = 2
# A white image is expected
Expand Down Expand Up @@ -302,6 +309,17 @@ def test_wms_getprint_postgres(self):

self._img_diff_error(res.body(), res.headers(), "WMS_GetPrint_postgres_print2_filtered")

# Clear constraints
self._clear_contraints()
_check_red()

req = QgsBufferServerRequest('http://my_server/' + qs.replace('print1', 'print2'))
res = QgsBufferServerResponse()
self._server.handleRequest(req, res, self.test_project)
self.assertEqual(res.statusCode(), 200)

self._img_diff_error(res.body(), res.headers(), "WMS_GetPrint_postgres_print2")

def test_atlas(self):
"""Test atlas"""

Expand All @@ -316,7 +334,7 @@ def test_atlas(self):
'TEMPLATE': "print1",
}.items())])

req = QgsBufferServerRequest('http://my_server/' + qs + '&ATLAS_PK=1,1')
req = QgsBufferServerRequest('http://my_server/' + qs + '&ATLAS_PK=1,2')
res = QgsBufferServerResponse()

self._server.handleRequest(req, res, self.test_project)
Expand All @@ -342,6 +360,26 @@ def test_atlas(self):
self._accesscontrol.active['layerFilterExpression'] = True
self._check_exception(qs + '&ATLAS_PK=1,2', "Atlas error: empty atlas.")

# Remove all constraints
self._clear_contraints()
req = QgsBufferServerRequest('http://my_server/' + qs + '&ATLAS_PK=1,2')
res = QgsBufferServerResponse()

self._server.handleRequest(req, res, self.test_project)
self.assertEqual(res.statusCode(), 200)

result_path = os.path.join(self.temp_dir.path(), 'atlas_1_2.png')
with open(result_path, 'wb+') as f:
f.write(res.body())

# A full red image is expected
image = QImage(result_path)
self.assertFalse(image.isGrayscale())
color = image.pixelColor(100, 100)
self.assertEqual(color.red(), 255)
self.assertEqual(color.green(), 0)
self.assertEqual(color.blue(), 0)


if __name__ == '__main__':
unittest.main()
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.
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 b4f8fa3

Please sign in to comment.