Commit b78e1e2a authored by thepaeth's avatar thepaeth
Browse files

init project

omit =
name: Tests
on: [push, pull_request]
runs-on: ubuntu-latest
# 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: ckan/ckan-solr-dev:2.9
image: ckan/ckan-postgres-dev:2.9
POSTGRES_DB: postgres
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
image: redis:3
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
- uses: actions/checkout@v2
- name: Install requirements
# Install any extra requirements your extension has here (dev requirements, other extensions etc)
run: |
pip install -r requirements.txt
pip install -r dev-requirements.txt
pip install -e .
- name: Setup extension
# Extra initialization steps
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
ckan -c test.ini db init
- name: Run tests
run: pytest --ckan-ini=test.ini --cov=ckanext.dataplatform --disable-warnings ckanext/dataplatform
# Byte-compiled / optimized / DLL files
# C extensions
# Distribution / packaging
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
# Installer logs
# Unit test / coverage reports
# Sphinx documentation
This diff is collapsed.
include README.rst
include LICENSE
include requirements.txt
recursive-include ckanext/dataplatform *.html *.json *.js *.less *.css *.mo
# ckanext-dataplatform
**TODO:** Put a description of your extension here: What does it do? What features does it have? Consider including some screenshots or embedding a video!
## Requirements
**TODO:** For example, you might want to mention here which versions of CKAN this
extension works with.
If your extension works across different versions you can add the following table:
Compatibility with core CKAN versions:
| CKAN version | Compatible? |
| --------------- | ------------- |
| 2.6 and earlier | not tested |
| 2.7 | not tested |
| 2.8 | not tested |
| 2.9 | not tested |
Suggested values:
* "yes"
* "not tested" - I can't think of a reason why it wouldn't work
* "not yet" - there is an intention to get it working
* "no"
## Installation
**TODO:** Add any additional install steps to the list below.
For example installing any non-Python dependencies or adding any required
config settings.
To install ckanext-dataplatform:
1. Activate your CKAN virtual environment, for example:
. /usr/lib/ckan/default/bin/activate
2. Clone the source and install it on the virtualenv
git clone
cd ckanext-dataplatform
pip install -e .
pip install -r requirements.txt
3. Add `dataplatform` to the `ckan.plugins` setting in your CKAN
config file (by default the config file is located at
4. Restart CKAN. For example if you've deployed CKAN with Apache on Ubuntu:
sudo service apache2 reload
## Config settings
None at present
**TODO:** Document any optional config settings here. For example:
# The minimum number of hours to wait before re-checking a resource
# (optional, default: 24).
ckanext.dataplatform.some_setting = some_default_value
## Developer installation
To install ckanext-dataplatform for development, activate your CKAN virtualenv and
git clone
cd ckanext-dataplatform
python develop
pip install -r dev-requirements.txt
## Tests
To run the tests, do:
pytest --ckan-ini=test.ini
## Releasing a new version of ckanext-dataplatform
If ckanext-dataplatform should be available on PyPI you can follow these steps to publish a new version:
1. Update the version number in the `` file. See [PEP 440]( for how to choose version numbers.
2. Make sure you have the latest version of necessary packages:
pip install --upgrade setuptools wheel twine
3. Create a source and binary distributions of the new version:
python sdist bdist_wheel && twine check dist/*
Fix any errors you get.
4. Upload the source distribution to PyPI:
twine upload dist/*
5. Commit any outstanding changes:
git commit -a
git push
6. Tag the new release of the project on GitHub with the version number from
the `` file. For example if the version number in `` is
0.0.1 then do:
git tag 0.0.1
git push --tags
## License
# encoding: utf-8
# this is a namespace package
import pkg_resources
except ImportError:
import pkgutil
__path__ = pkgutil.extend_path(__path__, __name__)
import ckan.plugins as plugins
import ckan.plugins.toolkit as toolkit
class DataplatformPlugin(plugins.SingletonPlugin):
# IConfigurer
def update_config(self, config_):
toolkit.add_template_directory(config_, 'templates')
toolkit.add_public_directory(config_, 'public')
Tests for
Tests are written using the pytest library (, and you
should read the testing guidelines in the CKAN docs:
To write tests for your extension you should install the pytest-ckan package:
pip install pytest-ckan
This will allow you to use CKAN specific fixtures on your tests.
For instance, if your test involves database access you can use `clean_db` to
reset the database:
import pytest
from ckan.tests import factories
def test_some_action():
dataset = factories.Dataset()
# ...
For functional tests that involve requests to the application, you can use the
`app` fixture:
from ckan.plugins import toolkit
def test_some_endpoint(app):
url = toolkit.url_for('myblueprint.some_endpoint')
response = app.get(url)
assert response.status_code == 200
To temporary patch the CKAN configuration for the duration of a test you can use:
import pytest
@pytest.mark.ckan_config("ckanext.myext.some_key", "some_value")
def test_some_action():
import ckanext.dataplatform.plugin as plugin
def test_plugin():
keywords = translate isPlural
add_comments = TRANSLATORS:
output_file = ckanext/dataplatform/i18n/ckanext-dataplatform.pot
width = 80
domain = ckanext-dataplatform
input_file = ckanext/dataplatform/i18n/ckanext-dataplatform.pot
output_dir = ckanext/dataplatform/i18n
domain = ckanext-dataplatform
input_file = ckanext/dataplatform/i18n/ckanext-dataplatform.pot
output_dir = ckanext/dataplatform/i18n
previous = true
domain = ckanext-dataplatform
directory = ckanext/dataplatform/i18n
statistics = true
# -*- coding: utf-8 -*-
# Always prefer setuptools over distutils
from setuptools import setup, find_packages
from codecs import open # To use a consistent encoding
from os import path
here = path.abspath(path.dirname(__file__))
# Get the long description from the relevant file
with open(path.join(here, ''), encoding='utf-8') as f:
long_description =
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across and the project code, see
# The project's main homepage.
# Author details
# Choose your license
# See
# How mature is this project? Common values are
# 3 - Alpha
# 4 - Beta
# 5 - Production/Stable
'Development Status :: 4 - Beta',
# Pick your license as you wish (should match "license" above)
'License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)',
# Specify the Python versions you support here. In particular, ensure
# that you indicate whether you support Python 2, Python 3 or both.
'Programming Language :: Python :: 2.7',
# What does your project relate to?
# You can just specify the packages manually here if your project is
# simple. Or you can use find_packages().
packages=find_packages(exclude=['contrib', 'docs', 'tests*']),
# CKAN extensions should not list dependencies here, but in a separate
# ``requirements.txt`` file.
# add-third-party-libraries-to-requirements-txt
# If there are data files included in your packages that need to be
# installed, specify them here. If using Python 2.6 or less, then these
# have to be included in as well.
# Although 'package_data' is the preferred approach, in some case you may
# need to place data files outside of your packages.
# see
# installing-additional-files
# In this case, 'data_file' will be installed into '<sys.prefix>/my_data'
# To provide executable scripts, use entry points in preference to the
# "scripts" keyword. Entry points provide cross-platform support and allow
# pip to create the appropriate form of executable for the target platform.
ckan = ckan.lib.extract:extract_ckan
# If you are changing from the default layout of your extension, you may
# have to change the message extractors, you can read more about babel
# message extraction at
'ckanext': [
('**.py', 'python', None),
('**.js', 'javascript', None),
('**/templates/**.html', 'ckan', None),
debug = false
smtp_server = localhost
error_email_from = ckan@localhost
use = config:../ckan/test-core.ini
# Insert any custom config settings to be used when running your extension's
# tests here. These will override the one defined in CKAN core's test-core.ini
ckan.plugins = dataplatform
# Logging configuration
keys = root, ckan, sqlalchemy
keys = console
keys = generic
level = WARN
handlers = console
qualname = ckan
handlers =
level = INFO
handlers =
qualname = sqlalchemy.engine
level = WARN
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic
format = %(asctime)s %(levelname)-5.5s [%(name)s] %(message)s
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment