Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility changes for CKAN 2.10 #3

Merged
merged 9 commits into from
Oct 2, 2024
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
38 changes: 30 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,34 @@ on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
ckan-version: ['2.9', '2.10']
include:
- ckan-version: '2.9'
ckan-image: ckan/ckan-base:2.9.11
solr-image: ckan/ckan-solr:2.9-solr8
postgres-image: ckan/ckan-postgres-dev:2.9
- ckan-version: '2.10'
ckan-image: ckan/ckan-base:2.10
solr-image: ckan/ckan-solr:2.10-solr8
postgres-image: ckan/ckan-postgres-dev:2.10

container:
# The CKAN version tag of the Solr and Postgres containers should match
# the one of the container the tests run on.
# You can switch this base image with a custom image tailored to your project
image: openknowledge/ckan-dev:2.9
image: ${{ matrix.ckan-image }}

services:
solr:
image: ckan/ckan-solr-dev:2.9
image: ${{ matrix.solr-image }}
postgres:
image: ckan/ckan-postgres-dev:2.9
image: ${{ matrix.postgres-image }}
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
redis:
image: redis:3
image: redis:3

env:
CKAN_SQLALCHEMY_URL: postgresql://ckan_default:pass@postgres/ckan_test
Expand All @@ -36,6 +47,18 @@ jobs:
pip install -r requirements.txt
pip install -r dev-requirements.txt
pip install -e .

- name: Set Git safe directory
run: git config --global --add safe.directory /__w/ckanext-short-urls/ckanext-short-urls

- name: Checkout tag 1.0.0
A-Souhei marked this conversation as resolved.
Show resolved Hide resolved
if: matrix.ckan-version == '2.9'
run: |
git fetch --tags
LATEST_TAG=$(git tag -l '1.*.*' --sort=-v:refname | head -n 1 || echo '1.0.0')
echo "Latest 1.x.x tag or default: $LATEST_TAG"
git checkout $LATEST_TAG

- name: Setup extension
# Extra initialization steps
run: |
Expand All @@ -45,4 +68,3 @@ jobs:
ckan -c test.ini db init
- name: Run tests
run: pytest --ckan-ini=test.ini --cov=ckanext.short_urls --disable-warnings ckanext/short_urls

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ https://yourckan.org/link/xxxx -> https://yourcan.org/dataset/my-dataset/resourc

## Requirements

The extension has been developed and tested with CKAN 2.9 + python3
The extension has been developed and tested with CKAN 2.9, 2.10 and python3

## Installation

Expand Down Expand Up @@ -93,7 +93,7 @@ If ckanext-short-urls should be available on PyPI you can follow these steps to
git push

6. Tag the new release of the project on GitHub with the version number from
the `setup.py` file. For example if the version number in `setup.py` is
the `setup.py` file. The tag should be 1.*.* for any release compatible with CKAN 2.9, and 2.*.* for releases compatible with CKAN 2.10. For example if the version number in `setup.py` is
0.0.1 then do:

git tag 0.0.1
Expand Down
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
4 changes: 4 additions & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
pytest-ckan
mock
pytest-factoryboy
pytest-cov
pylons
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# http://packaging.python.org/en/latest/tutorial.html#version
version='0.0.1',
version='2.0.0',

description='''Create short URLs for datasets and resources''',
long_description=long_description,
Expand Down
Loading