1
- # -*- coding: utf-8 -*-
2
1
"""
3
2
Tests for auth manager WMS/WFS using QGIS Server through OAuth2
4
3
enabled qgis_wrapped_server.py.
@@ -167,8 +166,8 @@ def setUpClass(cls):
167
166
assert cls .port != 0
168
167
169
168
# We need a valid port before we setup the oauth configuration
170
- cls .token_uri = '%s ://%s:%s/token' % ( cls .protocol , cls . hostname , cls .port )
171
- cls .refresh_token_uri = '%s ://%s:%s/refresh' % ( cls .protocol , cls . hostname , cls .port )
169
+ cls .token_uri = f' { cls . protocol } ://{ cls .hostname } : { cls .port } /token'
170
+ cls .refresh_token_uri = f' { cls . protocol } ://{ cls .hostname } : { cls .port } /refresh'
172
171
# Need a random authcfg or the cache will bites us back!
173
172
cls .authcfg_id = setup_oauth (cls .username , cls .password , cls .token_uri , cls .refresh_token_uri , str (random .randint (0 , 10000000 )))
174
173
# This is to test wrong credentials
@@ -178,7 +177,7 @@ def setUpClass(cls):
178
177
assert cls .auth_config .isValid ()
179
178
180
179
# Wait for the server process to start
181
- assert waitServer ('%s ://%s:%s' % ( cls .protocol , cls . hostname , cls .port )), "Server is not responding! %s ://%s:%s" % ( cls .protocol , cls . hostname , cls .port )
180
+ assert waitServer (f' { cls . protocol } ://{ cls .hostname } : { cls .port } ' ), f "Server is not responding! { cls . protocol } ://{ cls .hostname } : { cls .port } "
182
181
183
182
@classmethod
184
183
def tearDownClass (cls ):
@@ -205,13 +204,13 @@ def _getWFSLayer(cls, type_name, layer_name=None, authcfg=None):
205
204
parms = {
206
205
'srsname' : 'EPSG:4326' ,
207
206
'typename' : type_name ,
208
- 'url' : '%s ://%s:%s/?map=%s' % ( cls .protocol , cls . hostname , cls .port , cls .project_path ) ,
207
+ 'url' : f' { cls . protocol } ://{ cls .hostname } : { cls .port } /?map= { cls .project_path } ' ,
209
208
'version' : 'auto' ,
210
209
'table' : '' ,
211
210
}
212
211
if authcfg is not None :
213
212
parms .update ({'authcfg' : authcfg })
214
- uri = ' ' .join ([("%s='%s'" % ( k , v ) ) for k , v in list (parms .items ())])
213
+ uri = ' ' .join ([(f" { k } =' { v } '" ) for k , v in list (parms .items ())])
215
214
wfs_layer = QgsVectorLayer (uri , layer_name , 'WFS' )
216
215
return wfs_layer
217
216
@@ -224,7 +223,7 @@ def _getWMSLayer(cls, layers, layer_name=None, authcfg=None):
224
223
layer_name = 'wms_' + layers .replace (',' , '' )
225
224
parms = {
226
225
'crs' : 'EPSG:4326' ,
227
- 'url' : '%s ://%s:%s/?map=%s' % ( cls .protocol , cls . hostname , cls .port , cls .project_path ) ,
226
+ 'url' : f' { cls . protocol } ://{ cls .hostname } : { cls .port } /?map= { cls .project_path } ' ,
228
227
'format' : 'image/png' ,
229
228
# This is needed because of a really weird implementation in QGIS Server, that
230
229
# replaces _ in the the real layer name with spaces
@@ -235,7 +234,7 @@ def _getWMSLayer(cls, layers, layer_name=None, authcfg=None):
235
234
}
236
235
if authcfg is not None :
237
236
parms .update ({'authcfg' : authcfg })
238
- uri = '&' .join ([("%s=%s" % (k , v .replace ('=' , '%3D' ))) for k , v in list (parms .items ())])
237
+ uri = '&' .join ([("{}={}" . format (k , v .replace ('=' , '%3D' ))) for k , v in list (parms .items ())])
239
238
wms_layer = QgsRasterLayer (uri , layer_name , 'wms' )
240
239
return wms_layer
241
240
0 commit comments