Skip to content

Commit

Permalink
Styles tests and pin pytest requirements.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
BielStela committed Apr 8, 2024
1 parent fd86302 commit 11b3385
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 19 deletions.
3 changes: 3 additions & 0 deletions api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ src = ["app"]

[tool.ruff.flake8-bugbear]
extend-immutable-calls = ["fastapi.Depends", "fastapi.params.Depends", "fastapi.Query", "fastapi.params.Query"]

[tool.ruff.lint.per-file-ignores]
"**/{tests}/*" = ["D103"] # Missing docstring in public function
10 changes: 8 additions & 2 deletions api/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This file was autogenerated by uv via the following command:
# uv pip freeze | uv pip compile - -o requirements.txt
# uv pip compile - -o requirements.txt
affine==2.4.0
# via rasterio
annotated-types==0.6.0
Expand Down Expand Up @@ -60,6 +60,8 @@ idna==3.6
# via
# anyio
# httpx
iniconfig==2.0.0
# via pytest
jinja2==3.1.3
# via titiler-core
markupsafe==2.1.5
Expand All @@ -84,6 +86,10 @@ numpy==1.26.4
# snuggs
# titiler-core
orjson==3.10.0
packaging==24.0
# via pytest
pluggy==1.4.0
# via pytest
pydantic==2.6.4
# via
# cogeo-mosaic
Expand All @@ -108,6 +114,7 @@ pystac==1.10.0
# via
# rio-stac
# rio-tiler
pytest==8.1.1
python-dateutil==2.9.0.post0
# via pystac
python-dotenv==1.0.1
Expand Down Expand Up @@ -174,4 +181,3 @@ typing-extensions==4.10.0
# pydantic-core
# titiler-core
uvicorn==0.29.0
pytest==8.1.1
35 changes: 23 additions & 12 deletions api/tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import os
import shutil

import pytest
from app.config.config import get_settings

from tests.utils import test_client
import shutil

token = get_settings().auth_token
test_tif_path = get_settings().tif_path
Expand All @@ -21,12 +23,12 @@
[115.0870, -8.3355],
[115.0970, -8.3355],
[115.0970, -8.3455],
[115.0870, -8.3455]
[115.0870, -8.3455],
]
]
}
],
},
}
]
],
}

headers = {"Authorization": f"Bearer {token}"}
Expand All @@ -35,7 +37,7 @@
def test_no_token():
response = test_client.get("/tifs")
assert response.status_code == 401
assert response.text == 'Unauthorized'
assert response.text == "Unauthorized"


def test_with_token(setup_data_folder):
Expand All @@ -55,15 +57,24 @@ def test_list_files(setup_files):
assert response.json() == {"files": files}


def test_wrong_file_name_raises_404(setup_data_folder):
response = test_client.post(
"/exact_zonal_stats", headers=headers, params={"raster_filename": "wrong.tif"}, json=geojson
)
assert response.status_code == 404


# TODO: Activate this test once having a test tif file

# def test_exact_zonal_stats(setup_tif):
# response = test_client.post("/exact_zonal_stats", headers=headers, params={"raster_name": "test.tif"}, json=geojson)
# response = test_client.post(
# "/exact_zonal_stats", headers=headers, params={"raster_name": "test.tif"}, json=geojson
# )
# assert response.status_code == 200
# assert response.json() == {"mean": 0.0, "min": 0.0, "max": 0.0, "count": 0, "sum": 0.0}
#


@pytest.fixture()
def setup_data_folder():
os.mkdir(get_settings().tif_path)
Expand All @@ -77,22 +88,22 @@ def setup_data_folder():
def setup_files():
os.mkdir(get_settings().tif_path)
for file in files:
with open(f'{test_tif_path}/{file}', 'w') as f:
f.write('test data')
with open(f"{test_tif_path}/{file}", "w") as f:
f.write("test data")

yield

for file in files:
os.remove(f'{test_tif_path}/{file}')
os.remove(f"{test_tif_path}/{file}")
os.rmdir(test_tif_path)


@pytest.fixture()
def setup_tif():
os.mkdir(get_settings().tif_path)
shutil.copy('/opt/api/tests/test.tif', 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.remove(f"{get_settings().tif_path}/test.tif")
os.rmdir(get_settings().tif_path)
6 changes: 1 addition & 5 deletions api/tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
from fastapi.testclient import TestClient

from app.config.config import get_settings
from app.main import app
from fastapi.testclient import TestClient

test_client = TestClient(app)


0 comments on commit 11b3385

Please sign in to comment.