From f092cf548ebbe405e030a6247a81ac5b6d276e28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Garn=C3=A6s?= Date: Thu, 29 Feb 2024 19:48:57 +0100 Subject: [PATCH] Django server: EDR sanity test (#1530) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * EDR queries without instance id works Django URL's without instance IDs called a method requiring instance IDs, resulting in a crash. Instance ID defaults to None, which is also standard for the provider that ultimately will be called. Regression test added * Use fixtures in django server tests --------- Co-authored-by: Peter Garnæs --- tests/test_django.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/tests/test_django.py b/tests/test_django.py index acebab4..06cda4f 100644 --- a/tests/test_django.py +++ b/tests/test_django.py @@ -4,15 +4,38 @@ import os from unittest import mock import django +import pytest from django.test import Client +from .util import get_test_file_path -@mock.patch.dict(os.environ, {"DJANGO_SETTINGS_MODULE": "django_.settings"}) + +@pytest.fixture +@mock.patch.dict(os.environ, { + "DJANGO_SETTINGS_MODULE": "django_.settings", + "PYGEOAPI_CONFIG": get_test_file_path('pygeoapi-test-config.yml'), + "PYGEOAPI_OPENAPI": get_test_file_path('pygeoapi-test-openapi.yml') +}) @mock.patch.object(sys, "path", sys.path + ["./pygeoapi"]) -def test_django_landing_page_loads(): +def django_(): django.setup() + return django + +def test_django_landing_page_loads(django_): response = Client(SERVER_NAME="localhost").get("/") assert response.status_code == HTTPStatus.OK assert response.json()["title"] == "pygeoapi default instance" + + +def test_django_edr_without_instance_id(django_): + edr_position_query = ("/collections/icoads-sst/position?coords=" + "POINT(12.779895 55.783523)&f=json") + response = Client(SERVER_NAME="localhost").get(edr_position_query) + + assert response.status_code == HTTPStatus.OK + # Validate CoverageJSON is returned + response_json = response.json() + assert response_json["type"] == "Coverage" + assert response_json["domain"]["domainType"] == "Grid"