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
6 changes: 6 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[report]
omit =
*/site-packages/*
*/python?.?/*
ckan/*
*/tests/*
49 changes: 24 additions & 25 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@ jobs:
needs: lint
strategy:
matrix:
ckan-version: [2.8]
ckan-version: ["2.10", "2.11"]
fail-fast: false

name: CKAN ${{ matrix.ckan-version }}
runs-on: ubuntu-latest
container:
image: openknowledge/ckan-dev:${{ matrix.ckan-version }}
image: ckan/ckan-dev:${{ matrix.ckan-version }}
options: --user root
services:
solr:
image: ckan/ckan-solr:${{ matrix.ckan-version }}
image: ckan/ckan-solr:${{ matrix.ckan-version }}-solr9
postgres:
image: ckan/ckan-postgres-dev:${{ matrix.ckan-version }}
env:
Expand All @@ -37,7 +38,7 @@ jobs:
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
CKAN_DATASTORE_WRITE_URL: postgresql://datastore_write:pass@postgres/datastore_test
Expand All @@ -47,25 +48,23 @@ jobs:
CKAN_SITE_URL: http://test.ckan.net

steps:
- uses: actions/checkout@v3
- name: Install requirements
run: |
# Replace default path to CKAN core config file with the one on the container
sed -i -e 's/use = config:.*/use = config:\/srv\/app\/src\/ckan\/test-core.ini/' test.ini
pip install -r requirements.txt
pip install -r dev-requirements.txt
pip install -e .
# Last commit before support for Python 2 was dropped
pip install -e git+https://github.com/ckan/ckanext-harvest.git@v1.4.2#egg=ckanext-harvest
pip install -r https://raw.githubusercontent.com/ckan/ckanext-harvest/v1.4.2/requirements.txt
# Last commit before support for Python 2 was dropped
pip install -e git+https://github.com/ckan/ckanext-dcat.git@0c26bed5b7a3a7fca8e7b78e338aace096e0ebf6#egg=ckanext-dcat
pip install -r https://raw.githubusercontent.com/ckan/ckanext-dcat/0c26bed5b7a3a7fca8e7b78e338aace096e0ebf6/requirements-py2.txt
pip install -r https://raw.githubusercontent.com/ckan/ckanext-dcat/0c26bed5b7a3a7fca8e7b78e338aace096e0ebf6/dev-requirements-py2.txt
- name: Checkout
uses: actions/checkout@v4
- name: Install requirements
run: |
pip install -r requirements.txt
pip install -r dev-requirements.txt
pip install -e .
pip install -e git+https://github.com/ckan/ckanext-harvest.git#egg=ckanext-harvest
pip install -r https://raw.githubusercontent.com/ckan/ckanext-harvest/master/requirements.txt
pip install -e git+https://github.com/ckan/ckanext-dcat.git#egg=ckanext-dcat
pip install -r https://raw.githubusercontent.com/ckan/ckanext-dcat/master/requirements.txt
# Replace default path to CKAN core config file with the one on the container
sed -i -e 's/use = config:.*/use = config:\/srv\/app\/src\/ckan\/test-core.ini/' test.ini

- name: Setup extension
run: |
paster --plugin=ckan db init -c test.ini
paster --plugin=ckanext-harvest harvester initdb -c test.ini
- name: Run tests
run: nosetests --ckan --nocapture --nologcapture --with-pylons=test.ini --with-coverage --cover-package=ckanext.dcatapchharvest --cover-inclusive --cover-erase --cover-tests ckanext/dcatapchharvest
- name: Setup extension
run: |
ckan -c test.ini db init
ckan -c test.ini db pending-migrations --apply
- name: Run tests
run: pytest --ckan-ini=test.ini --disable-warnings --cov=ckanext.dcatapchharvest ckanext/dcatapchharvest
4 changes: 3 additions & 1 deletion ckanext/dcatapchharvest/harvesters.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def before_download(self, url, harvest_job):
url = url.replace("ogd.global.szh.loc", "data.stadt-zuerich.ch")
return url, []

def _get_guid(self, dataset_dict, source_url=None):
def _get_guid(self, dataset_dict, source_url=None): # noqa C901
"""
Try to get a unique identifier for a harvested dataset
It will be the first found of:
Expand All @@ -82,6 +82,8 @@ def _get_guid(self, dataset_dict, source_url=None):
The last two are obviously not optimal, as depend on title, which
might change.
Returns None if no guid could be decided.

TODO: This method is too complex (flake8 says 16). Refactor it!
"""
guid = None

Expand Down
8 changes: 5 additions & 3 deletions ckanext/dcatapchharvest/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _add_multilang_value(
if values:
# the values can be either a multilang-dict or they are
# nested in another iterable (e.g. keywords)
if not hasattr(values, "__iter__"):
if not isinstance(values, list):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently in Python 3, strings also have the __iter__ attribute. We need to really check whether the value is a list, not check for this attribute, or we won't correctly wrap a string value in a list (in the next line) and we'll end up iterating over it letter by letter.

I think there aren't any other kinds of iterable that we could get as a value here, only a list or a string, so this should be enough of a check here.

values = [values]
for value in values:
if value:
Expand Down Expand Up @@ -542,7 +542,8 @@ def _get_groups(self, subject):
# Deduplicate group names before returning list of group dicts
return [{"name": name} for name in list(set(group_names))]

def parse_dataset(self, dataset_dict, dataset_ref):
def parse_dataset(self, dataset_dict, dataset_ref): # noqa C901
# TODO: This method is too complex (flake8 says 30). Refactor it!
log.debug(f"Parsing dataset '{dataset_ref!r}'")

dataset_dict["temporals"] = []
Expand Down Expand Up @@ -760,7 +761,8 @@ def parse_dataset(self, dataset_dict, dataset_ref):

return dataset_dict

def graph_from_dataset(self, dataset_dict, dataset_ref):
def graph_from_dataset(self, dataset_dict, dataset_ref): # noqa C901
# TODO: This method is too complex (flake8 says 49, I am amazed). Refactor it!

log.debug(f"Create graph from dataset '{dataset_dict['name']}'")

Expand Down
Loading
Loading