Skip to content

Commit

Permalink
Compatibility changes for CKAN 2.10
Browse files Browse the repository at this point in the history
  • Loading branch information
toavina committed Sep 19, 2024
1 parent 154ddfb commit ae8d6c1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
10 changes: 6 additions & 4 deletions ckanext/short_urls/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@ def get_blueprint(self):
return blueprints

# IPackageController & IResourceController
def after_create(self, context, data_dict):
if _data_dict_is_resource(data_dict):
short_url_create(ObjectType.RESOURCE, data_dict['id'])
else:
def after_dataset_create(self, context, data_dict):
if not _data_dict_is_resource(data_dict):
short_url_create(ObjectType.DATASET, data_dict['id'])

def after_resource_create(self, context, data_dict):
short_url_create(ObjectType.RESOURCE, data_dict['id'])


# ITemplateHelpers
def get_helpers(self):
return {
Expand Down
12 changes: 7 additions & 5 deletions ckanext/short_urls/tests/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
from ckanext.short_urls.logic import get_short_url_from_object_id
from ckan.cli.cli import ckan

dataset_or_resource_after_create_action = \
'ckanext.short_urls.plugin.ShortUrlsPlugin.after_create'
dataset_after_create_action = \
'ckanext.short_urls.plugin.ShortUrlsPlugin.after_dataset_create'
resource_after_create_action = \
'ckanext.short_urls.plugin.ShortUrlsPlugin.after_resource_create'

@pytest.mark.usefixtures(u"with_plugins")
class TestCommand(object):

def test_assigning_short_urls_to_all_existing_datasets_command(self, cli):
with mock.patch(dataset_or_resource_after_create_action):
with mock.patch(dataset_after_create_action):
dataset = factories.Dataset()
short_url = get_short_url_from_object_id(dataset['id'])
assert not short_url
Expand All @@ -21,11 +23,11 @@ def test_assigning_short_urls_to_all_existing_datasets_command(self, cli):
assert short_url

def test_assigning_short_urls_to_all_existing_resource_command(self, cli):
with mock.patch(dataset_or_resource_after_create_action):
with mock.patch(dataset_after_create_action), mock.patch(resource_after_create_action):
dataset = factories.Dataset()
resource = factories.Resource(package_id=dataset['id'])
short_url = get_short_url_from_object_id(resource['id'])
assert not short_url
cli.invoke(ckan, ["short-urls", "migrate"])
short_url = get_short_url_from_object_id(resource['id'])
assert short_url
assert short_url
10 changes: 6 additions & 4 deletions ckanext/short_urls/tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@

generate_unique_short_url_code_function = \
'ckanext.short_urls.logic._generate_unique_short_url_code'
dataset_or_resource_after_create_action = \
'ckanext.short_urls.plugin.ShortUrlsPlugin.after_create'
dataset_after_create_action = \
'ckanext.short_urls.plugin.ShortUrlsPlugin.after_dataset_create'
resource_after_create_action = \
'ckanext.short_urls.plugin.ShortUrlsPlugin.after_resource_create'


@pytest.mark.usefixtures('with_plugins')
Expand Down Expand Up @@ -153,7 +155,7 @@ def test_short_url_for_resource_redirects_to_resource_page(self, app):

def test_short_url_on_dataset_page_is_hidden_if_missing(self, app):
user = factories.User()
with mock.patch(dataset_or_resource_after_create_action):
with mock.patch(dataset_after_create_action):
dataset = factories.Dataset(user=user)
response = app.get(
url=url_for(
Expand All @@ -169,7 +171,7 @@ def test_short_url_on_dataset_page_is_hidden_if_missing(self, app):
def test_short_url_on_resource_page_is_hidden_if_missing(self, app):
user = factories.User()
dataset = factories.Dataset(user=user)
with mock.patch(dataset_or_resource_after_create_action):
with mock.patch(resource_after_create_action):
resource = factories.Resource(package_id=dataset['id'])
response = app.get(
url=url_for(
Expand Down
5 changes: 5 additions & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
pytest-ckan
mock
pytest-factoryboy
beautifulsoup4
pytest-cov
pylons

0 comments on commit ae8d6c1

Please sign in to comment.