Skip to content

Commit

Permalink
Merge pull request #6 from okfn/ckan2.10_update
Browse files Browse the repository at this point in the history
CKAN 2.10 update
  • Loading branch information
amercader authored Mar 28, 2023
2 parents c892ccb + 81a8e0c commit 326dc6f
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 99 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ omit =
*/site-packages/*
*/python?.?/*
ckan/*
ckanext/envvars/tests/*
16 changes: 13 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v2
with:
python-version: '3.6'
python-version: '3.8'
- name: Install requirements
run: pip install flake8 pycodestyle
- name: Check syntax
Expand All @@ -17,7 +17,7 @@ jobs:
needs: lint
strategy:
matrix:
ckan-version: [2.9, 2.9-py2, 2.8, 2.7]
ckan-version: ["2.10", 2.9, 2.9-py2, 2.8, 2.7]
fail-fast: false

name: CKAN ${{ matrix.ckan-version }}
Expand All @@ -42,6 +42,8 @@ jobs:
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
# required for CKAN 2.10 (if datastore is enabled)
CKAN__DATAPUSHER__API_TOKEN: XX

steps:
- uses: actions/checkout@v3
Expand All @@ -59,8 +61,16 @@ jobs:
if: ${{ matrix.ckan-version == '2.7' || matrix.ckan-version == '2.8' }}
run: |
paster --plugin=ckan db init -c test.ini
- name: Run tests
run: pytest --ckan-ini=test.ini --cov=ckanext.envvars --cov-report=xml --cov-append --disable-warnings ckanext/envvars/tests.py
run: |
pytest -v --ckan-ini=test.ini \
--cov=ckanext.envvars \
--cov-report=xml \
--cov-append \
--disable-warnings \
ckanext/envvars/tests/
- name: Upload coverage report to codecov
uses: codecov/codecov-action@v1
with:
Expand Down
13 changes: 0 additions & 13 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ e.g.:
Requirements
------------

Tested in CKAN 2.7, CKAN 2.8 and CKAN 2.9, but may work in other
Tested in CKAN 2.7, CKAN 2.8, CKAN 2.9 and CKAN 2.10, but may work in other
versions.

To ensure all config settings are overridden by env var values,
Expand Down
41 changes: 0 additions & 41 deletions bin/travis-build.bash

This file was deleted.

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

This file was deleted.

10 changes: 8 additions & 2 deletions ckanext/envvars/plugin.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import logging
import os

import ckan.plugins as plugins
import ckantoolkit as toolkit


import logging
log = logging.getLogger(__name__)


Expand Down Expand Up @@ -35,3 +36,8 @@ def update_config(self, config):

# override config settings with new values
config.update(dict(ckan_vars))

# CKAN >=2.10 normalizes config values
if toolkit.check_ckan_version(min_version='2.10'):
from ckan.common import config_declaration
config_declaration.normalize(config)
Empty file.
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import os
import pytest

import ckan.plugins as p
import ckantoolkit as tk
from ckanext.envvars.plugin import EnvvarsPlugin

from ckantoolkit import config
import ckantoolkit as toolkit

from ckanext.envvars.plugin import EnvvarsPlugin
if tk.check_ckan_version(min_version='2.10'):
from unittest import mock
else:
import mock


class TestEnvVarToIni(object):
Expand Down Expand Up @@ -59,11 +60,11 @@ def test_envvars_values_in_config(self):

self._setup_env_vars(envvar_to_ini_examples)

assert config['ckan.site_id'] == 'my-envvar-site'
assert config['ckanext.extension_setting'] == 'my-extension-value'
assert config['ckanext.another.ext_setting'] == 'my-other-extension-value'
assert config['beaker.session.key'] == 'my-beaker-key'
assert config['cache_dir'] == '/cache_directory_path/'
assert tk.config['ckan.site_id'] == 'my-envvar-site'
assert tk.config['ckanext.extension_setting'] == 'my-extension-value'
assert tk.config['ckanext.another.ext_setting'] == 'my-other-extension-value'
assert tk.config['beaker.session.key'] == 'my-beaker-key'
assert tk.config['cache_dir'] == '/cache_directory_path/'

self._teardown_env_vars(envvar_to_ini_examples)

Expand All @@ -88,52 +89,63 @@ def _teardown_env_vars(self, envvar_list):
# plugin.load() will force the config to update
p.load()

def test_core_ckan_envvar_values_in_config(self):

if not toolkit.check_ckan_version('2.4.0'):
raise pytest.skip('CKAN version 2.4 or above needed')
# The datastore plugin, only for CKAN 2.10+, will try to
# connect to the database when it is loaded.
@mock.patch('ckanext.datastore.plugin.DatastorePlugin.configure')
def test_core_ckan_envvar_values_in_config(self, datastore_configure):

core_ckan_env_var_list = [
('CKAN_SQLALCHEMY_URL', 'postgresql://mynewsqlurl/'),
('CKAN_DATASTORE_WRITE_URL', 'http://mynewdbwriteurl/'),
('CKAN_DATASTORE_READ_URL', 'http://mynewdbreadurl/'),
('CKAN_DATASTORE_WRITE_URL', 'postgresql://mynewdbwriteurl/'),
('CKAN_DATASTORE_READ_URL', 'postgresql://mynewdbreadurl/'),
('CKAN_SITE_ID', 'my-site'),
('CKAN_DB', 'postgresql://mydeprectatesqlurl/'),
# SMTP settings takes precedence from CKAN core CONFIG_FROM_ENV_VARS
('CKAN_SMTP_SERVER', 'mail.example.com'),
('CKAN_SMTP_STARTTLS', 'True'),
('CKAN_SMTP_USER', 'my_user'),
('CKAN_SMTP_PASSWORD', 'password'),
('CKAN_SMTP_MAIL_FROM', 'server@example.com')

('CKAN_SMTP_MAIL_FROM', 'server@example.com'),
('CKAN__DATASETS_PER_PAGE', '14'),
('CKAN__HIDE_ACTIVITY_FROM_USERS', 'user1 user2'),
]

self._setup_env_vars(core_ckan_env_var_list)

assert config['sqlalchemy.url'] == 'postgresql://mynewsqlurl/'
assert config['ckan.datastore.write_url'] == 'http://mynewdbwriteurl/'
assert config['ckan.datastore.read_url'] == 'http://mynewdbreadurl/'
assert config['ckan.site_id'] == 'my-site'
assert config['smtp.server'] == 'mail.example.com'
assert config['smtp.starttls'] == 'True'
assert config['smtp.user'] == 'my_user'
assert config['smtp.password'] == 'password'
assert config['smtp.mail_from'] == 'server@example.com'
assert tk.config['sqlalchemy.url'] == 'postgresql://mynewsqlurl/'
assert tk.config['ckan.datastore.write_url'] == 'postgresql://mynewdbwriteurl/'
assert tk.config['ckan.datastore.read_url'] == 'postgresql://mynewdbreadurl/'
assert tk.config['ckan.site_id'] == 'my-site'
assert tk.config['smtp.server'] == 'mail.example.com'

assert tk.config['smtp.user'] == 'my_user'
assert tk.config['smtp.password'] == 'password'
assert tk.config['smtp.mail_from'] == 'server@example.com'
# See https://github.com/ckan/ckan/pull/7502
assert tk.config['smtp.starttls'] == 'True'

if tk.check_ckan_version(min_version='2.10'):
assert tk.config['ckan.datasets_per_page'] == 14
assert tk.config['ckan.hide_activity_from_users'] == ['user1', 'user2']
else:
assert tk.config['ckan.datasets_per_page'] == '14'
assert tk.config['ckan.hide_activity_from_users'] == 'user1 user2'

self._teardown_env_vars(core_ckan_env_var_list)

def test_core_ckan_envvar_values_in_config_take_precedence(self):
@mock.patch('ckanext.datastore.plugin.DatastorePlugin.configure')
def test_core_ckan_envvar_values_in_config_take_precedence(self, datastore_configure):
'''Core CKAN env var transformations take precedence over this
extension'''

if not toolkit.check_ckan_version('2.4.0'):
raise pytest.skip('CKAN version 2.4 or above needed')

combined_list = [
('CKAN___SQLALCHEMY__URL', 'postgresql://thisextensionformat/'),
('CKAN_SQLALCHEMY_URL', 'postgresql://coreckanformat/'),
]

self._setup_env_vars(combined_list)

assert config['sqlalchemy.url'] == 'postgresql://coreckanformat/'
assert tk.config['sqlalchemy.url'] == 'postgresql://coreckanformat/'

self._teardown_env_vars(combined_list)
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,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.2',
version='0.0.3',

description='''CKAN configuration settings available from env vars''',
long_description=long_description,
Expand All @@ -35,7 +35,7 @@
# 3 - Alpha
# 4 - Beta
# 5 - Production/Stable
'Development Status :: 4 - Beta',
'Development Status :: 5 - Production/Stable',

# Pick your license as you wish (should match "license" above)
'License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)',
Expand Down

0 comments on commit 326dc6f

Please sign in to comment.