|
1 | 1 | """Tests for API responses.""" |
2 | 2 | from io import BytesIO |
| 3 | +import re |
3 | 4 | import zipfile |
4 | 5 |
|
5 | 6 | import pytest |
@@ -48,6 +49,37 @@ def test_get_ags_exporter_by_polygon(client, count_only): |
48 | 49 | assert f'Project : {bgs_proj_id}' in metadata_text |
49 | 50 |
|
50 | 51 |
|
| 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 | + |
51 | 83 | @pytest.mark.parametrize('polygon, count', [ |
52 | 84 | ('POLYGON((-3.946 56.061,-3.640 56.061,-3.640 55.966,-3.946 55.966,-3.946 56.061))', 0), |
53 | 85 | ('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