Skip to content
Permalink
Browse files

#286 handle JSON error msg in ESRI FS Probe plus add tests (#287)

  • Loading branch information...
justb4 committed Oct 1, 2019
1 parent deb61dc commit 3d356adce5edf5b6157880ac726c7d8673b7e94e
Showing with 50 additions and 7 deletions.
  1. +28 −5 GeoHealthCheck/plugins/probe/esrifs.py
  2. +21 −1 tests/data/fixtures.json
  3. +1 −1 tests/test_resources.py
@@ -45,6 +45,27 @@ def get_request_headers(self):
headers['X-Esri-Authorization'] = headers['Authorization']
return headers

def perform_esrifs_get_request(self, url):
response = self.perform_get_request(url).json()
error_msg = 'code=%d message=%s'
# May have error like:
# {
# "error" :
# {
# "code" : 499,
# "message" : "Token Required",
# "messageCode" : "GWM_0003",
# "details" : [
# "Token Required"
# ]
# }
# }
if 'error' in response:
err = response['error']
raise Exception(error_msg % (err['code'], err['message']))

return response

def perform_request(self):
"""
Perform the drilldown.
@@ -73,7 +94,7 @@ def perform_request(self):
result.start()
layers = []
try:
fs_caps = self.perform_get_request(req_tpl['fs_caps']).json()
fs_caps = self.perform_esrifs_get_request(req_tpl['fs_caps'])
for attr in ['currentVersion', 'layers']:
val = fs_caps.get(attr, None)
if val is None:
@@ -94,6 +115,8 @@ def perform_request(self):
return

# 2. Test each Layer Capabilities
result = Result(True, 'Test Layer Capabilities')
result.start()
layer_ids = []
layer_caps = []
try:
@@ -102,8 +125,8 @@ def perform_request(self):
layer_ids.append(layer['id'])

for layer_id in layer_ids:
layer_caps.append(self.perform_get_request(
req_tpl['layer_caps'] % layer_id).json())
layer_caps.append(self.perform_esrifs_get_request(
req_tpl['layer_caps'] % layer_id))

except Exception as err:
result.set(False, str(err))
@@ -124,8 +147,8 @@ def perform_request(self):
for layer_id in layer_ids:

try:
features = self.perform_get_request(
req_tpl['get_features'] % layer_id).json()
features = self.perform_esrifs_get_request(
req_tpl['get_features'] % layer_id)
obj_id_field_name = features['objectIdFieldName']
features = features['features']
if len(features) == 0:
@@ -11,7 +11,8 @@
"ows": "ows",
"tiling": "tiling",
"pdok": "pdok",
"ogc": "ogc"
"ogc": "ogc",
"esri": "esri"
},
"resources": {
"PDOK BAG WMS": {
@@ -95,7 +96,18 @@
"tags": [
"ogc"
]
},
"ESRI FEATURESERVER": {
"owner": "admin",
"resource_type": "ESRI:FS",
"active": true,
"title": "ESRI ArcGIS FeatureServer (FS)",
"url": "https://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Fire/Sheep/FeatureServer",
"tags": [
"esri"
]
}

},
"probe_vars": {
"PDOK BAG WMS - GetCaps": {
@@ -223,7 +235,15 @@
"resource": "PYGEOAPI FEATURES",
"probe_class": "GeoHealthCheck.plugins.probe.wfs3.WFS3OpenAPIValidator",
"parameters": {}
},
"ESRIFS - Drilldown": {
"resource": "ESRI FEATURESERVER",
"probe_class": "GeoHealthCheck.plugins.probe.esrifs.ESRIFSDrilldown",
"parameters": {
"drilldown_level": "full"
}
}

},
"check_vars": {
"PDOK BAG WMS - GetCaps - XML Parse": {
@@ -65,7 +65,7 @@ def tearDown(self):
def testResourcesPresent(self):
resources = Resource.query.all()

self.assertEqual(len(resources), 8)
self.assertEqual(len(resources), 9)

def testRunResoures(self):
# Do the whole healthcheck for all Resources for now

0 comments on commit 3d356ad

Please sign in to comment.
You can’t perform that action at this time.