Commit 7a526712 authored by Vincent Fazio's avatar Vincent Fazio Committed by Vincent Fazio
Browse files

NVCL-58 Add parameter testing to asud

parent 4dfbeace
Pipeline #221957832 passed with stages
in 3 minutes and 34 seconds
......@@ -8,7 +8,8 @@ import yaml
# A very rough script to demonstrate 'nvcl_kit'
# NB: requires 'pyyaml' - install via 'pip3 install pyyaml'
# Provider list. Format is (WFS service URL, NVCL service URL, bounding box coords, local filtering, WFS version, max boreholes))
prov_list = [ ("", "", { "west": 143.75, "south": -43.75, "east": 148.75, "north": -39.75 }, False, "1.1.0", 20),
......@@ -47,7 +48,7 @@ def do_demo(wfs, nvcl, bbox, local_filt, version, max):
bh_list = reader.get_boreholes_list()
print("len(bh_list) = ", len(bh_list))
# Print borehole details and Australian Stratigraphic Units Database records
# Print borehole details and relevant records from Australian Stratigraphic Units Database (
for bh in bh_list[:5]:
......@@ -121,11 +121,30 @@ def _get_asud_strat_no(lon, lat):
def get_asud_record(lon, lat):
''' Retrieves a stratigraphy record from the 'Australian Strategraphic Units Database'
:param lon: longitude
:param lat: latitude
:param lon: longitude (float or string)
:param lat: latitude (float or string)
:returns: stratigraphy record as a dict or None upon error or not found
strat_no = _get_asud_strat_no(lon, lat)
# Check input parameters
if not isinstance(lon, float):
lon_flt = float(lon)
except (ValueError, TypeError):
LOGGER.warning("lon parameter is not a float")
return None
lon_flt = lon
if not isinstance(lat, float):
lat_flt = float(lat)
except (ValueError, TypeError):
LOGGER.warning("lat parameter is not a float")
return None
lat_flt = lat
strat_no = _get_asud_strat_no(lon_flt, lat_flt)
if strat_no is not None:
resp = post(GSUD_API, data=json.dumps({"actionName": "searchStratigraphicUnitsDetails", "stratNo": strat_no}))
#!/usr/bin/env python3
import sys, os
import unittest
from unittest.mock import patch, Mock
from requests.exceptions import Timeout, RequestException
from owslib.util import ServiceException
from http.client import HTTPException
import logging
from types import SimpleNamespace
from nvcl_kit.asud import get_asud_record
class TestNVCLAsud(unittest.TestCase):
def try_input_param(self, lon, lat, msg):
''' Used to test variations in erroneous input parameters
:param lon: longitude (float)
:param lat: latitude (float)
:param msg: expected warning message
with self.assertLogs('nvcl_kit.asud', level='WARN') as nvcl_log:
rec = get_asud_record(lon, lat)
self.assertIn(msg, nvcl_log.output[0])
self.assertEqual(rec, None)
def test_params(self):
''' Tests exception handling in get_borehole_data()
self.try_input_param(0.0, None, 'lat parameter is not a float')
self.try_input_param(None, 8.0, 'lon parameter is not a float')
self.try_input_param(None, "", 'lon parameter is not a float')
......@@ -776,7 +776,3 @@ class TestNVCLReader(unittest.TestCase):
self.assertEqual(log_list[0].log_id, 'b80a98e4-6d9b-4a58-ab04-d105c172e67')
self.assertEqual(log_list[0].log_name, 'Imagery')
self.assertEqual(log_list[0].sample_count, 30954)
if __name__ == '__main__':
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment