25
25
parts = keyvalue .split ("=" )
26
26
WMS_ACCESSS_KEY [parts [0 ]]= parts [1 ]
27
27
28
+ WEIGHT_GET_CAPABILITIES = int (os .getenv ('WEIGHT_GET_CAPABILITIES' , "1" ))
29
+ WEIGHT_GET_LEGEND_GRAPHIC = int (os .getenv ('WEIGHT_GET_LEGEND_GRAPHIC' , "2" ))
30
+ WEIGHT_GET_MAP = int (os .getenv ('WEIGHT_GET_MAP' , "10" ))
31
+
32
+ verbose = os .getenv ('LOG_VERBOSE' , '0' )
33
+ VERBOSE = False
34
+ if verbose .lower () == "1" :
35
+ VERBOSE = True
36
+
37
+ if VERBOSE :
38
+ def vprint (* args , ** kwargs ):
39
+ print (* args , ** kwargs )
40
+ else :
41
+ vprint = lambda * a , ** k : None # do-nothing function
42
+
28
43
WMS_VERSION_111 = "1.1.1"
29
44
WMS_VERSION_130 = "1.3.0"
30
45
@@ -146,7 +161,18 @@ def getLegendURL( style: xmltodict.OrderedDict):
146
161
return legendUrl
147
162
148
163
149
-
164
+ def formatDateTime (ts :datetime ):
165
+ """
166
+ Formats the datetime according to D.2.1 of WMS Spec: ccyy-mm-ddThh:mm:ss.sssZ
167
+
168
+ A time zone suffix is mandatory if the hours field appears in the time string.
169
+ All times should be expressed in Coordinated Universal Time (UTC), indicated
170
+ by the suffix Z (for "zulu"). When a local time applies, a numeric time zone
171
+ suffix as defined by ISO 8601:2004, 5.3.4.1 shall be used. The absence of any
172
+ suffix at all means local time in an undefined zone, which shall not be
173
+ used in the global network of map servers enabled by this International Standard.
174
+ """
175
+ return ts .isoformat (timespec = 'milliseconds' ).replace ("+00:00" ,"Z" )
150
176
151
177
def enumerateAvailableTimes (text :str ):
152
178
"""
@@ -186,7 +212,7 @@ def enumerateAvailableTimes(text:str):
186
212
except :
187
213
raise Exception ("Error parsing the step in time definition: '{}'" .format (definition ))
188
214
while start <= end :
189
- values .append (datetime . strftime (start , TIME_FORMAT_ISO8601 ))
215
+ values .append ( formatDateTime (start ))
190
216
start = start + delta
191
217
#values["beginning"] = beginning
192
218
#values["end"] = end
@@ -415,8 +441,11 @@ def sendGetCapabilitiesRequest(client:locustclients.HttpSession, wmsversion:str)
415
441
params = getGetCapabilitiesRequest (wmsversion = wmsversion )
416
442
417
443
with client .request ("GET" , "" , params = params , name = "WMS-{}-GetCapabilities" .format (wmsversion ), catch_response = True ) as response :
444
+ url = urllib .parse .unquote (response .url )
418
445
if not response .status_code == 200 :
419
- response .failure ("Request failed with HTTP status code: '{}'\n Response-Content: '{}'" .format (response .status_code , response .content ) )
446
+ errormsg = "Request failed with HTTP status code: '{}'\n Request URL: {}\n Response-Content: '{}'" .format (response .status_code , url , response .content )
447
+ vprint ( "Request failed:\n {}" .format (errormsg ) )
448
+ response .failure (errormsg )
420
449
return
421
450
422
451
if not hasValidGetCapabilitiesResponseType (response .headers ['content-type' ]):
@@ -429,6 +458,7 @@ def sendGetCapabilitiesRequest(client:locustclients.HttpSession, wmsversion:str)
429
458
430
459
try :
431
460
capabilities = xmltodict .parse (response .content )
461
+ #vprint("Request successful: {}".format(url))
432
462
return capabilities
433
463
except :
434
464
response .failure ("Failed to parse GetCapabilities XML" )
@@ -437,22 +467,36 @@ def sendGetCapabilitiesRequest(client:locustclients.HttpSession, wmsversion:str)
437
467
def sendGetMapRequest (client :locustclients .HttpSession , params :dict , wmsversion :str ):
438
468
with client .request ("GET" , "" , params = params , name = "WMS-{}-GetMap" .format (wmsversion ), catch_response = True ) as response :
439
469
if response .status_code == 200 :
470
+ url = urllib .parse .unquote (response .url )
440
471
if response .headers ['content-type' ] != "image/png" :
441
- response .failure ("Expected format 'image/png' but got '{}' instead\n Request params: '{}'\n Response: '{}'\n " .format (response .headers ['content-type' ], params , response .text ) )
472
+ errormsg = "Expected format 'image/png' but got '{}' instead\n Request URL: {}\n Request params: '{}'\n Response: '{}'\n " .format (response .headers ['content-type' ], url , params , response .text )
473
+ vprint ( "Request failed:\n {}" .format (errormsg ) )
474
+ response .failure (errormsg )
442
475
else :
476
+ #vprint("Request successful: {}".format(url))
443
477
response .success ()
444
478
445
479
446
480
def sendGetLegendGraphicRequest (client :locustclients .HttpSession , params :dict , wmsversion :str ):
447
- with client .request ("GET" , "" , params = params , name = "WMS-{}-GetLegendGraphic" .format (wmsversion ), catch_response = True ) as response :
481
+ requestUrl = ""
482
+ if "url" in params :
483
+ # extract request url from params
484
+ requestUrl = params ["url" ]
485
+ params .pop ("url" )
486
+
487
+ with client .request ("GET" , requestUrl , params = params , name = "WMS-{}-GetLegendGraphic" .format (wmsversion ), catch_response = True ) as response :
448
488
#if response.history:
449
489
# #Response was redirected
450
490
# for resp in response.history:
451
491
# print("Redirected with code '{}' to url '{}'".format(resp.status_code,resp.url))
452
492
if response .status_code == 200 :
493
+ url = urllib .parse .unquote (response .url )
453
494
if response .headers ['content-type' ] != "image/png" :
454
- response .failure ("Expected format 'image/png' but got '{}' instead\n Request params: '{}'\n Response: '{}'\n " .format (response .headers ['content-type' ], params , response .text ) )
495
+ errormsg = "Expected format 'image/png' but got '{}' instead\n Request URL: {}\n Request params: '{}'\n Response: '{}'\n " .format (response .headers ['content-type' ], url , params , response .text )
496
+ vprint ( "Request failed:\n {}" .format (errormsg ) )
497
+ response .failure (errormsg )
455
498
else :
499
+ #vprint("Request successful: {}".format(url))
456
500
response .success ()
457
501
458
502
class WebsiteTasks (TaskSet ):
@@ -469,7 +513,7 @@ class WebsiteTasks(TaskSet):
469
513
#def index(self):
470
514
# self.client.get("/")
471
515
472
- @task (1 )
516
+ @task (WEIGHT_GET_CAPABILITIES )
473
517
def get_capa (self ):
474
518
wmsversion = random .choice (WMS_SUPPORTED_VERSIONS )
475
519
capabilities = sendGetCapabilitiesRequest (client = self .client , wmsversion = wmsversion )
@@ -482,7 +526,7 @@ def get_capa(self):
482
526
# for each WMS version
483
527
self .allLayers [wmsversion ] = getAllLayers (capabilities = capabilities , wmsversion = wmsversion )
484
528
485
- @task (2 )
529
+ @task (WEIGHT_GET_LEGEND_GRAPHIC )
486
530
def get_legend_graphic (self ):
487
531
wmsversion = random .choice (WMS_SUPPORTED_VERSIONS )
488
532
if not wmsversion in self .allLayers :
@@ -495,7 +539,7 @@ def get_legend_graphic(self):
495
539
if not getLegendGraphicRequest is None :
496
540
sendGetLegendGraphicRequest (client = self .client , params = getLegendGraphicRequest , wmsversion = wmsversion )
497
541
498
- @task (10 )
542
+ @task (WEIGHT_GET_MAP )
499
543
def get_map (self ):
500
544
wmsversion = random .choice (WMS_SUPPORTED_VERSIONS )
501
545
if not wmsversion in self .allLayers :
0 commit comments