Skip to content

Commit a9bba27

Browse files
authored
Merge pull request #188 from BritishGeologicalSurvey/use-borehole-limit-constant
Use borehole limit constant
2 parents 7e788d2 + f39fae3 commit a9bba27

3 files changed

Lines changed: 34 additions & 2 deletions

File tree

app/routes/ags_export_by_polygon.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def ags_export_by_polygon(
6767
except shapely.errors.GEOSException:
6868
raise HTTPException(status_code=422, detail="Invalid polygon")
6969

70-
url = BOREHOLE_INDEX_URL.format(polygon=polygon)
70+
url = BOREHOLE_INDEX_URL.format(polygon=polygon, borehole_export_limit=BOREHOLE_EXPORT_LIMIT)
7171

7272
try:
7373
response = requests.get(url, timeout=10)

app/routes/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
BOREHOLE_EXPORT_URL = "https://gwbv.bgs.ac.uk/ags_export?loca_ids={bgs_loca_id}"
1616
BOREHOLE_INDEX_URL = (
1717
"https://ogcapi.bgs.ac.uk/collections/agsboreholeindex/items?f=json"
18-
"&properties=bgs_loca_id&filter=INTERSECTS(shape,{polygon})&limit=50"
18+
"&properties=bgs_loca_id&filter=INTERSECTS(shape,{polygon})&limit={borehole_export_limit}"
1919
)
2020

2121
log_responses = dict(error_responses)

test/integration/test_ags_export_by_polygon.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Tests for API responses."""
22
from io import BytesIO
3+
import re
34
import zipfile
45

56
import pytest
@@ -48,6 +49,37 @@ def test_get_ags_exporter_by_polygon(client, count_only):
4849
assert f'Project : {bgs_proj_id}' in metadata_text
4950

5051

52+
@pytest.mark.xfail(IN_GITHUB_ACTIONS, reason="Upstream URL not available from Github Actions")
53+
def test_get_ags_exporter_by_polygon_with_more_than_10_polygons(client):
54+
# Arrange
55+
# There should be 28 boreholes in this area, this should pass for a limit of 50,
56+
# and it should fail for a limit of 10
57+
polygon = 'POLYGON((-3.946 56.065,-3.640 56.065,-3.640 55.966,-3.946 55.966,-3.946 56.065))'
58+
query = f'{API_VERSION}/ags_export_by_polygon/?polygon={polygon}'
59+
ags_metadata_file_name = 'FILE/BGSFileSet01/BGS_download_metadata.txt'
60+
61+
# Act
62+
with client as ac:
63+
response = ac.get(query)
64+
65+
# Assert
66+
assert response.status_code == 200
67+
assert response.headers["Content-Disposition"] == 'attachment; filename="boreholes.zip"'
68+
assert response.headers["Content-Type"] == "application/x-zip-compressed"
69+
assert len(response.content) > 0
70+
71+
assert zipfile.is_zipfile(BytesIO(response.content))
72+
with zipfile.ZipFile(BytesIO(response.content)) as ags_zip:
73+
# Check that metadata.txt lists 28 loca IDs
74+
with ags_zip.open(ags_metadata_file_name) as metadata_file:
75+
# find the pattern 20200205093727287902;20200205093727287903;2020...
76+
regex = r'\d+(;\d+)+'
77+
metadata_text = metadata_file.read().decode()
78+
match = re.search(regex, metadata_text)
79+
assert match
80+
assert len(match.group(0).split(';')) == 28
81+
82+
5183
@pytest.mark.parametrize('polygon, count', [
5284
('POLYGON((-3.946 56.061,-3.640 56.061,-3.640 55.966,-3.946 55.966,-3.946 56.061))', 0),
5385
('POLYGON((-3.946 56.063,-3.640 56.063,-3.640 55.966,-3.946 55.966,-3.946 56.063))', 4),

0 commit comments

Comments
 (0)