Skip to content

Commit b10e708

Browse files
committedNov 23, 2015
some fixes to the server access control tests on windows
1 parent 7bcc935 commit b10e708

File tree

1 file changed

+43
-17
lines changed

1 file changed

+43
-17
lines changed
 

‎tests/src/python/test_qgsserver_accesscontrol.py

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from qgis.core import QgsRenderChecker
2525
from PyQt4.QtCore import QSize
2626
import tempfile
27+
import urllib
2728

2829

2930
XML_NS = \
@@ -37,7 +38,7 @@
3738
'xmlns:gml="http://www.opengis.net/gml" ' \
3839
'xmlns:ows="http://www.opengis.net/ows" '
3940

40-
WFS_TRANSATION_INSERT = """<?xml version="1.0" encoding="UTF-8"?>
41+
WFS_TRANSACTION_INSERT = """<?xml version="1.0" encoding="UTF-8"?>
4142
<wfs:Transaction {xml_ns}>
4243
<wfs:Insert idgen="GenerateNew">
4344
<qgs:db_point>
@@ -52,7 +53,7 @@
5253
</wfs:Insert>
5354
</wfs:Transaction>""".format(x=1000, y=2000, name="test", color="{color}", xml_ns=XML_NS)
5455

55-
WFS_TRANSATION_UPDATE = """<?xml version="1.0" encoding="UTF-8"?>
56+
WFS_TRANSACTION_UPDATE = """<?xml version="1.0" encoding="UTF-8"?>
5657
<wfs:Transaction {xml_ns}>
5758
<wfs:Update typeName="db_point">
5859
<wfs:Property>
@@ -80,31 +81,31 @@ class RestrictedAccessControl(QgsAccessControlFilter):
8081
""" Used to have restriction access """
8182

8283
# Be able to deactivate the access control to have a reference point
83-
_acctive = False
84+
_active = False
8485

8586
def __init__(self, server_iface):
8687
super(QgsAccessControlFilter, self).__init__(server_iface)
8788

8889
def layerFilterExpression(self, layer):
8990
""" Return an additional expression filter """
9091

91-
if not self._acctive:
92+
if not self._active:
9293
return super(RestrictedAccessControl, self).layerFilterExpression(layer)
9394

9495
return "$id = 1" if layer.name() == "Hello" else None
9596

9697
def layerFilterSubsetString(self, layer):
9798
""" Return an additional subset string (typically SQL) filter """
9899

99-
if not self._acctive:
100+
if not self._active:
100101
return super(RestrictedAccessControl, self).layerFilterSubsetString(layer)
101102

102103
return "pk = 1" if layer.name() == "Hello_SubsetString" else None
103104

104105
def layerPermissions(self, layer):
105106
""" Return the layer rights """
106107

107-
if not self._acctive:
108+
if not self._active:
108109
return super(RestrictedAccessControl, self).layerPermissions(layer)
109110

110111
rh = self.serverInterface().requestHandler()
@@ -125,7 +126,7 @@ def layerPermissions(self, layer):
125126
def authorizedLayerAttributes(self, layer, attributes):
126127
""" Return the authorised layer attributes """
127128

128-
if not self._acctive:
129+
if not self._active:
129130
return super(RestrictedAccessControl, self).authorizedLayerAttributes(layer, attributes)
130131

131132
if "colour" in attributes:
@@ -135,13 +136,13 @@ def authorizedLayerAttributes(self, layer, attributes):
135136
def allowToEdit(self, layer, feature):
136137
""" Are we authorise to modify the following geometry """
137138

138-
if not self._acctive:
139+
if not self._active:
139140
return super(RestrictedAccessControl, self).allowToEdit(layer, feature)
140141

141142
return feature.attribute("color") in ["red", "yellow"]
142143

143144
def cacheKey(self):
144-
return "r" if self._acctive else "f"
145+
return "r" if self._active else "f"
145146

146147

147148
server = QgsServer()
@@ -158,10 +159,11 @@ def setUp(self):
158159

159160
copyfile(path.join(self.testdata_path, "helloworld.db"), path.join(self.testdata_path, "_helloworld.db"))
160161

161-
if "QUERY_STRING" in environ:
162-
del environ["QUERY_STRING"]
162+
for k in ["QUERY_STRING", "QGIS_PROJECT_FILE"]:
163+
if k in environ:
164+
del environ[k]
163165

164-
environ["QGIS_PROJECT_FILE"] = path.join(self.testdata_path, "project.qgs")
166+
self.projectPath = urllib.quote( path.join(self.testdata_path, "project.qgs") )
165167

166168
def tearDown(self):
167169
copyfile(path.join(self.testdata_path, "_helloworld.db"), path.join(self.testdata_path, "helloworld.db"))
@@ -170,6 +172,7 @@ def tearDown(self):
170172

171173
def test_wms_getcapabilities(self):
172174
query_string = "&".join(["%s=%s" % i for i in {
175+
"MAP": self.projectPath,
173176
"SERVICE": "WMS",
174177
"VERSION": "1.1.1",
175178
"REQUEST": "GetCapabilities"
@@ -193,6 +196,7 @@ def test_wms_getcapabilities(self):
193196

194197
def test_wms_describelayer_hello(self):
195198
query_string = "&".join(["%s=%s" % i for i in {
199+
"MAP": self.projectPath,
196200
"SERVICE": "WMS",
197201
"VERSION": "1.1.1",
198202
"REQUEST": "DescribeLayer",
@@ -212,6 +216,7 @@ def test_wms_describelayer_hello(self):
212216

213217
def test_wms_describelayer_country(self):
214218
query_string = "&".join(["%s=%s" % i for i in {
219+
"MAP": self.projectPath,
215220
"SERVICE": "WMS",
216221
"VERSION": "1.1.1",
217222
"REQUEST": "DescribeLayer",
@@ -231,6 +236,7 @@ def test_wms_describelayer_country(self):
231236

232237
def test_wms_getlegendgraphic_hello(self):
233238
query_string = "&".join(["%s=%s" % i for i in {
239+
"MAP": self.projectPath,
234240
"SERVICE": "WMS",
235241
"VERSION": "1.1.1",
236242
"REQUEST": "GetLegendGraphic",
@@ -246,6 +252,7 @@ def test_wms_getlegendgraphic_hello(self):
246252

247253
def test_wms_getlegendgraphic_country(self):
248254
query_string = "&".join(["%s=%s" % i for i in {
255+
"MAP": self.projectPath,
249256
"SERVICE": "WMS",
250257
"VERSION": "1.1.1",
251258
"REQUEST": "GetLegendGraphic",
@@ -267,6 +274,7 @@ def test_wms_getlegendgraphic_country(self):
267274

268275
def test_wms_getmap(self):
269276
query_string = "&".join(["%s=%s" % i for i in {
277+
"MAP": self.projectPath,
270278
"SERVICE": "WMS",
271279
"VERSION": "1.1.1",
272280
"REQUEST": "GetMap",
@@ -283,6 +291,7 @@ def test_wms_getmap(self):
283291
self._img_diff_error(response, headers, "WMS_GetMap")
284292

285293
query_string = "&".join(["%s=%s" % i for i in {
294+
"MAP": self.projectPath,
286295
"SERVICE": "WMS",
287296
"VERSION": "1.1.1",
288297
"REQUEST": "GetMap",
@@ -298,6 +307,7 @@ def test_wms_getmap(self):
298307
self._img_diff_error(response, headers, "Restricted_WMS_GetMap")
299308

300309
query_string = "&".join(["%s=%s" % i for i in {
310+
"MAP": self.projectPath,
301311
"SERVICE": "WMS",
302312
"VERSION": "1.1.1",
303313
"REQUEST": "GetMap",
@@ -320,6 +330,7 @@ def test_wms_getmap(self):
320330

321331
def test_wms_getfeatureinfo_hello(self):
322332
query_string = "&".join(["%s=%s" % i for i in {
333+
"MAP": self.projectPath,
323334
"SERVICE": "WMS",
324335
"VERSION": "1.1.1",
325336
"REQUEST": "GetFeatureInfo",
@@ -358,6 +369,7 @@ def test_wms_getfeatureinfo_hello(self):
358369

359370
def test_wms_getfeatureinfo_hello2(self):
360371
query_string = "&".join(["%s=%s" % i for i in {
372+
"MAP": self.projectPath,
361373
"SERVICE": "WMS",
362374
"VERSION": "1.1.1",
363375
"REQUEST": "GetFeatureInfo",
@@ -387,6 +399,7 @@ def test_wms_getfeatureinfo_hello2(self):
387399

388400
def test_wms_getfeatureinfo_country(self):
389401
query_string = "&".join(["%s=%s" % i for i in {
402+
"MAP": self.projectPath,
390403
"SERVICE": "WMS",
391404
"VERSION": "1.1.1",
392405
"REQUEST": "GetFeatureInfo",
@@ -418,6 +431,7 @@ def test_wms_getfeatureinfo_country(self):
418431

419432
def test_wfs_getcapabilities(self):
420433
query_string = "&".join(["%s=%s" % i for i in {
434+
"MAP": self.projectPath,
421435
"SERVICE": "WFS",
422436
"VERSION": "1.1.0",
423437
"REQUEST": "GetCapabilities"
@@ -441,6 +455,7 @@ def test_wfs_getcapabilities(self):
441455

442456
def test_wfs_describefeaturetype_hello(self):
443457
query_string = "&".join(["%s=%s" % i for i in {
458+
"MAP": self.projectPath,
444459
"SERVICE": "WFS",
445460
"VERSION": "1.1.0",
446461
"REQUEST": "DescribeFeatureType",
@@ -459,6 +474,7 @@ def test_wfs_describefeaturetype_hello(self):
459474

460475
def test_wfs_describefeaturetype_country(self):
461476
query_string = "&".join(["%s=%s" % i for i in {
477+
"MAP": self.projectPath,
462478
"SERVICE": "WFS",
463479
"VERSION": "1.1.0",
464480
"REQUEST": "DescribeFeatureType",
@@ -546,6 +562,7 @@ def test_wfs_getfeature_country(self):
546562

547563
def test_wcs_getcapabilities(self):
548564
query_string = "&".join(["%s=%s" % i for i in {
565+
"MAP": self.projectPath,
549566
"SERVICE": "WCS",
550567
"VERSION": "1.0.0",
551568
"REQUEST": "GetCapabilities",
@@ -562,6 +579,7 @@ def test_wcs_getcapabilities(self):
562579
"No dem layer in WCS/GetCapabilities\n%s" % response)
563580

564581
query_string = "&".join(["%s=%s" % i for i in {
582+
"MAP": self.projectPath,
565583
"SERVICE": "WCS",
566584
"VERSION": "1.0.0",
567585
"REQUEST": "GetCapabilities",
@@ -575,6 +593,7 @@ def test_wcs_getcapabilities(self):
575593

576594
def test_wcs_describecoverage(self):
577595
query_string = "&".join(["%s=%s" % i for i in {
596+
"MAP": self.projectPath,
578597
"SERVICE": "WCS",
579598
"VERSION": "1.0.0",
580599
"REQUEST": "DescribeCoverage",
@@ -592,6 +611,7 @@ def test_wcs_describecoverage(self):
592611
"No dem layer in DescribeCoverage\n%s" % response)
593612

594613
query_string = "&".join(["%s=%s" % i for i in {
614+
"MAP": self.projectPath,
595615
"SERVICE": "WCS",
596616
"VERSION": "1.0.0",
597617
"REQUEST": "DescribeCoverage",
@@ -606,6 +626,7 @@ def test_wcs_describecoverage(self):
606626

607627
def test_wcs_getcoverage(self):
608628
query_string = "&".join(["%s=%s" % i for i in {
629+
"MAP": self.projectPath,
609630
"SERVICE": "WCS",
610631
"VERSION": "1.0.0",
611632
"REQUEST": "GetCoverage",
@@ -634,6 +655,7 @@ def test_wcs_getcoverage(self):
634655
"Image for GetCoverage is wrong")
635656

636657
query_string = "&".join(["%s=%s" % i for i in {
658+
"MAP": self.projectPath,
637659
"SERVICE": "WCS",
638660
"VERSION": "1.0.0",
639661
"REQUEST": "GetCoverage",
@@ -658,7 +680,7 @@ def test_wcs_getcoverage(self):
658680
# # WFS/Transactions # #
659681

660682
def test_wfstransaction_insert(self):
661-
data = WFS_TRANSATION_INSERT.format(x=1000, y=2000, name="test", color="{color}", xml_ns=XML_NS)
683+
data = WFS_TRANSACTION_INSERT.format(x=1000, y=2000, name="test", color="{color}", xml_ns=XML_NS)
662684
self._test_colors({1: "blue"})
663685

664686
response, headers = self._post_fullaccess(data.format(color="red"))
@@ -698,7 +720,7 @@ def test_wfstransaction_insert(self):
698720
self._test_colors({3: "yellow"})
699721

700722
def test_wfstransaction_update(self):
701-
data = WFS_TRANSATION_UPDATE.format(id="1", color="{color}", xml_ns=XML_NS)
723+
data = WFS_TRANSACTION_UPDATE.format(id="1", color="{color}", xml_ns=XML_NS)
702724
self._test_colors({1: "blue"})
703725

704726
response, headers = self._post_restricted(data.format(color="yellow"))
@@ -774,7 +796,7 @@ def test_wfstransaction_delete_restricted(self):
774796
'<ServiceException code="Security">Feature modify permission denied</ServiceException>') != -1,
775797
"WFS/Transactions Delete succeed\n%s" % response)
776798

777-
data_update = WFS_TRANSATION_UPDATE.format(id="1", color="red", xml_ns=XML_NS)
799+
data_update = WFS_TRANSACTION_UPDATE.format(id="1", color="red", xml_ns=XML_NS)
778800
response, headers = self._post_fullaccess(data_update)
779801
self._test_colors({1: "red"})
780802

@@ -800,6 +822,7 @@ def test_wfstransaction_delete_restricted(self):
800822
# # WMS # # WMS # # WMS # #
801823
def test_wms_getmap_subsetstring(self):
802824
query_string = "&".join(["%s=%s" % i for i in {
825+
"MAP": self.projectPath,
803826
"SERVICE": "WMS",
804827
"VERSION": "1.1.1",
805828
"REQUEST": "GetMap",
@@ -816,6 +839,7 @@ def test_wms_getmap_subsetstring(self):
816839
self._img_diff_error(response, headers, "WMS_GetMap")
817840

818841
query_string = "&".join(["%s=%s" % i for i in {
842+
"MAP": self.projectPath,
819843
"SERVICE": "WMS",
820844
"VERSION": "1.1.1",
821845
"REQUEST": "GetMap",
@@ -949,7 +973,7 @@ def test_wfs_getfeature_subsetstring2(self):
949973
"Unexpected result in GetFeature\n%s" % response)
950974

951975
def _handle_request(self, restricted, *args):
952-
accesscontrol._acctive = restricted
976+
accesscontrol._active = restricted
953977
result = self._result(server.handleRequest(*args))
954978
return result
955979

@@ -1027,8 +1051,10 @@ def _geo_img_diff(self, image_1, image_2):
10271051
with open(path.join(tempfile.gettempdir(), image_2), "w") as f:
10281052
f.write(image_1)
10291053
image_1 = gdal.Open(path.join(tempfile.gettempdir(), image_2), GA_ReadOnly)
1054+
assert image_1, "No output image written: " + image_2
10301055

1031-
image_2 = gdal.Open(self.testdata_path + "/results/" + image_2, GA_ReadOnly)
1056+
image_2 = gdal.Open(path.join(self.testdata_path, "results", image_2), GA_ReadOnly)
1057+
assert image_1, "No expected image found:" + image_2
10321058

10331059
if image_1.RasterXSize != image_2.RasterXSize:
10341060
return 1000 # wrong size

0 commit comments

Comments
 (0)
Please sign in to comment.