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

tests: Add Github Actions tests #120

Merged
merged 24 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8547e5b
tests: Add Github Actions tests
bellisk Sep 22, 2023
d00e056
style: Fix flake8 errors
bellisk Sep 22, 2023
a6ac8ab
chore: Revert to pyyaml==5.3.1 due to bug
bellisk Sep 22, 2023
c6f9d54
tests: Remove old Travis config
bellisk Sep 22, 2023
7858a21
chore: Pin pyproj version to that used by CKAN
bellisk Sep 22, 2023
b57bf96
tests: Output logs in tests
bellisk Sep 22, 2023
2c549cf
feat: Map resource rights to license field as well
bellisk Sep 22, 2023
7ef7eb3
tests: Set up solr container for testing
bellisk Sep 22, 2023
4829c10
tests: Don't specify location of docker executable
bellisk Sep 22, 2023
5c30349
tests: Don't run in a container
bellisk Sep 22, 2023
b0bf5c6
tests: Make install script executable
bellisk Sep 22, 2023
f466a36
tests: Use our fork of ckanext-scheming
bellisk Sep 22, 2023
93f28f6
tests: Define variable in script
bellisk Sep 22, 2023
18c5b8d
tests: Set port for postgres container
bellisk Sep 22, 2023
faadbda
tests: Update test.ini for github testing
bellisk Sep 22, 2023
e70ce0b
tests: Update pip before installing requirements
bellisk Sep 22, 2023
58c731c
tests: Fix path to ckanext and requirements
bellisk Sep 22, 2023
298f921
tests: Output logs for debugging
bellisk Sep 22, 2023
6afb930
tests: Add debug statements
bellisk Sep 22, 2023
bb7cf21
tests: Add debug statements
bellisk Sep 22, 2023
6f361ef
tests: Fix quotes in env vars
bellisk Sep 22, 2023
8235777
tests: Adjust solr setup for CKAN 2.8 solr image
bellisk Sep 22, 2023
c07bdd3
tests: Remove debug statement
bellisk Sep 22, 2023
ef88bbc
tests: Remove old schema.xml
bellisk Sep 22, 2023
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
80 changes: 80 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Tests
on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
container:
image: python:2.7.18-buster
steps:
- uses: actions/checkout@v3
- name: Install requirements
run: pip install flake8 pycodestyle
- name: Check syntax
run: flake8 --statistics --show-source ckanext

test:
needs: lint
strategy:
matrix:
ckan-version: [2.8]
fail-fast: false

name: CKAN ${{ matrix.ckan-version }}
runs-on: ubuntu-latest
services:
postgres:
image: ckan/ckan-postgres-dev:${{ matrix.ckan-version }}
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
redis:
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
CKAN_DATASTORE_READ_URL: postgresql://datastore_read:pass@postgres/datastore_test
CKAN_SOLR_URL: http://solr:8983/solr/ckan
CKAN_REDIS_URL: redis://redis:6379/1
CKAN_SITE_URL: http://test.ckan.net
WORKDIR: /__w/ckanext-geocat/ckanext-geocat
SOLR_CONFIG_CKAN_DIR: /opt/solr/server/solr/ckan/conf

steps:
- uses: actions/checkout@v3
- name: Create solr container
run: |
git clone https://github.com/opendata-swiss/ckanext-switzerland-ng.git
docker create --name test_solr --network ${{ job.container.network }} --network-alias solr \
--workdir $WORKDIR --publish 8983:8983 \
-e SOLR_HEAP=1024m -e GITHUB_ACTIONS=true -e CI=true \
-v "${{ github.workspace }}/ckanext-switzerland-ng/solr/schema.xml":"$SOLR_CONFIG_CKAN_DIR/schema.xml" \
-v "${{ github.workspace }}/ckanext-switzerland-ng/solr/english_stop.txt":"$SOLR_CONFIG_CKAN_DIR/english_stop.txt" \
-v "${{ github.workspace }}/ckanext-switzerland-ng/solr/fr_elision.txt":"$SOLR_CONFIG_CKAN_DIR/fr_elision.txt" \
-v "${{ github.workspace }}/ckanext-switzerland-ng/solr/french_stop.txt":"$SOLR_CONFIG_CKAN_DIR/french_stop.txt" \
-v "${{ github.workspace }}/ckanext-switzerland-ng/solr/german_dictionary.txt":"$SOLR_CONFIG_CKAN_DIR/german_dictionary.txt" \
-v "${{ github.workspace }}/ckanext-switzerland-ng/solr/german_stop.txt":"$SOLR_CONFIG_CKAN_DIR/german_stop.txt" \
-v "${{ github.workspace }}/ckanext-switzerland-ng/solr/italian_stop.txt":"$SOLR_CONFIG_CKAN_DIR/italian_stop.txt" \
-v "${{ github.workspace }}/ckanext-switzerland-ng/solr/solrconfig.xml":"$SOLR_CONFIG_CKAN_DIR/solrconfig.xml" \
ckan/ckan-solr:${{ matrix.ckan-version }}
docker start test_solr
- name: Create ckan container
run: |
docker create --name test_ckan --network ${{ job.container.network }} --network-alias ckan \
-e "HOME=/github/home" -e GITHUB_ACTIONS=true -e CI=true -v "/var/run/docker.sock":"/var/run/docker.sock" \
-v "/home/runner/work":"/__w" -v "/home/runner/work/_temp":"/__w/_temp" \
-v "/home/runner/work/_actions":"/__w/_actions" -v "/opt/hostedtoolcache":"/__t" \
-v "/home/runner/work/_temp/_github_home":"/github/home" \
-v "/home/runner/work/_temp/_github_workflow":"/github/workflow" \
--entrypoint "tail" openknowledge/ckan-dev:${{ matrix.ckan-version }} "-f" "/dev/null"
docker start test_ckan
- name: Install requirements and set up database
run: |
docker exec test_ckan $WORKDIR/bin/install_test_requirements.sh ${{ matrix.ckan-version }}
- name: Run tests
run: |
docker exec test_ckan nosetests --ckan --with-pylons=$WORKDIR/test.ini \
--with-coverage --cover-package=ckanext.geocat --cover-inclusive --cover-erase --cover-tests $WORKDIR/ckanext/geocat
22 changes: 0 additions & 22 deletions .travis.yml

