Skip to content
Permalink
Browse files

Add/update tests

  • Loading branch information
pblottiere committed May 30, 2017
1 parent c85cf23 commit e663d192e3cbf2319b8a2edaec6b76b5cc3052ae
Showing with 15,315 additions and 806 deletions.
  1. +6 −2 tests/src/python/test_qgsserver.py
  2. +11 −12 tests/src/python/test_qgsserver_accesscontrol.py
  3. +40 −3 tests/src/python/test_qgsserver_projectutils.py
  4. +458 −0 tests/src/python/test_qgsserver_wms.py
  5. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_Annotations/WMS_GetMap_Annotations.png
  6. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_Annotations/WMS_GetMap_Annotations_mask.png
  7. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_Basic2/WMS_GetMap_Basic2.png
  8. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_Basic2/WMS_GetMap_Basic2_mask.png
  9. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_Basic3/WMS_GetMap_Basic3.png
  10. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_Basic3/WMS_GetMap_Basic3_mask.png
  11. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_Basic4/WMS_GetMap_Basic4.png
  12. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_Basic4/WMS_GetMap_Basic4_mask.png
  13. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_Diagrams/WMS_GetMap_Diagrams.png
  14. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_Diagrams/WMS_GetMap_Diagrams_mask.png
  15. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_Filter2/WMS_GetMap_Filter2.png
  16. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_Filter2/WMS_GetMap_Filter2_mask.png
  17. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_Filter3/WMS_GetMap_Filter3.png
  18. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_Filter3/WMS_GetMap_Filter3_mask.png
  19. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_Highlight/WMS_GetMap_Highlight.png
  20. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_Highlight/WMS_GetMap_Highlight_mask.png
  21. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_Opacities/WMS_GetMap_Opacities.png
  22. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_Opacities2/WMS_GetMap_Opacities2.png
  23. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_SLD/WMS_GetMap_SLD.png
  24. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_SLDRestored/WMS_GetMap_SLDRestored.png
  25. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_SLDRestored/WMS_GetMap_SLDRestored_mask.png
  26. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_StyleCustom/WMS_GetMap_StyleCustom_mask.png
  27. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_StyleDefault/WMS_GetMap_StyleDefault_mask.png
  28. BIN ...ata/control_images/qgis_server_accesscontrol/Restricted_WMS_GetMap/Restricted_WMS_GetMap_mask.png
  29. BIN ...esscontrol/Restricted_WMS_GetMap_projectsubstring/Restricted_WMS_GetMap_projectsubstring_mask.png
  30. BIN tests/testdata/control_images/qgis_server_accesscontrol/WMS_GetMap/WMS_GetMap_mask.png
  31. BIN ...images/qgis_server_accesscontrol/WMS_GetMap_projectsubstring/WMS_GetMap_projectsubstring_mask.png
  32. BIN tests/testdata/qgis_server_accesscontrol/_helloworld.db
  33. BIN tests/testdata/qgis_server_accesscontrol/helloworld.db
  34. +1,430 −714 tests/testdata/qgis_server_accesscontrol/project.qgs
  35. +3,850 −0 tests/testdata/qgis_server_accesscontrol/project_state.qgs
  36. +4,199 −0 tests/testdata/qgis_server_accesscontrol/project_use_layerids.qgs
  37. +3,935 −0 tests/testdata/qgis_server_accesscontrol/project_with_annotations.qgs
  38. +1,117 −75 tests/testdata/qgis_server_project/project.qgs
  39. +269 −0 tests/testdata/qgis_server_project/project2.qgs
@@ -55,6 +55,7 @@


class QgsServerTestBase(unittest.TestCase):

"""Base class for QGIS server tests"""

# Set to True in child classes to re-generate reference files for this class
@@ -97,6 +98,9 @@ def setUp(self):

d = unitTestDataPath('qgis_server_accesscontrol') + '/'
self.projectPath = os.path.join(d, "project.qgs")
self.projectAnnotationPath = os.path.join(d, "project_with_annotations.qgs")
self.projectStatePath = os.path.join(d, "project_state.qgs")
self.projectUseLayerIdsPath = os.path.join(d, "project_use_layerids.qgs")

# Clean env just to be sure
env_vars = ['QUERY_STRING', 'QGIS_PROJECT_FILE']
@@ -187,14 +191,14 @@ def _execute_request(self, qs, requestMethod=QgsServerRequest.GetMethod, data=No
self.server.handleRequest(request, response)
headers = []
rh = response.headers()
rk = list(rh.keys())
rk.sort()
rk = sorted(rh.keys())
for k in rk:
headers.append(("%s: %s" % (k, rh[k])).encode('utf-8'))
return b"\n".join(headers) + b"\n\n", bytes(response.body())


class TestQgsServer(QgsServerTestBase):

"""Tests container"""

# Set to True to re-generate reference files for this class
@@ -142,8 +142,8 @@ def authorizedLayerAttributes(self, layer, attributes):
if not self._active:
return super(RestrictedAccessControl, self).authorizedLayerAttributes(layer, attributes)

if "colour" in attributes: # spellok
attributes.remove("colour") # spellok
if "color" in attributes: # spellok
attributes.remove("color") # spellok
return attributes

def allowToEdit(self, layer, feature):
@@ -169,8 +169,7 @@ def _execute_request(cls, qs, requestMethod=QgsServerRequest.GetMethod, data=Non
cls._server.handleRequest(request, response)
headers = []
rh = response.headers()
rk = list(rh.keys())
rk.sort()
rk = sorted(rh.keys())
for k in rk:
headers.append(("%s: %s" % (k, rh[k])).encode('utf-8'))
return b"\n".join(headers) + b"\n\n", bytes(response.body())
@@ -250,7 +249,7 @@ def test_wms_getprojectsettings(self):
str(response).find("<TreeName>Country</TreeName>") != -1,
"No Country layer in GetProjectSettings\n%s" % response)
self.assertTrue(
str(response).find("<LayerDrawingOrder>Country_Labels,Country,dem,Hello_Filter_SubsetString,Hello_Project_SubsetString,Hello_SubsetString,Hello,db_point</LayerDrawingOrder>") != -1,
str(response).find("<LayerDrawingOrder>Country_Diagrams,Country_Labels,Country,dem,Hello_Filter_SubsetString,Hello_Project_SubsetString,Hello_SubsetString,Hello,db_point</LayerDrawingOrder>") != -1,
"LayerDrawingOrder in GetProjectSettings\n%s" % response)

response, headers = self._get_restricted(query_string)
@@ -261,7 +260,7 @@ def test_wms_getprojectsettings(self):
str(response).find("<TreeName>Country</TreeName>") != -1,
"Country layer in GetProjectSettings\n%s" % response)
self.assertTrue(
str(response).find("<LayerDrawingOrder>Country_Labels,dem,Hello_Filter_SubsetString,Hello_Project_SubsetString,Hello_SubsetString,Hello,db_point</LayerDrawingOrder>") != -1,
str(response).find("<LayerDrawingOrder>Country_Diagrams,Country_Labels,dem,Hello_Filter_SubsetString,Hello_Project_SubsetString,Hello_SubsetString,Hello,db_point</LayerDrawingOrder>") != -1,
"LayerDrawingOrder in GetProjectSettings\n%s" % response)

def test_wms_getprojectsettings(self):
@@ -451,18 +450,18 @@ def test_wms_getfeatureinfo_hello(self):
str(response).find("<qgs:pk>1</qgs:pk>") != -1,
"No result in GetFeatureInfo\n%s" % response)
self.assertTrue(
str(response).find("<qgs:colour>red</qgs:colour>") != -1, # spellok
str(response).find("<qgs:color>red</qgs:color>") != -1, # spellok
"No color in result of GetFeatureInfo\n%s" % response)

