Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Oct 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 28 additions & 5 deletions GeoHealthCheck/plugins/probe/esrifs.py
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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))
Expand All @@ -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:
Expand Down
22 changes: 21 additions & 1 deletion tests/data/fixtures.json
Expand Up @@ -11,7 +11,8 @@
"ows": "ows",
"tiling": "tiling",
"pdok": "pdok",
"ogc": "ogc"
"ogc": "ogc",
"esri": "esri"
},
"resources": {
"PDOK BAG WMS": {
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_resources.py
Expand Up @@ -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
Expand Down