This file was deleted.

47 changes: 47 additions & 0 deletions bin/install_test_requirements.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash

WORKDIR=/__w/ckanext-geocat/ckanext-geocat

pip install --upgrade pip

# Install ckanext-geocat
pip install -r "$WORKDIR"/requirements.txt
pip install -r "$WORKDIR"/dev-requirements.txt
pip install -e "$WORKDIR"/

# Install ckanext dependencies
pip install -e git+https://github.com/ckan/ckanext-fluent.git#egg=ckanext-fluent
pip install -e git+https://github.com/ckan/ckanext-hierarchy.git#egg=ckanext-hierarchy
pip install -e git+https://github.com/ckan/ckanext-xloader.git#egg=ckanext-xloader
pip install -r https://raw.githubusercontent.com/ckan/ckanext-xloader/master/requirements.txt

# Last commit before support for Python 2 was dropped
pip install -e git+https://github.com/ckan/[email protected]#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

# Last commit before support for Python 2 was dropped
pip install -e git+https://github.com/ckan/[email protected]#egg=ckanext-showcase

# Our ckanexts
pip install -e git+https://github.com/opendata-swiss/ckanext-dcatapchharvest.git#egg=ckanext-dcatapchharvest
pip install -r https://raw.githubusercontent.com/opendata-swiss/ckanext-dcatapchharvest/master/requirements.txt
pip install -e git+https://github.com/opendata-swiss/ckanext-harvester_dashboard.git#egg=ckanext-harvester_dashboard
pip install -r https://raw.githubusercontent.com/opendata-swiss/ckanext-harvester_dashboard/master/requirements.txt
pip install -e git+https://github.com/opendata-swiss/ckanext-subscribe.git#egg=ckanext-subscribe
pip install -r https://raw.githubusercontent.com/opendata-swiss/ckanext-subscribe/master/requirements.txt
pip install -e git+https://github.com/opendata-swiss/ckanext-switzerland-ng.git#egg=ckanext-switzerland-ng
pip install -r https://raw.githubusercontent.com/opendata-swiss/ckanext-switzerland-ng/master/requirements.txt
pip install -e git+https://github.com/opendata-swiss/ckanext-scheming.git#egg=ckanext-scheming

# 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/' "$WORKDIR"/test.ini

# Init db and enable required plugins
paster --plugin=ckan config-tool "$WORKDIR"/test.ini "ckan.plugins = "
paster --plugin=ckan db init -c "$WORKDIR"/test.ini
paster --plugin=ckanext-harvest harvester initdb -c "$WORKDIR"/test.ini
paster --plugin=ckan config-tool "$WORKDIR"/test.ini "ckan.plugins = harvest ckan_harvester geocat_harvester ogdch ogdch_pkg scheming_datasets fluent"
167 changes: 0 additions & 167 deletions bin/travis-build.bash

This file was deleted.

14 changes: 0 additions & 14 deletions bin/travis-run.sh

This file was deleted.

1 change: 1 addition & 0 deletions ckanext/geocat/utils/ogdch_map_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ def map_resource(geocat_resource, issued, modified, rights):
resource_dict['issued'] = issued
resource_dict['modified'] = modified
resource_dict['rights'] = rights
resource_dict['license'] = rights
if geocat_resource.get('format'):
resource_dict['format'] = geocat_resource['format']
resource_dict['description'] = geocat_resource.get('description')
Expand Down
4 changes: 2 additions & 2 deletions ckanext/geocat/utils/xpath_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def xpath_get_rights_dict_form_rights_node(node):
if value_locale:
rights_dict[locale.lower()] = _clean_string(value_locale[0])
return rights_dict
except:
except Exception:
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense to log the exception?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To be honest, I'm not sure what kind of exception we could possibly be getting here. :-/ I don't think it's worth logging it, though, because when we use this rights dictionary, we actually only need it to have a valid rights name in one of the languages to get the correct rights id. (Here: https://github.com/opendata-swiss/ckanext-geocat/blob/master/ckanext/geocat/utils/csw_mapping.py#L399.)

return ''


Expand Down Expand Up @@ -376,7 +376,7 @@ def _get_normed_protocol(protocol):

def _clean_string(value):
try:
return re.sub('\s+', ' ', value).strip()
return re.sub(r'\s+', ' ', value).strip()
except TypeError:
return value

Expand Down
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
lxml>=4.6.2
OWSLib==0.18.0
pyproj==1.9.6
python-dateutil==2.8.1
pyyaml==5.4
# TODO: Revert to 5.4 once https://github.com/yaml/pyyaml/issues/724 is fixed
pyyaml==5.3.1
rdflib==5.0.0
Loading
Loading