response, headers = self._get_restricted(query_string)
self.assertTrue(
str(response).find("<qgs:pk>1</qgs:pk>") != -1,
"No result in GetFeatureInfo\n%s" % response)
self.assertFalse(
str(response).find("<qgs:colour>red</qgs:colour>") != -1, # spellok
str(response).find("<qgs:color>red</qgs:color>") != -1, # spellok
"Unexpected color in result of GetFeatureInfo\n%s" % response)
self.assertFalse(
str(response).find("<qgs:colour>NULL</qgs:colour>") != -1, # spellok
str(response).find("<qgs:color>NULL</qgs:color>") != -1, # spellok
"Unexpected color NULL in result of GetFeatureInfo\n%s" % response)

def test_wms_getfeatureinfo_hello2(self):
@@ -603,18 +602,18 @@ def test_wfs_getfeature_hello(self):
str(response).find("<qgs:pk>1</qgs:pk>") != -1,
"No result in GetFeature\n%s" % response)
self.assertTrue(
str(response).find("<qgs:colour>red</qgs:colour>") != -1, # spellok
str(response).find("<qgs:color>red</qgs:color>") != -1, # spellok
"No color in result of GetFeature\n%s" % response)

response, headers = self._post_restricted(data)
self.assertTrue(
str(response).find("<qgs:pk>1</qgs:pk>") != -1,
"No result in GetFeature\n%s" % response)
self.assertFalse(
str(response).find("<qgs:colour>red</qgs:colour>") != -1, # spellok
str(response).find("<qgs:color>red</qgs:color>") != -1, # spellok
"Unexpected color in result of GetFeature\n%s" % response)
self.assertFalse(
str(response).find("<qgs:colour>NULL</qgs:colour>") != -1, # spellok
str(response).find("<qgs:color>NULL</qgs:color>") != -1, # spellok
"Unexpected color NULL in result of GetFeature\n%s" % response)

def test_wfs_getfeature_hello2(self):
@@ -27,9 +27,12 @@ def setUp(self):
self.testdata_path = unitTestDataPath('qgis_server_project') + '/'

self.prj = QgsProject()
prjPath = os.path.join(self.testdata_path, "project.qgs")
self.prj.setFileName(prjPath)
self.prj.read()
self.prjPath = os.path.join(self.testdata_path, "project.qgs")
self.prj.read(self.prjPath)

self.prj2 = QgsProject()
self.prj2Path = os.path.join(self.testdata_path, "project2.qgs")
self.prj2.read(self.prj2Path)

def tearDown(self):
pass
@@ -43,6 +46,40 @@ def test_url(self):
self.assertEqual(QgsServerProjectUtils.wcsServiceUrl(self.prj), "my_wcs_advertised_url")
self.assertEqual(QgsServerProjectUtils.wfsServiceUrl(self.prj), "my_wfs_advertised_url")

def test_wmsuselayerids(self):
self.assertEqual(QgsServerProjectUtils.wmsUseLayerIds(self.prj), False)
self.assertEqual(QgsServerProjectUtils.wmsUseLayerIds(self.prj2), True)

def test_wmsrestrictedlayers(self):
# retrieve entry from project
result = QgsServerProjectUtils.wmsRestrictedLayers(self.prj)
expected = []
expected.append('points') # layer
expected.append('group1') # local group
expected.append('groupEmbedded') # embedded group

self.assertListEqual(sorted(expected), sorted(result))

def test_wfslayersids(self):
# retrieve entry from project
result = QgsServerProjectUtils.wfsLayerIds(self.prj)

expected = []
expected.append('multipoint20170309173637804') # from embedded group
expected.append('points20170309173738552') # local layer
expected.append('polys20170309173913723') # from local group

self.assertEqual(expected, result)

def test_wcslayersids(self):
# retrieve entry from project
result = QgsServerProjectUtils.wcsLayerIds(self.prj)

expected = []
expected.append('landsat20170313142548073')

self.assertEqual(expected, result)


if __name__ == '__main__':
unittest.main()

0 comments on commit e663d19

Please sign in to comment.
You can’t perform that action at this time.