Skip to content

Commit

Permalink
Merge pull request #159 from GSA/max-resource
Browse files Browse the repository at this point in the history
Max resource
  • Loading branch information
jbrown-xentity authored Sep 25, 2024
2 parents fe4ccb6 + c25da65 commit c461c29
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions ckanext/datajson/parse_datajson.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from ckan.lib.munge import munge_title_to_name
from ckan.lib.navl.dictization_functions import DataError
from ckan.plugins.toolkit import config
from ckan.plugins.toolkit import asint, config

import re

Expand Down Expand Up @@ -110,7 +110,8 @@ def parse_datajson_entry(datajson, package, defaults, schema_version):
}
distribution.append(d)

max_resource_count = config.get('ckanext.datajson.max_resource_count')
# max_resource_count is unlimited if not set or set to 0
max_resource_count = asint(config.get('ckanext.datajson.max_resource_count', 0))
if max_resource_count and len(distribution) > max_resource_count:
error_message = (f'Too many resources. Maximum allowed is {max_resource_count}. '
f'Actual size is {len(distribution)}.')
Expand Down
2 changes: 1 addition & 1 deletion ckanext/datajson/tests/test_datajson_ckan_all_harvester.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ def test_harvesting_parent_child_2_collections(self):
parent = model.Package.get(parent_package_id)
assert parent.title == 'Employee Relations Roundtables 2'

@pytest.mark.ckan_config('ckanext.datajson.max_resource_count', 10)
@pytest.mark.ckan_config('ckanext.datajson.max_resource_count', '10')
def test_too_many_resources(self):
url = 'http://127.0.0.1:%s/many-resources' % self.mock_port
self.run_source(url=url)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

setup(
name='ckanext-datajson',
version='0.1.26',
version='0.1.27',
description='CKAN extension to generate /data.json',
long_description=long_description,
long_description_content_type='text/markdown',
Expand Down

0 comments on commit c461c29

Please sign in to comment.