From cefd74ca3789359d803648cedabcff45dab1d321 Mon Sep 17 00:00:00 2001 From: Colin Blackburn Date: Wed, 3 Dec 2025 14:07:21 +0000 Subject: [PATCH 1/2] Test for borehole count above old limit of 10 --- .../integration/test_ags_export_by_polygon.py | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/integration/test_ags_export_by_polygon.py b/test/integration/test_ags_export_by_polygon.py index 80b0114..7f3a1a0 100644 --- a/test/integration/test_ags_export_by_polygon.py +++ b/test/integration/test_ags_export_by_polygon.py @@ -1,5 +1,6 @@ """Tests for API responses.""" from io import BytesIO +import re import zipfile import pytest @@ -48,6 +49,37 @@ def test_get_ags_exporter_by_polygon(client, count_only): assert f'Project : {bgs_proj_id}' in metadata_text +@pytest.mark.xfail(IN_GITHUB_ACTIONS, reason="Upstream URL not available from Github Actions") +def test_get_ags_exporter_by_polygon_with_more_than_10_polygons(client): + # Arrange + # There should be 28 boreholes in this area, this should pass for a limit of 50, + # and it should fail for a limit of 10 + polygon = 'POLYGON((-3.946 56.065,-3.640 56.065,-3.640 55.966,-3.946 55.966,-3.946 56.065))' + query = f'{API_VERSION}/ags_export_by_polygon/?polygon={polygon}' + ags_metadata_file_name = 'FILE/BGSFileSet01/BGS_download_metadata.txt' + + # Act + with client as ac: + response = ac.get(query) + + # Assert + assert response.status_code == 200 + assert response.headers["Content-Disposition"] == 'attachment; filename="boreholes.zip"' + assert response.headers["Content-Type"] == "application/x-zip-compressed" + assert len(response.content) > 0 + + assert zipfile.is_zipfile(BytesIO(response.content)) + with zipfile.ZipFile(BytesIO(response.content)) as ags_zip: + # Check that metadata.txt lists 28 loca IDs + with ags_zip.open(ags_metadata_file_name) as metadata_file: + # find the pattern 20200205093727287902;20200205093727287903;2020... + regex = r'\d+(;\d+)+' + metadata_text = metadata_file.read().decode() + match = re.search(regex, metadata_text) + assert match + assert len(match.group(0).split(';')) == 28 + + @pytest.mark.parametrize('polygon, count', [ ('POLYGON((-3.946 56.061,-3.640 56.061,-3.640 55.966,-3.946 55.966,-3.946 56.061))', 0), ('POLYGON((-3.946 56.063,-3.640 56.063,-3.640 55.966,-3.946 55.966,-3.946 56.063))', 4), From f39fae32ca2bfe9210208440560a2b5317cd8785 Mon Sep 17 00:00:00 2001 From: Colin Blackburn Date: Wed, 3 Dec 2025 13:51:15 +0000 Subject: [PATCH 2/2] Use constant for borehole export limit --- app/routes/ags_export_by_polygon.py | 2 +- app/routes/utils.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/routes/ags_export_by_polygon.py b/app/routes/ags_export_by_polygon.py index 9c87fa4..7fc5683 100644 --- a/app/routes/ags_export_by_polygon.py +++ b/app/routes/ags_export_by_polygon.py @@ -67,7 +67,7 @@ def ags_export_by_polygon( except shapely.errors.GEOSException: raise HTTPException(status_code=422, detail="Invalid polygon") - url = BOREHOLE_INDEX_URL.format(polygon=polygon) + url = BOREHOLE_INDEX_URL.format(polygon=polygon, borehole_export_limit=BOREHOLE_EXPORT_LIMIT) try: response = requests.get(url, timeout=10) diff --git a/app/routes/utils.py b/app/routes/utils.py index f36583c..5292a98 100644 --- a/app/routes/utils.py +++ b/app/routes/utils.py @@ -15,7 +15,7 @@ BOREHOLE_EXPORT_URL = "https://gwbv.bgs.ac.uk/ags_export?loca_ids={bgs_loca_id}" BOREHOLE_INDEX_URL = ( "https://ogcapi.bgs.ac.uk/collections/agsboreholeindex/items?f=json" - "&properties=bgs_loca_id&filter=INTERSECTS(shape,{polygon})&limit=50" + "&properties=bgs_loca_id&filter=INTERSECTS(shape,{polygon})&limit={borehole_export_limit}" ) log_responses = dict(error_responses)