24
24
from qgis .core import QgsRenderChecker
25
25
from PyQt4 .QtCore import QSize
26
26
import tempfile
27
+ import urllib
27
28
28
29
29
30
XML_NS = \
37
38
'xmlns:gml="http://www.opengis.net/gml" ' \
38
39
'xmlns:ows="http://www.opengis.net/ows" '
39
40
40
- WFS_TRANSATION_INSERT = """<?xml version="1.0" encoding="UTF-8"?>
41
+ WFS_TRANSACTION_INSERT = """<?xml version="1.0" encoding="UTF-8"?>
41
42
<wfs:Transaction {xml_ns}>
42
43
<wfs:Insert idgen="GenerateNew">
43
44
<qgs:db_point>
52
53
</wfs:Insert>
53
54
</wfs:Transaction>""" .format (x = 1000 , y = 2000 , name = "test" , color = "{color}" , xml_ns = XML_NS )
54
55
55
- WFS_TRANSATION_UPDATE = """<?xml version="1.0" encoding="UTF-8"?>
56
+ WFS_TRANSACTION_UPDATE = """<?xml version="1.0" encoding="UTF-8"?>
56
57
<wfs:Transaction {xml_ns}>
57
58
<wfs:Update typeName="db_point">
58
59
<wfs:Property>
@@ -80,31 +81,31 @@ class RestrictedAccessControl(QgsAccessControlFilter):
80
81
""" Used to have restriction access """
81
82
82
83
# Be able to deactivate the access control to have a reference point
83
- _acctive = False
84
+ _active = False
84
85
85
86
def __init__ (self , server_iface ):
86
87
super (QgsAccessControlFilter , self ).__init__ (server_iface )
87
88
88
89
def layerFilterExpression (self , layer ):
89
90
""" Return an additional expression filter """
90
91
91
- if not self ._acctive :
92
+ if not self ._active :
92
93
return super (RestrictedAccessControl , self ).layerFilterExpression (layer )
93
94
94
95
return "$id = 1" if layer .name () == "Hello" else None
95
96
96
97
def layerFilterSubsetString (self , layer ):
97
98
""" Return an additional subset string (typically SQL) filter """
98
99
99
- if not self ._acctive :
100
+ if not self ._active :
100
101
return super (RestrictedAccessControl , self ).layerFilterSubsetString (layer )
101
102
102
103
return "pk = 1" if layer .name () == "Hello_SubsetString" else None
103
104
104
105
def layerPermissions (self , layer ):
105
106
""" Return the layer rights """
106
107
107
- if not self ._acctive :
108
+ if not self ._active :
108
109
return super (RestrictedAccessControl , self ).layerPermissions (layer )
109
110
110
111
rh = self .serverInterface ().requestHandler ()
@@ -125,7 +126,7 @@ def layerPermissions(self, layer):
125
126
def authorizedLayerAttributes (self , layer , attributes ):
126
127
""" Return the authorised layer attributes """
127
128
128
- if not self ._acctive :
129
+ if not self ._active :
129
130
return super (RestrictedAccessControl , self ).authorizedLayerAttributes (layer , attributes )
130
131
131
132
if "colour" in attributes :
@@ -135,13 +136,13 @@ def authorizedLayerAttributes(self, layer, attributes):
135
136
def allowToEdit (self , layer , feature ):
136
137
""" Are we authorise to modify the following geometry """
137
138
138
- if not self ._acctive :
139
+ if not self ._active :
139
140
return super (RestrictedAccessControl , self ).allowToEdit (layer , feature )
140
141
141
142
return feature .attribute ("color" ) in ["red" , "yellow" ]
142
143
143
144
def cacheKey (self ):
144
- return "r" if self ._acctive else "f"
145
+ return "r" if self ._active else "f"
145
146
146
147
147
148
server = QgsServer ()
@@ -158,10 +159,11 @@ def setUp(self):
158
159
159
160
copyfile (path .join (self .testdata_path , "helloworld.db" ), path .join (self .testdata_path , "_helloworld.db" ))
160
161
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 ]
163
165
164
- environ [ "QGIS_PROJECT_FILE" ] = path .join (self .testdata_path , "project.qgs" )
166
+ self . projectPath = urllib . quote ( path .join (self .testdata_path , "project.qgs" ) )
165
167
166
168
def tearDown (self ):
167
169
copyfile (path .join (self .testdata_path , "_helloworld.db" ), path .join (self .testdata_path , "helloworld.db" ))
@@ -170,6 +172,7 @@ def tearDown(self):
170
172
171
173
def test_wms_getcapabilities (self ):
172
174
query_string = "&" .join (["%s=%s" % i for i in {
175
+ "MAP" : self .projectPath ,
173
176
"SERVICE" : "WMS" ,
174
177
"VERSION" : "1.1.1" ,
175
178
"REQUEST" : "GetCapabilities"
@@ -193,6 +196,7 @@ def test_wms_getcapabilities(self):
193
196
194
197
def test_wms_describelayer_hello (self ):
195
198
query_string = "&" .join (["%s=%s" % i for i in {
199
+ "MAP" : self .projectPath ,
196
200
"SERVICE" : "WMS" ,
197
201
"VERSION" : "1.1.1" ,
198
202
"REQUEST" : "DescribeLayer" ,
@@ -212,6 +216,7 @@ def test_wms_describelayer_hello(self):
212
216
213
217
def test_wms_describelayer_country (self ):
214
218
query_string = "&" .join (["%s=%s" % i for i in {
219
+ "MAP" : self .projectPath ,
215
220
"SERVICE" : "WMS" ,
216
221
"VERSION" : "1.1.1" ,
217
222
"REQUEST" : "DescribeLayer" ,
@@ -231,6 +236,7 @@ def test_wms_describelayer_country(self):
231
236
232
237
def test_wms_getlegendgraphic_hello (self ):
233
238
query_string = "&" .join (["%s=%s" % i for i in {
239
+ "MAP" : self .projectPath ,
234
240
"SERVICE" : "WMS" ,
235
241
"VERSION" : "1.1.1" ,
236
242
"REQUEST" : "GetLegendGraphic" ,
@@ -246,6 +252,7 @@ def test_wms_getlegendgraphic_hello(self):
246
252
247
253
def test_wms_getlegendgraphic_country (self ):
248
254
query_string = "&" .join (["%s=%s" % i for i in {
255
+ "MAP" : self .projectPath ,
249
256
"SERVICE" : "WMS" ,
250
257
"VERSION" : "1.1.1" ,
251
258
"REQUEST" : "GetLegendGraphic" ,
@@ -267,6 +274,7 @@ def test_wms_getlegendgraphic_country(self):
267
274
268
275
def test_wms_getmap (self ):
269
276
query_string = "&" .join (["%s=%s" % i for i in {
277
+ "MAP" : self .projectPath ,
270
278
"SERVICE" : "WMS" ,
271
279
"VERSION" : "1.1.1" ,
272
280
"REQUEST" : "GetMap" ,
@@ -283,6 +291,7 @@ def test_wms_getmap(self):
283
291
self ._img_diff_error (response , headers , "WMS_GetMap" )
284
292
285
293
query_string = "&" .join (["%s=%s" % i for i in {
294
+ "MAP" : self .projectPath ,
286
295
"SERVICE" : "WMS" ,
287
296
"VERSION" : "1.1.1" ,
288
297
"REQUEST" : "GetMap" ,
@@ -298,6 +307,7 @@ def test_wms_getmap(self):
298
307
self ._img_diff_error (response , headers , "Restricted_WMS_GetMap" )
299
308
300
309
query_string = "&" .join (["%s=%s" % i for i in {
310
+ "MAP" : self .projectPath ,
301
311
"SERVICE" : "WMS" ,
302
312
"VERSION" : "1.1.1" ,
303
313
"REQUEST" : "GetMap" ,
@@ -320,6 +330,7 @@ def test_wms_getmap(self):
320
330
321
331
def test_wms_getfeatureinfo_hello (self ):
322
332
query_string = "&" .join (["%s=%s" % i for i in {
333
+ "MAP" : self .projectPath ,
323
334
"SERVICE" : "WMS" ,
324
335
"VERSION" : "1.1.1" ,
325
336
"REQUEST" : "GetFeatureInfo" ,
@@ -358,6 +369,7 @@ def test_wms_getfeatureinfo_hello(self):
358
369
359
370
def test_wms_getfeatureinfo_hello2 (self ):
360
371
query_string = "&" .join (["%s=%s" % i for i in {
372
+ "MAP" : self .projectPath ,
361
373
"SERVICE" : "WMS" ,
362
374
"VERSION" : "1.1.1" ,
363
375
"REQUEST" : "GetFeatureInfo" ,
@@ -387,6 +399,7 @@ def test_wms_getfeatureinfo_hello2(self):
387
399
388
400
def test_wms_getfeatureinfo_country (self ):
389
401
query_string = "&" .join (["%s=%s" % i for i in {
402
+ "MAP" : self .projectPath ,
390
403
"SERVICE" : "WMS" ,
391
404
"VERSION" : "1.1.1" ,
392
405
"REQUEST" : "GetFeatureInfo" ,
@@ -418,6 +431,7 @@ def test_wms_getfeatureinfo_country(self):
418
431
419
432
def test_wfs_getcapabilities (self ):
420
433
query_string = "&" .join (["%s=%s" % i for i in {
434
+ "MAP" : self .projectPath ,
421
435
"SERVICE" : "WFS" ,
422
436
"VERSION" : "1.1.0" ,
423
437
"REQUEST" : "GetCapabilities"
@@ -441,6 +455,7 @@ def test_wfs_getcapabilities(self):
441
455
442
456
def test_wfs_describefeaturetype_hello (self ):
443
457
query_string = "&" .join (["%s=%s" % i for i in {
458
+ "MAP" : self .projectPath ,
444
459
"SERVICE" : "WFS" ,
445
460
"VERSION" : "1.1.0" ,
446
461
"REQUEST" : "DescribeFeatureType" ,
@@ -459,6 +474,7 @@ def test_wfs_describefeaturetype_hello(self):
459
474
460
475
def test_wfs_describefeaturetype_country (self ):
461
476
query_string = "&" .join (["%s=%s" % i for i in {
477
+ "MAP" : self .projectPath ,
462
478
"SERVICE" : "WFS" ,
463
479
"VERSION" : "1.1.0" ,
464
480
"REQUEST" : "DescribeFeatureType" ,
@@ -546,6 +562,7 @@ def test_wfs_getfeature_country(self):
546
562
547
563
def test_wcs_getcapabilities (self ):
548
564
query_string = "&" .join (["%s=%s" % i for i in {
565
+ "MAP" : self .projectPath ,
549
566
"SERVICE" : "WCS" ,
550
567
"VERSION" : "1.0.0" ,
551
568
"REQUEST" : "GetCapabilities" ,
@@ -562,6 +579,7 @@ def test_wcs_getcapabilities(self):
562
579
"No dem layer in WCS/GetCapabilities\n %s" % response )
563
580
564
581
query_string = "&" .join (["%s=%s" % i for i in {
582
+ "MAP" : self .projectPath ,
565
583
"SERVICE" : "WCS" ,
566
584
"VERSION" : "1.0.0" ,
567
585
"REQUEST" : "GetCapabilities" ,
@@ -575,6 +593,7 @@ def test_wcs_getcapabilities(self):
575
593
576
594
def test_wcs_describecoverage (self ):
577
595
query_string = "&" .join (["%s=%s" % i for i in {
596
+ "MAP" : self .projectPath ,
578
597
"SERVICE" : "WCS" ,
579
598
"VERSION" : "1.0.0" ,
580
599
"REQUEST" : "DescribeCoverage" ,
@@ -592,6 +611,7 @@ def test_wcs_describecoverage(self):
592
611
"No dem layer in DescribeCoverage\n %s" % response )
593
612
594
613
query_string = "&" .join (["%s=%s" % i for i in {
614
+ "MAP" : self .projectPath ,
595
615
"SERVICE" : "WCS" ,
596
616
"VERSION" : "1.0.0" ,
597
617
"REQUEST" : "DescribeCoverage" ,
@@ -606,6 +626,7 @@ def test_wcs_describecoverage(self):
606
626
607
627
def test_wcs_getcoverage (self ):
608
628
query_string = "&" .join (["%s=%s" % i for i in {
629
+ "MAP" : self .projectPath ,
609
630
"SERVICE" : "WCS" ,
610
631
"VERSION" : "1.0.0" ,
611
632
"REQUEST" : "GetCoverage" ,
@@ -634,6 +655,7 @@ def test_wcs_getcoverage(self):
634
655
"Image for GetCoverage is wrong" )
635
656
636
657
query_string = "&" .join (["%s=%s" % i for i in {
658
+ "MAP" : self .projectPath ,
637
659
"SERVICE" : "WCS" ,
638
660
"VERSION" : "1.0.0" ,
639
661
"REQUEST" : "GetCoverage" ,
@@ -658,7 +680,7 @@ def test_wcs_getcoverage(self):
658
680
# # WFS/Transactions # #
659
681
660
682
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 )
662
684
self ._test_colors ({1 : "blue" })
663
685
664
686
response , headers = self ._post_fullaccess (data .format (color = "red" ))
@@ -698,7 +720,7 @@ def test_wfstransaction_insert(self):
698
720
self ._test_colors ({3 : "yellow" })
699
721
700
722
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 )
702
724
self ._test_colors ({1 : "blue" })
703
725
704
726
response , headers = self ._post_restricted (data .format (color = "yellow" ))
@@ -774,7 +796,7 @@ def test_wfstransaction_delete_restricted(self):
774
796
'<ServiceException code="Security">Feature modify permission denied</ServiceException>' ) != - 1 ,
775
797
"WFS/Transactions Delete succeed\n %s" % response )
776
798
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 )
778
800
response , headers = self ._post_fullaccess (data_update )
779
801
self ._test_colors ({1 : "red" })
780
802
@@ -800,6 +822,7 @@ def test_wfstransaction_delete_restricted(self):
800
822
# # WMS # # WMS # # WMS # #
801
823
def test_wms_getmap_subsetstring (self ):
802
824
query_string = "&" .join (["%s=%s" % i for i in {
825
+ "MAP" : self .projectPath ,
803
826
"SERVICE" : "WMS" ,
804
827
"VERSION" : "1.1.1" ,
805
828
"REQUEST" : "GetMap" ,
@@ -816,6 +839,7 @@ def test_wms_getmap_subsetstring(self):
816
839
self ._img_diff_error (response , headers , "WMS_GetMap" )
817
840
818
841
query_string = "&" .join (["%s=%s" % i for i in {
842
+ "MAP" : self .projectPath ,
819
843
"SERVICE" : "WMS" ,
820
844
"VERSION" : "1.1.1" ,
821
845
"REQUEST" : "GetMap" ,
@@ -949,7 +973,7 @@ def test_wfs_getfeature_subsetstring2(self):
949
973
"Unexpected result in GetFeature\n %s" % response )
950
974
951
975
def _handle_request (self , restricted , * args ):
952
- accesscontrol ._acctive = restricted
976
+ accesscontrol ._active = restricted
953
977
result = self ._result (server .handleRequest (* args ))
954
978
return result
955
979
@@ -1027,8 +1051,10 @@ def _geo_img_diff(self, image_1, image_2):
1027
1051
with open (path .join (tempfile .gettempdir (), image_2 ), "w" ) as f :
1028
1052
f .write (image_1 )
1029
1053
image_1 = gdal .Open (path .join (tempfile .gettempdir (), image_2 ), GA_ReadOnly )
1054
+ assert image_1 , "No output image written: " + image_2
1030
1055
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
1032
1058
1033
1059
if image_1 .RasterXSize != image_2 .RasterXSize :
1034
1060
return 1000 # wrong size
0 commit comments