-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1ae5c4e
commit bfc1105
Showing
7 changed files
with
257 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: main | ||
tags: | ||
- 'v*' | ||
pull_request: | ||
branches: main | ||
|
||
env: | ||
CKANVERSION: 2.9 | ||
|
||
jobs: | ||
code_quality: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Setup Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.8' | ||
|
||
- name: Install flake8 | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install flake8 | ||
- name: Lint with flake8 | ||
run: | | ||
flake8 . --count --max-complexity=10 --max-line-length=127 --statistics --exclude ckan,ckanext-resourcedictionary | ||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: [ '3.6', '3.7', '3.8' ] | ||
name: Python ${{ matrix.python-version }} extension test | ||
|
||
services: | ||
postgresql: | ||
image: postgres | ||
env: | ||
POSTGRES_PASSWORD: postgres | ||
options: >- | ||
--health-cmd pg_isready | ||
--health-interval 10s | ||
--health-timeout 5s | ||
--health-retries 5 | ||
ports: | ||
- 5432:5432 | ||
|
||
redis: | ||
image: redis | ||
options: >- | ||
--health-cmd "redis-cli ping" | ||
--health-interval 10s | ||
--health-timeout 5s | ||
--health-retries 5 | ||
ports: | ||
- 6379:6379 | ||
|
||
ckan-solr: | ||
# Workflow level env variables are not addressable on job level, only on steps level | ||
# image: ghcr.io/keitaroinc/ckan-solr-dev:{{ env.CKANVERSION }} | ||
image: ghcr.io/keitaroinc/ckan-solr-dev:2.9 | ||
ports: | ||
- 8983:8983 | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Setup Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
architecture: x64 | ||
|
||
- name: Install pytest | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install pytest | ||
- name: Setup CKAN | ||
env: | ||
PGPASSWORD: postgres | ||
run: | | ||
bash bin/setup-ckan.bash | ||
- name: Test with pytest | ||
run: | | ||
pytest --ckan-ini=subdir/test.ini --cov=ckanext.resourcedictionary --disable-warnings ckanext/resourcedictionary/tests | ||
- name: Coveralls | ||
uses: AndreMiras/coveralls-python-action@develop | ||
with: | ||
parallel: true | ||
flag-name: Python ${{ matrix.python-version }} Unit Test | ||
|
||
publish: | ||
needs: test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Setup Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.8' | ||
|
||
- name: Install setup requirements | ||
run: | | ||
python -m pip install --upgrade setuptools wheel twine | ||
- name: Build and package | ||
run: | | ||
python setup.py sdist bdist_wheel | ||
twine check dist/* | ||
- name: Publish package | ||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') | ||
uses: pypa/gh-action-pypi-publish@release/v1 | ||
with: | ||
user: __token__ | ||
password: ${{ secrets.PYPI_API_TOKEN }} | ||
|
||
coveralls_finish: | ||
needs: test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Coveralls Finished | ||
uses: AndreMiras/coveralls-python-action@develop | ||
with: | ||
parallel-finished: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
echo "This is setup-ckan.bash..." | ||
|
||
echo "Installing the packages that CKAN requires..." | ||
sudo apt-get update -qq | ||
sudo apt-get install xmlsec1 libxmlsec1-dev | ||
|
||
echo "Installing CKAN and its Python dependencies..." | ||
git clone https://github.com/ckan/ckan | ||
cd ckan | ||
if [ $CKANVERSION == 'master' ] | ||
then | ||
echo "CKAN version: master" | ||
else | ||
CKAN_TAG=$(git tag | grep ^ckan-$CKANVERSION | sort --version-sort | tail -n 1) | ||
git checkout $CKAN_TAG | ||
echo "CKAN version: ${CKAN_TAG#ckan-}" | ||
fi | ||
|
||
# install the recommended version of setuptools | ||
if [ -f requirement-setuptools.txt ] | ||
then | ||
echo "Updating setuptools..." | ||
pip install -r requirement-setuptools.txt | ||
fi | ||
|
||
if [ $CKANVERSION == '2.7' ] | ||
then | ||
echo "Installing setuptools" | ||
pip install setuptools==39.0.1 | ||
fi | ||
|
||
python setup.py develop | ||
pip install -r requirements.txt | ||
pip install -r dev-requirements.txt | ||
cd - | ||
|
||
echo "Creating the PostgreSQL user and database..." | ||
psql -h localhost -U postgres -c "CREATE USER ckan_default WITH PASSWORD 'pass';" | ||
psql -h localhost -U postgres -c "CREATE USER datastore_default WITH PASSWORD 'pass';" | ||
psql -h localhost -U postgres -c 'CREATE DATABASE ckan_test WITH OWNER ckan_default;' | ||
psql -h localhost -U postgres -c 'CREATE DATABASE datastore_default WITH OWNER ckan_default;' | ||
|
||
echo "Setting datastore permissions..." | ||
cd ckan | ||
ckan -c test-core.ini datastore set-permissions | ||
|
||
echo "Initialising the database..." | ||
ckan -c test-core.ini db init | ||
cd - | ||
|
||
echo "Installing ckanext-resourcedictionary and its requirements..." | ||
python setup.py develop | ||
pip install -r dev-requirements.txt | ||
|
||
echo "Moving test.ini into a subdir..." | ||
mkdir subdir | ||
mv test.ini subdir | ||
|
||
echo "setup-ckan.bash is done." |
This file was deleted.
Oops, something went wrong.
61 changes: 56 additions & 5 deletions
61
ckanext/resourcedictionary/tests/views/test_resource_dictionary.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,63 @@ | ||
# encoding: utf-8 | ||
import six | ||
import pytest | ||
|
||
from ckan.tests import factories | ||
from ckan.plugins import toolkit | ||
import ckan.tests.helpers as h | ||
from ckan.lib.helpers import url_for | ||
|
||
|
||
@pytest.mark.ckan_config("ckan.plugins", "datastore") | ||
@pytest.mark.usefixtures(u'clean_db', u'clean_index', | ||
u'clean_datastore', u'with_plugins') | ||
def test_create(self, app): | ||
pass | ||
u'clean_datastore',) | ||
def test_create_new_resource_dictionary_successfully(app): | ||
|
||
user = factories.Sysadmin() | ||
env = {u'REMOTE_USER': six.ensure_str(user[u'name'])} | ||
|
||
context = { | ||
u'user': six.ensure_str(user[u'name']), | ||
u'ignore_auth': True | ||
} | ||
users = [{ | ||
u'name': six.ensure_str(user[u'name']), | ||
u'capacity': 'admin' | ||
}] | ||
|
||
organization = h.call_action(u'organization_create', | ||
context, | ||
name='organization', | ||
users=users) | ||
|
||
package = h.call_action(u'package_create', | ||
context, | ||
name=u'package', | ||
owner_org=organization[u'id']) | ||
|
||
resource = h.call_action(u'resource_create', | ||
context, | ||
name=u'resource', | ||
package_id=package[u'id']) | ||
|
||
post_data = { | ||
u'field__1__id': u'Name', | ||
u'info__1__type': u'text', | ||
u'info__1__type_override': u'', | ||
u'info__1__label': u'Name Label', | ||
u'info__1__notes': u'Name Field Description', | ||
u'field__2__id': u'Lastname', | ||
u'info__2__type': u'text', | ||
u'info__2__type_override': u'', | ||
u'info__2__label': u'Lastname Label', | ||
u'info__2__notes': u'Lastname Field Description', | ||
} | ||
|
||
url = url_for(u'resource_dictionary.dictionary', | ||
id=package[u'id'], | ||
resource_id=resource[u'id']) | ||
|
||
res = app.post( | ||
url, | ||
data=post_data, | ||
extra_environ=env | ||
) | ||
assert 200 == res.status_code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
pytest_plugins = [ | ||
u'ckanext.resourcedictionary.tests.fixtures', | ||
u'ckanext.datastore.tests.conftest', | ||
u'ckan.tests.pytest_ckan.ckan_setup', | ||
u'ckan.tests.pytest_ckan.fixtures', | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters