Skip to content

Commit

Permalink
Removes unused fixture and rename fixture
Browse files Browse the repository at this point in the history
Rename to make clear that it is creating empty files just to test listing of available data sources
  • Loading branch information
BielStela committed Apr 8, 2024
1 parent fb53fec commit 5f5ef8e
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions api/tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import shutil

import numpy as np
import pytest
Expand Down Expand Up @@ -67,30 +66,20 @@ def tif_file(setup_data_folder):


@pytest.fixture()
def setup_files(setup_data_folder):
def setup_empty_files(setup_data_folder):
test_tif_path = get_settings().tif_path

for file in FILES:
# Create empty files writing nothing
with open(f"{test_tif_path}/{file}", "w") as f:
f.write("test data")
f.write("")

yield

for file in FILES:
os.remove(f"{test_tif_path}/{file}")


@pytest.fixture()
def setup_tif():
os.mkdir(get_settings().tif_path)
shutil.copy("/opt/api/tests/test.tif", get_settings().tif_path)

yield

os.remove(f"{get_settings().tif_path}/test.tif")
os.rmdir(get_settings().tif_path)


def test_no_token():
response = test_client.get("/tifs")
assert response.status_code == 401
Expand All @@ -112,7 +101,7 @@ def test_list_files_empty(setup_data_folder):
assert response.json() == {"files": []}


def test_list_files(setup_files):
def test_list_files(setup_empty_files):
response = test_client.get("/tifs", headers=HEADERS)
assert response.status_code == 200
assert response.json() == {"files": FILES}
Expand Down Expand Up @@ -158,3 +147,13 @@ def test_custom_zonal_stats(tif_file):
)
assert response.status_code == 200
assert response.json() == {"features": [{"properties": {"count": 9}, "type": "Feature"}]}


def test_nonexistent_statistic_raises_422(tif_file):
response = test_client.post(
"/exact_zonal_stats",
headers=HEADERS,
params={"raster_filename": "raster.tif", "statistics": ["nonexistent"]},
json=GEOJSON,
)
assert response.status_code == 422

0 comments on commit 5f5ef8e

Please sign in to comment.