Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pygeoapi/api/stac.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def search(api: API, request: Union[APIRequest, Any]) -> Tuple[dict, int, str]:
if request.data:
LOGGER.debug('Intercepting STAC POST request into query args')
request_data = json.loads(request.data)
request_params = deepcopy(dict(request.params))
request_params = deepcopy(dict(request.params.items()))

for qp in ['bbox', 'datetime', 'limit', 'offset']:
if qp in request_data:
Expand Down Expand Up @@ -398,7 +398,7 @@ def search(api: API, request: Union[APIRequest, Any]) -> Tuple[dict, int, str]:

next_link = False
prev_link = False
request_params = deepcopy(dict(request._args))
request_params = deepcopy(dict(request.params.items()))
limit = itemtypes_api.evaluate_limit(
request_params.get('limit'),
api.config['server'].get('limits', {}), {})
Expand Down
41 changes: 41 additions & 0 deletions tests/other/test_django.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,21 @@


from http import HTTPStatus
import json
import os
import sys
from unittest import mock
from types import SimpleNamespace
from urllib.parse import parse_qs, urlsplit

import django
from django.test import Client
import pytest

from pygeoapi.api import API, APIRequest
from pygeoapi.api.stac import search
from pygeoapi.util import yaml_load

from ..util import get_test_file_path


Expand Down Expand Up @@ -71,3 +78,37 @@ def test_django_edr_without_instance_id(django_):
response_json = response.json()
assert response_json["type"] == "Coverage"
assert response_json["domain"]["domainType"] == "PointSeries"


@pytest.fixture
def stac_api(openapi):
with open(get_test_file_path('pygeoapi-test-stac-api-config.yml')) as fh:
return API(yaml_load(fh), openapi)


@pytest.mark.parametrize('post_data,limit', [(None, 3), ({'limit': 2}, 2)])
def test_search_django_query_params(stac_api, post_data, limit, monkeypatch):
"""Django query values stay scalar in POST overrides and paging links."""
django_http = pytest.importorskip('django.http')
monkeypatch.setattr(django_http.request, 'settings', SimpleNamespace(
DATA_UPLOAD_MAX_NUMBER_FIELDS=1000))
params = django_http.QueryDict(
'limit=1&limit=3&offset=2&bbox=-180,-90,180,90', encoding='utf-8')
request = SimpleNamespace(
GET=params, headers={}, path_info='/stac-api/search',
body=json.dumps(post_data).encode() if post_data else b'')
req = APIRequest.from_django(request, stac_api.locales)

_, code, response = search(stac_api, req)
assert code == 200
response = json.loads(response)
assert response['numberMatched'] == 10
assert response['numberReturned'] == limit
links = {link['rel']: link['href'] for link in response['links']}
for rel, offset in [('prev', None), ('next', [str(2 + limit)])]:
query = parse_qs(urlsplit(links[rel]).query)
assert query['limit'] == [str(limit)]
assert query['bbox'] == ['-180,-90,180,90']
assert query.get('offset') == offset
assert params.getlist('limit') == ['1', '3']
assert params['offset'] == '2'
Loading