Skip to content

Commit

Permalink
Merge pull request #14 from ricardogsilva/2-add-integration-tests
Browse files Browse the repository at this point in the history
Added integration tests
  • Loading branch information
francbartoli authored Feb 14, 2024
2 parents 5bb9892 + ce30fcf commit a78b205
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[run]
branch = True
source =
djangoapp \
padoa
4 changes: 3 additions & 1 deletion tests/ci/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ async def build_and_test():
.with_exec(
shlex.split(
"pip install "
"coverage==7.4.1 "
"pytest==8.0.0 "
"pytest-cov==4.1.0 "
"pytest-django==4.8.0"
),
skip_entrypoint=True
Expand All @@ -89,7 +91,7 @@ async def build_and_test():
)
.with_exec(shlex.split("python manage.py migrate"), skip_entrypoint=True)
.with_exec(
shlex.split("pytest --verbose -x --reuse-db ../tests/test_padoa_forecastattributes_views.py"),
shlex.split("pytest --verbose --cov -k 'padoa' -x --reuse-db ../tests"),
skip_entrypoint=True
)
).stdout()
Expand Down
53 changes: 53 additions & 0 deletions tests/test_padoa_places_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import pytest

from padoa.places import models


@pytest.mark.django_db
def test_list_cities(client):
num_items = 3
fake_region = models.Regions.objects.create(
id=1,
name="fakeregion",
geometry="MULTIPOLYGON(((40 40, 20 45, 45 30, 40 40)),((20 35, 10 30, 10 10, 30 5, 45 20, 20 35),(30 20, 20 15, 20 25, 30 20)))",
centroid="Point(0 0)"
)
fake_province = models.Provinces.objects.create(
id=10,
name="fakeprovince",
region=fake_region,
geometry="MULTIPOLYGON(((40 40, 20 45, 45 30, 40 40)),((20 35, 10 30, 10 10, 30 5, 45 20, 20 35),(30 20, 20 15, 20 25, 30 20)))",
centroid="Point(10 10)",
)
centroids = {}
for i in range(1, num_items + 1):
centroid = {"longitude": i, "latitude": i+3}
centroids[i] = centroid
models.Cities.objects.create(
id=100+i,
name=f"Fake city {i}",
prov_code="fakeprovincecode",
region=fake_region,
province=fake_province,
geometry="MULTIPOLYGON(((40 40, 20 45, 45 30, 40 40)),((20 35, 10 30, 10 10, 30 5, 45 20, 20 35),(30 20, 20 15, 20 25, 30 20)))",
centroid=f"Point({centroid['longitude']} {centroid['latitude']})"
)
response = client.get("/places/cities/")
assert response.status_code == 200
contents = response.json()
assert contents.get("count") == num_items
assert len(contents.get("results")) == num_items
for i in range(1, num_items + 1):
print(f"looking for city #{i}...")
for model_ in contents["results"]:
if model_.get("id") == 100 + i:
expected_centroid = centroids[i]
assert model_["name"] == f"Fake city {i}"
assert model_["latlng"] == {
"lng": expected_centroid["longitude"],
"lat": expected_centroid["latitude"]
}
break
else:
print(f"Did not find instance #{i}")
assert False
1 change: 1 addition & 0 deletions tests/test_padoa_thredds_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@


@pytest.mark.django_db
@pytest.mark.xfail(reason="Not implemented yet")
@pytest.mark.parametrize("url_list_path", [
pytest.param("/maps/ncss/timeserie/"),
])
Expand Down

0 comments on commit a78b205

Please sign in to comment.