Skip to content
Permalink
Browse files
[Server] Add tests (GetContext and access control project)
  • Loading branch information
rldhont committed May 23, 2017
1 parent b82d757 commit 5d9b460fac429556237d8e30cefa5c47a3c5a3ac
@@ -187,7 +187,7 @@ def wms_request_compare(self, request, extra=None, reference_file=None):

def test_project_wms(self):
"""Test some WMS request"""
for request in ('GetCapabilities', 'GetProjectSettings'):
for request in ('GetCapabilities', 'GetProjectSettings', 'GetContext'):
self.wms_request_compare(request)

# Test getfeatureinfo response
@@ -237,6 +237,41 @@ def test_project_wms_inspire(self):
for request in ('GetCapabilities',):
self.wms_inspire_request_compare(request)

def wms_accesscontrol_request_compare(self, request, extra=None, reference_file=None):
project = self.projectPath
assert os.path.exists(project), "Project file not found: " + project

query_string = 'MAP=%s&SERVICE=WMS&VERSION=1.3&REQUEST=%s' % (urllib.quote(project), request)
if extra is not None:
query_string += extra
header, body = [str(_v) for _v in self.server.handleRequest(query_string)]
response = header + body
f = open(self.testdata_path + request.lower() + '_accesscontrol.txt')
expected = f.read()
f.close()
# Store the output for debug or to regenerate the reference documents:
"""
f = open(os.path.dirname(__file__) + '/expected.txt', 'w+')
f.write(expected)
f.close()
f = open(os.path.dirname(__file__) + '/response.txt', 'w+')
f.write(response)
f.close()
"""
response = re.sub(RE_STRIP_PATH, '', response)
expected = re.sub(RE_STRIP_PATH, '', expected)

# for older GDAL versions (<2.0), id field will be integer type
if int(osgeo.gdal.VersionInfo()[:1]) < 2:
expected = expected.replace('typeName="Integer64" precision="0" length="10" editType="TextEdit" type="qlonglong"', 'typeName="Integer" precision="0" length="10" editType="TextEdit" type="int"')

self.assertEqual(response, expected, msg="request %s failed.\n Query: %s\n Expected:\n%s\n\n Response:\n%s" % (query_string, request, expected, response))

def test_project_accesscontrol_wms(self):
"""Test some WMS request"""
for request in ('GetCapabilities', 'GetProjectSettings', 'GetContext'):
self.wms_accesscontrol_request_compare(request)

# WFS tests
def wfs_request_compare(self, request):
project = self.testdata_path + "test_project_wfs.qgs"
@@ -0,0 +1,328 @@

Content-Type: text/xml; charset=utf-8

