Skip to content

Commit

Permalink
Merge pull request #197 from vrk-kpa/fix_pagination_uris
Browse files Browse the repository at this point in the history
Fixes pagination URIs to use same logic as catalog_uri
  • Loading branch information
amercader authored Jun 22, 2021
2 parents 3d86671 + 7012845 commit 1c6c8f3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
6 changes: 2 additions & 4 deletions ckanext/dcat/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import ckanext.dcat.converters as converters

from ckanext.dcat.processors import RDFSerializer

from ckanext.dcat.utils import catalog_uri

DATASETS_PER_PAGE = 100

Expand Down Expand Up @@ -144,9 +144,7 @@ def _pagination_info(query, data_dict):

def _page_url(page):

base_url = config.get('ckan.site_url', '').strip('/')
if not base_url:
base_url = toolkit.request.host_url
base_url = catalog_uri()
base_url = '%s%s' % (
base_url, toolkit.request.path)

Expand Down
12 changes: 6 additions & 6 deletions ckanext/dcat/tests/test_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,9 @@ def test_pagination_keeps_only_supported_params(self, mock_request):
assert 'previous' not in pagination

@pytest.mark.ckan_config('ckanext.dcat.datasets_per_page', 10)
@pytest.mark.ckan_config('ckan.site_url', '')
@pytest.mark.ckan_config('ckanext.dcat.base_uri', 'http://example.com/data')
@mock.patch('ckan.plugins.toolkit.request')
def test_pagination_without_site_url(self, mock_request):
def test_pagination_with_dcat_base_uri(self, mock_request):

mock_request.params = {}
mock_request.host_url = 'http://ckan.example.com'
Expand All @@ -262,10 +262,10 @@ def test_pagination_without_site_url(self, mock_request):

assert pagination['count'] == 12
assert pagination['items_per_page'] == config.get('ckanext.dcat.datasets_per_page')
assert pagination['current'] == 'http://ckan.example.com/feed/catalog.xml?page=1'
assert pagination['first'] == 'http://ckan.example.com/feed/catalog.xml?page=1'
assert pagination['last'] == 'http://ckan.example.com/feed/catalog.xml?page=2'
assert pagination['next'] == 'http://ckan.example.com/feed/catalog.xml?page=2'
assert pagination['current'] == 'http://example.com/data/feed/catalog.xml?page=1'
assert pagination['first'] == 'http://example.com/data/feed/catalog.xml?page=1'
assert pagination['last'] == 'http://example.com/data/feed/catalog.xml?page=2'
assert pagination['next'] == 'http://example.com/data/feed/catalog.xml?page=2'
assert 'previous' not in pagination

def test_pagination_no_results_empty_dict(self):
Expand Down

0 comments on commit 1c6c8f3

Please sign in to comment.