<?xml version="1.0" encoding="utf-8"?>
<WMS_Capabilities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.3" xmlns="http://www.opengis.net/wms" xsi:schemaLocation="http://www.opengis.net/wms http://schemas.opengis.net/wms/1.3.0/capabilities_1_3_0.xsd http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/sld_capabilities.xsd http://www.qgis.org/wms http:?&amp;SERVICE=WMS&amp;REQUEST=GetSchemaExtension" xmlns:sld="http://www.opengis.net/sld" xmlns:qgs="http://www.qgis.org/wms">
<Service>
<Name>WMS</Name>
<Title>QGIS Server test</Title>
<Abstract>Simple test app.</Abstract>
<KeywordList>
<Keyword vocabulary="ISO">infoMapAccessService</Keyword>
</KeywordList>
<OnlineResource xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href=""/>
<ContactInformation>
<ContactPersonPrimary>
<ContactPerson>Stéphane Brunner</ContactPerson>
<ContactOrganization>QGIS</ContactOrganization>
<ContactPosition></ContactPosition>
</ContactPersonPrimary>
<ContactVoiceTelephone></ContactVoiceTelephone>
<ContactElectronicMailAddress></ContactElectronicMailAddress>
</ContactInformation>
<Fees>conditions unknown</Fees>
<AccessConstraints>None</AccessConstraints>
<MaxWidth>5000</MaxWidth>
<MaxHeight>5000</MaxHeight>
</Service>
<Capability>
<Request>
<GetCapabilities>
<Format>text/xml</Format>
<DCPType>
<HTTP>
<Get>
<OnlineResource xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http:?&amp;"/>
</Get>
</HTTP>
</DCPType>
</GetCapabilities>
<GetMap>
<Format>image/jpeg</Format>
<Format>image/png</Format>
<Format>image/png; mode=16bit</Format>
<Format>image/png; mode=8bit</Format>
<Format>image/png; mode=1bit</Format>
<Format>application/dxf</Format>
<DCPType>
<HTTP>
<Get>
<OnlineResource xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http:?&amp;"/>
</Get>
</HTTP>
</DCPType>
</GetMap>
<GetFeatureInfo>
<Format>text/plain</Format>
<Format>text/html</Format>
<Format>text/xml</Format>
<Format>application/vnd.ogc.gml</Format>
<Format>application/vnd.ogc.gml/3.1.1</Format>
<DCPType>
<HTTP>
<Get>
<OnlineResource xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http:?&amp;"/>
</Get>
</HTTP>
</DCPType>
</GetFeatureInfo>
<sld:GetLegendGraphic>
<Format>image/jpeg</Format>
<Format>image/png</Format>
<DCPType>
<HTTP>
<Get>
<OnlineResource xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http:?&amp;"/>
</Get>
</HTTP>
</DCPType>
</sld:GetLegendGraphic>
<sld:DescribeLayer>
<Format>text/xml</Format>
<DCPType>
<HTTP>
<Get>
<OnlineResource xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http:?&amp;"/>
</Get>
</HTTP>
</DCPType>
</sld:DescribeLayer>
<qgs:GetStyles>
<Format>text/xml</Format>
<DCPType>
<HTTP>
<Get>
<OnlineResource xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http:?&amp;"/>
</Get>
</HTTP>
</DCPType>
</qgs:GetStyles>
</Request>
<Exception>
<Format>XML</Format>
</Exception>
<Layer queryable="1">
<Name>QGIS Server Hello World</Name>
<Title>QGIS Server Hello World</Title>
<CRS>CRS:84</CRS>
<CRS>EPSG:3857</CRS>
<CRS>EPSG:4326</CRS>
<EX_GeographicBoundingBox>
<westBoundLongitude>-174.767</westBoundLongitude>
<eastBoundLongitude>177.931</eastBoundLongitude>
<southBoundLatitude>-69.9578</southBoundLatitude>
<northBoundLatitude>84.3079</northBoundLatitude>
</EX_GeographicBoundingBox>
<BoundingBox CRS="EPSG:4326" maxx="84.3079" minx="-69.9578" maxy="177.931" miny="-174.767"/>
<BoundingBox CRS="EPSG:3857" maxx="2.09619e+07" minx="-2.06097e+07" maxy="1.91438e+07" miny="-1.1055e+07"/>
<Layer queryable="1">
<Name>db_point</Name>
<Title>db_point</Title>
<CRS>CRS:84</CRS>
<CRS>EPSG:3857</CRS>
<CRS>EPSG:4326</CRS>
<EX_GeographicBoundingBox>
<westBoundLongitude>0.00898315</westBoundLongitude>
<eastBoundLongitude>0.00898315</eastBoundLongitude>
<southBoundLatitude>0.0179663</southBoundLatitude>
<northBoundLatitude>0.0179663</northBoundLatitude>
</EX_GeographicBoundingBox>
<BoundingBox CRS="EPSG:4326" maxx="0.0179663" minx="0.0179663" maxy="0.00898315" miny="0.00898315"/>
<BoundingBox CRS="EPSG:3857" maxx="1000" minx="1000" maxy="2000" miny="2000"/>
<Style>
<Name>default</Name>
<Title>default</Title>
<LegendURL>
<Format>image/png</Format>
<OnlineResource xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http:?&amp;&amp;SERVICE=WMS&amp;VERSION=1.3&amp;REQUEST=GetLegendGraphic&amp;LAYER=db_point&amp;FORMAT=image/png&amp;STYLE=default"/>
</LegendURL>
</Style>
</Layer>
<Layer queryable="1">
<Name>Hello</Name>
<Title>Hello</Title>
<CRS>CRS:84</CRS>
<CRS>EPSG:3857</CRS>
<CRS>EPSG:4326</CRS>
<EX_GeographicBoundingBox>
<westBoundLongitude>-132.468</westBoundLongitude>
<eastBoundLongitude>101.889</eastBoundLongitude>
<southBoundLatitude>-1.00674</southBoundLatitude>
<northBoundLatitude>69.5205</northBoundLatitude>
</EX_GeographicBoundingBox>
<BoundingBox CRS="EPSG:4326" maxx="69.5205" minx="-1.00674" maxy="101.889" miny="-132.468"/>
<BoundingBox CRS="EPSG:3857" maxx="1.13422e+07" minx="-1.47463e+07" maxy="1.09144e+07" miny="-112075"/>
<Style>
<Name>default</Name>
<Title>default</Title>
<LegendURL>
<Format>image/png</Format>
<OnlineResource xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http:?&amp;&amp;SERVICE=WMS&amp;VERSION=1.3&amp;REQUEST=GetLegendGraphic&amp;LAYER=Hello&amp;FORMAT=image/png&amp;STYLE=default"/>
</LegendURL>
</Style>
</Layer>
<Layer queryable="1">
<Name>Hello_SubsetString</Name>
<Title>Hello_SubsetString</Title>
<CRS>CRS:84</CRS>
<CRS>EPSG:3857</CRS>
<CRS>EPSG:4326</CRS>
<EX_GeographicBoundingBox>
<westBoundLongitude>-132.468</westBoundLongitude>
<eastBoundLongitude>101.889</eastBoundLongitude>
<southBoundLatitude>-1.00674</southBoundLatitude>
<northBoundLatitude>69.5205</northBoundLatitude>
</EX_GeographicBoundingBox>
<BoundingBox CRS="EPSG:4326" maxx="69.5205" minx="-1.00674" maxy="101.889" miny="-132.468"/>
<BoundingBox CRS="EPSG:3857" maxx="1.13422e+07" minx="-1.47463e+07" maxy="1.09144e+07" miny="-112075"/>
<Style>
<Name>default</Name>
<Title>default</Title>
<LegendURL>
<Format>image/png</Format>
<OnlineResource xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http:?&amp;&amp;SERVICE=WMS&amp;VERSION=1.3&amp;REQUEST=GetLegendGraphic&amp;LAYER=Hello_SubsetString&amp;FORMAT=image/png&amp;STYLE=default"/>
</LegendURL>
</Style>
</Layer>
<Layer queryable="1">
<Name>Hello_Project_SubsetString</Name>
<Title>Hello_Project_SubsetString</Title>
<CRS>CRS:84</CRS>
<CRS>EPSG:3857</CRS>
<CRS>EPSG:4326</CRS>
<EX_GeographicBoundingBox>
<westBoundLongitude>-132.468</westBoundLongitude>
<eastBoundLongitude>101.889</eastBoundLongitude>
<southBoundLatitude>-1.00674</southBoundLatitude>
<northBoundLatitude>69.5205</northBoundLatitude>
</EX_GeographicBoundingBox>
<BoundingBox CRS="EPSG:4326" maxx="69.5205" minx="-1.00674" maxy="101.889" miny="-132.468"/>
<BoundingBox CRS="EPSG:3857" maxx="1.13422e+07" minx="-1.47463e+07" maxy="1.09144e+07" miny="-112075"/>
<Style>
<Name>default</Name>
<Title>default</Title>
<LegendURL>
<Format>image/png</Format>
<OnlineResource xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http:?&amp;&amp;SERVICE=WMS&amp;VERSION=1.3&amp;REQUEST=GetLegendGraphic&amp;LAYER=Hello_Project_SubsetString&amp;FORMAT=image/png&amp;STYLE=default"/>
</LegendURL>
</Style>
</Layer>
<Layer queryable="1">
<Name>Hello_Filter_SubsetString</Name>
<Title>Hello_Filter_SubsetString</Title>
<CRS>CRS:84</CRS>
<CRS>EPSG:3857</CRS>
<CRS>EPSG:4326</CRS>
<EX_GeographicBoundingBox>
<westBoundLongitude>-132.468</westBoundLongitude>
<eastBoundLongitude>101.889</eastBoundLongitude>
<southBoundLatitude>-1.00674</southBoundLatitude>
<northBoundLatitude>69.5205</northBoundLatitude>
</EX_GeographicBoundingBox>
<BoundingBox CRS="EPSG:4326" maxx="69.5205" minx="-1.00674" maxy="101.889" miny="-132.468"/>
<BoundingBox CRS="EPSG:3857" maxx="1.13422e+07" minx="-1.47463e+07" maxy="1.09144e+07" miny="-112075"/>
<Style>
<Name>default</Name>
<Title>default</Title>
<LegendURL>
<Format>image/png</Format>
<OnlineResource xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http:?&amp;&amp;SERVICE=WMS&amp;VERSION=1.3&amp;REQUEST=GetLegendGraphic&amp;LAYER=Hello_Filter_SubsetString&amp;FORMAT=image/png&amp;STYLE=default"/>
</LegendURL>
</Style>
</Layer>
<Layer queryable="1">
<Name>dem</Name>
<Title>dem</Title>
<CRS>CRS:84</CRS>
<CRS>EPSG:3857</CRS>
<CRS>EPSG:4326</CRS>
<EX_GeographicBoundingBox>
<westBoundLongitude>-30</westBoundLongitude>
<eastBoundLongitude>3.33245e-12</eastBoundLongitude>
<southBoundLatitude>30</southBoundLatitude>
<northBoundLatitude>60</northBoundLatitude>
</EX_GeographicBoundingBox>
<BoundingBox CRS="EPSG:4326" maxx="60" minx="30" maxy="3.33245e-12" miny="-30"/>
<BoundingBox CRS="EPSG:3857" maxx="3.73885e-07" minx="-3.33958e+06" maxy="8.39974e+06" miny="3.50355e+06"/>
<Style>
<Name>default</Name>
<Title>default</Title>
<LegendURL>
<Format>image/png</Format>
<OnlineResource xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http:?&amp;&amp;SERVICE=WMS&amp;VERSION=1.3&amp;REQUEST=GetLegendGraphic&amp;LAYER=dem&amp;FORMAT=image/png&amp;STYLE=default"/>
</LegendURL>
</Style>
</Layer>
<Layer queryable="1">
<Name>Country</Name>
<Title>Country</Title>
<CRS>CRS:84</CRS>
<CRS>EPSG:3857</CRS>
<CRS>EPSG:4326</CRS>
<EX_GeographicBoundingBox>
<westBoundLongitude>-176.248</westBoundLongitude>
<eastBoundLongitude>179.413</eastBoundLongitude>
<southBoundLatitude>-67.593</southBoundLatitude>
<northBoundLatitude>83.6211</northBoundLatitude>
</EX_GeographicBoundingBox>
<BoundingBox CRS="EPSG:4326" maxx="83.6211" minx="-67.593" maxy="179.413" miny="-176.248"/>
<BoundingBox CRS="EPSG:3857" maxx="1.99721e+07" minx="-1.96199e+07" maxy="1.84159e+07" miny="-1.03271e+07"/>
<Style>
<Name>default</Name>
<Title>default</Title>
<LegendURL>
<Format>image/png</Format>
<OnlineResource xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http:?&amp;&amp;SERVICE=WMS&amp;VERSION=1.3&amp;REQUEST=GetLegendGraphic&amp;LAYER=Country&amp;FORMAT=image/png&amp;STYLE=default"/>
</LegendURL>
</Style>
<Style>
<Name>origin</Name>
<Title>origin</Title>
<LegendURL>
<Format>image/png</Format>
<OnlineResource xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http:?&amp;&amp;SERVICE=WMS&amp;VERSION=1.3&amp;REQUEST=GetLegendGraphic&amp;LAYER=Country&amp;FORMAT=image/png&amp;STYLE=origin"/>
</LegendURL>
</Style>
<Style>
<Name>test2</Name>
<Title>test2</Title>
<LegendURL>
<Format>image/png</Format>
<OnlineResource xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http:?&amp;&amp;SERVICE=WMS&amp;VERSION=1.3&amp;REQUEST=GetLegendGraphic&amp;LAYER=Country&amp;FORMAT=image/png&amp;STYLE=test2"/>
</LegendURL>
</Style>
</Layer>
<Layer queryable="1">
<Name>Country_Labels</Name>
<Title>Country_Labels</Title>
<CRS>CRS:84</CRS>
<CRS>EPSG:3857</CRS>
<CRS>EPSG:4326</CRS>
<EX_GeographicBoundingBox>
<westBoundLongitude>-176.248</westBoundLongitude>
<eastBoundLongitude>179.413</eastBoundLongitude>
<southBoundLatitude>-67.593</southBoundLatitude>
<northBoundLatitude>83.6211</northBoundLatitude>
</EX_GeographicBoundingBox>
<BoundingBox CRS="EPSG:4326" maxx="83.6211" minx="-67.593" maxy="179.413" miny="-176.248"/>
<BoundingBox CRS="EPSG:3857" maxx="1.99721e+07" minx="-1.96199e+07" maxy="1.84159e+07" miny="-1.03271e+07"/>
<Style>
<Name>default</Name>
<Title>default</Title>
<LegendURL>
<Format>image/png</Format>
<OnlineResource xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http:?&amp;&amp;SERVICE=WMS&amp;VERSION=1.3&amp;REQUEST=GetLegendGraphic&amp;LAYER=Country_Labels&amp;FORMAT=image/png&amp;STYLE=default"/>
</LegendURL>
</Style>
<Style>
<Name>custom</Name>
<Title>custom</Title>
<LegendURL>
<Format>image/png</Format>
<OnlineResource xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http:?&amp;&amp;SERVICE=WMS&amp;VERSION=1.3&amp;REQUEST=GetLegendGraphic&amp;LAYER=Country_Labels&amp;FORMAT=image/png&amp;STYLE=custom"/>
</LegendURL>
</Style>
</Layer>
</Layer>
</Capability>
</WMS_Capabilities>

0 comments on commit 5d9b460

Please sign in to comment.