From a93e608b69a05b278e2d01a36ae67898b1334938 Mon Sep 17 00:00:00 2001 From: avdata99 Date: Fri, 24 Mar 2023 13:32:56 -0300 Subject: [PATCH 01/12] Update tests and add 2.10 checks --- .github/workflows/test.yml | 4 ++-- setup.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5b15fff..c4b3e7b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 @@ -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 }} diff --git a/setup.py b/setup.py index cc3392a..7270d75 100644 --- a/setup.py +++ b/setup.py @@ -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, From c22129388ccac34d18e64772c5f119f4347fe93b Mon Sep 17 00:00:00 2001 From: avdata99 Date: Fri, 24 Mar 2023 13:48:44 -0300 Subject: [PATCH 02/12] Fix CKAN 2.10 test --- .github/workflows/test.yml | 4 +++- README.md | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c4b3e7b..9576821 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 + CKAN__DATAPUSHER__API_TOKEN: XX steps: - uses: actions/checkout@v3 @@ -60,7 +62,7 @@ jobs: 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 -vv --ckan-ini=test.ini --cov=ckanext.envvars --cov-report=xml --cov-append --disable-warnings ckanext/envvars/tests.py - name: Upload coverage report to codecov uses: codecov/codecov-action@v1 with: diff --git a/README.md b/README.md index 31f8691..2c53486 100755 --- a/README.md +++ b/README.md @@ -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, From d2d5841173e2f12b7d605ee18511f3e6529a7cf0 Mon Sep 17 00:00:00 2001 From: avdata99 Date: Fri, 24 Mar 2023 13:59:37 -0300 Subject: [PATCH 03/12] Fix datastore URLs --- ckanext/envvars/tests.py | 8 ++++---- setup.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ckanext/envvars/tests.py b/ckanext/envvars/tests.py index f5b0707..0d49a2c 100644 --- a/ckanext/envvars/tests.py +++ b/ckanext/envvars/tests.py @@ -95,8 +95,8 @@ def test_core_ckan_envvar_values_in_config(self): 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/'), ('CKAN_SMTP_SERVER', 'mail.example.com'), @@ -109,8 +109,8 @@ def test_core_ckan_envvar_values_in_config(self): 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.datastore.write_url'] == 'postgresql://mynewdbwriteurl/' + assert config['ckan.datastore.read_url'] == 'postgresql://mynewdbreadurl/' assert config['ckan.site_id'] == 'my-site' assert config['smtp.server'] == 'mail.example.com' assert config['smtp.starttls'] == 'True' diff --git a/setup.py b/setup.py index 7270d75..0fdf894 100644 --- a/setup.py +++ b/setup.py @@ -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+)', From 72ebbc77054eca56d2925919ed9586b7bdeba44b Mon Sep 17 00:00:00 2001 From: avdata99 Date: Fri, 24 Mar 2023 14:21:33 -0300 Subject: [PATCH 04/12] Skip datastore work from test --- ckanext/envvars/tests.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/ckanext/envvars/tests.py b/ckanext/envvars/tests.py index 0d49a2c..2b67813 100644 --- a/ckanext/envvars/tests.py +++ b/ckanext/envvars/tests.py @@ -1,8 +1,12 @@ import os import pytest -import ckan.plugins as p +try: + from unittest import mock +except ImportError: + import mock +import ckan.plugins as p from ckantoolkit import config import ckantoolkit as toolkit @@ -88,7 +92,8 @@ 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): + @mock.patch('ckanext.datastore.plugin.DatastorePlugin.configure') + def test_core_ckan_envvar_values_in_config(self, datastore_configure): if not toolkit.check_ckan_version('2.4.0'): raise pytest.skip('CKAN version 2.4 or above needed') @@ -103,7 +108,8 @@ def test_core_ckan_envvar_values_in_config(self): ('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'), ] self._setup_env_vars(core_ckan_env_var_list) @@ -117,9 +123,15 @@ def test_core_ckan_envvar_values_in_config(self): assert config['smtp.user'] == 'my_user' assert config['smtp.password'] == 'password' assert config['smtp.mail_from'] == 'server@example.com' + # I'll expect CKAN 2.10 to transform this to an int + if toolkit.check_ckan_version(min_version='2.10'): + assert config['ckan.datasets_per_page'] == 14 + else: + assert config['ckan.datasets_per_page'] == '14' self._teardown_env_vars(core_ckan_env_var_list) + @mock.patch('ckanext.datastore.plugin.DatastorePlugin.configure') def test_core_ckan_envvar_values_in_config_take_precedence(self): '''Core CKAN env var transformations take precedence over this extension''' From 3c2affc351343d2838fc2efd86e84d7a90119b21 Mon Sep 17 00:00:00 2001 From: avdata99 Date: Fri, 24 Mar 2023 14:31:06 -0300 Subject: [PATCH 05/12] Update gh action and drop travis --- .coveragerc | 1 + .github/workflows/test.yml | 10 ++- .travis.yml | 13 --- bin/travis-build.bash | 41 ---------- bin/travis-run.sh | 6 -- ckanext/envvars/tests/__init__.py | 0 ckanext/envvars/tests/test_base.py | 63 +++++++++++++++ .../{tests.py => tests/test_gte_ckan210.py} | 76 ++--------------- ckanext/envvars/tests/test_lte_ckan29.py | 81 +++++++++++++++++++ 9 files changed, 159 insertions(+), 132 deletions(-) delete mode 100644 .travis.yml delete mode 100644 bin/travis-build.bash delete mode 100644 bin/travis-run.sh create mode 100644 ckanext/envvars/tests/__init__.py create mode 100644 ckanext/envvars/tests/test_base.py rename ckanext/envvars/{tests.py => tests/test_gte_ckan210.py} (52%) create mode 100644 ckanext/envvars/tests/test_lte_ckan29.py diff --git a/.coveragerc b/.coveragerc index 895e291..59a7c1e 100644 --- a/.coveragerc +++ b/.coveragerc @@ -3,3 +3,4 @@ omit = */site-packages/* */python?.?/* ckan/* + ckanext/envvars/tests/* diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9576821..27ff7f5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -61,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 -vv --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: diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 42cfed1..0000000 --- a/.travis.yml +++ /dev/null @@ -1,13 +0,0 @@ -language: python -python: - - "2.7" -env: - - PGVERSION=9.1 CKANVERSION=master - - PGVERSION=9.1 CKANVERSION=2.3 -install: - - bash bin/travis-build.bash - - pip install coveralls -script: sh bin/travis-run.sh -after_success: - - coveralls -sudo: required diff --git a/bin/travis-build.bash b/bin/travis-build.bash deleted file mode 100644 index 5b151bd..0000000 --- a/bin/travis-build.bash +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/bash -set -e - -echo "This is travis-build.bash..." - -echo "Installing the packages that CKAN requires..." -sudo apt-get update -qq -sudo apt-get install postgresql-$PGVERSION solr-jetty libcommons-fileupload-java:amd64=1.2.2-1 - -echo "Installing CKAN and its Python dependencies..." -git clone https://github.com/ckan/ckan -cd ckan -if [ $ CKANVERSION == '2.3'] -then - git checkout release-v2.3 -else - git checkout master -fi -python setup.py develop -pip install -r requirements.txt --allow-all-external -pip install -r dev-requirements.txt --allow-all-external -cd - - -echo "Creating the PostgreSQL user and database..." -sudo -u postgres psql -c "CREATE USER ckan_default WITH PASSWORD 'pass';" -sudo -u postgres psql -c 'CREATE DATABASE ckan_test WITH OWNER ckan_default;' - -echo "Initialising the database..." -cd ckan -paster db init -c test-core.ini -cd - - -echo "Installing ckanext-envvars 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 "travis-build.bash is done." diff --git a/bin/travis-run.sh b/bin/travis-run.sh deleted file mode 100644 index d31158e..0000000 --- a/bin/travis-run.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh -e - -echo "NO_START=0\nJETTY_HOST=127.0.0.1\nJETTY_PORT=8983\nJAVA_HOME=$JAVA_HOME" | sudo tee /etc/default/jetty -sudo cp ckan/ckan/config/solr/schema.xml /etc/solr/conf/schema.xml -sudo service jetty restart -nosetests --ckan --nologcapture --with-pylons=subdir/test.ini --with-coverage --cover-package=ckanext.envvars --cover-inclusive --cover-erase --cover-tests diff --git a/ckanext/envvars/tests/__init__.py b/ckanext/envvars/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/ckanext/envvars/tests/test_base.py b/ckanext/envvars/tests/test_base.py new file mode 100644 index 0000000..c6fce29 --- /dev/null +++ b/ckanext/envvars/tests/test_base.py @@ -0,0 +1,63 @@ +import os +import ckan.plugins as p +from ckantoolkit import config +from ckanext.envvars.plugin import EnvvarsPlugin + + +class TestEnvVarToIni(object): + + def test_envvartoini_expected_output(self): + ''' + EnvvarsPlugin._envvar_to_ini returns expected transformation of env + var formated keys + ''' + + envvar_to_ini_examples = [ + ('CKAN___CKAN__SITE_ID', 'ckan.site_id'), + ('CKAN__SITE_ID', 'ckan.site_id'), + ('CKAN___CKANEXT__EXTENSION_SETTING', 'ckanext.extension_setting'), + ('CKANEXT__EXTENSION_SETTING', 'ckanext.extension_setting'), + ('CKAN___BEAKER__SESSION__KEY', 'beaker.session.key'), + ('CKAN___CACHE_DIR', 'cache_dir'), + ('CKAN___CKAN__FEEDS__AUTHORITY_NAME', + 'ckan.feeds.authority_name'), + ('CKAN__FEEDS__AUTHORITY_NAME', 'ckan.feeds.authority_name'), + ] + + for envkey, inikey in envvar_to_ini_examples: + assert EnvvarsPlugin._envvar_to_ini(envkey) == inikey + + +class TestEnvVarsConfig(object): + + def _setup_env_vars(self, envvar_list): + for env_var, value in envvar_list: + os.environ[env_var] = value + # plugin.load() will force the config to update + p.load() + + def _teardown_env_vars(self, envvar_list): + for env_var, _ in envvar_list: + if os.environ.get(env_var, None): + del os.environ[env_var] + # plugin.load() will force the config to update + p.load() + + def test_envvars_values_in_config(self): + envvar_to_ini_examples = [ + ('CKAN__SITE_ID', 'my-envvar-site'), + ('CKAN___CKANEXT__EXTENSION_SETTING', 'my-extension-value'), + ('CKANEXT__ANOTHER__EXT_SETTING', 'my-other-extension-value'), + ('CKAN___BEAKER__SESSION__KEY', 'my-beaker-key'), + ('CKAN___CACHE_DIR', '/cache_directory_path/'), + ] + + 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/' + + self._teardown_env_vars(envvar_to_ini_examples) diff --git a/ckanext/envvars/tests.py b/ckanext/envvars/tests/test_gte_ckan210.py similarity index 52% rename from ckanext/envvars/tests.py rename to ckanext/envvars/tests/test_gte_ckan210.py index 2b67813..e4d0e35 100644 --- a/ckanext/envvars/tests.py +++ b/ckanext/envvars/tests/test_gte_ckan210.py @@ -1,75 +1,15 @@ import os import pytest - -try: - from unittest import mock -except ImportError: - import mock - import ckan.plugins as p from ckantoolkit import config import ckantoolkit as toolkit -from ckanext.envvars.plugin import EnvvarsPlugin - - -class TestEnvVarToIni(object): - - def test_envvartoini_expected_output(self): - ''' - EnvvarsPlugin._envvar_to_ini returns expected transformation of env - var formated keys - ''' - - envvar_to_ini_examples = [ - ('CKAN___CKAN__SITE_ID', 'ckan.site_id'), - ('CKAN__SITE_ID', 'ckan.site_id'), - ('CKAN___CKANEXT__EXTENSION_SETTING', 'ckanext.extension_setting'), - ('CKANEXT__EXTENSION_SETTING', 'ckanext.extension_setting'), - ('CKAN___BEAKER__SESSION__KEY', 'beaker.session.key'), - ('CKAN___CACHE_DIR', 'cache_dir'), - ('CKAN___CKAN__FEEDS__AUTHORITY_NAME', - 'ckan.feeds.authority_name'), - ('CKAN__FEEDS__AUTHORITY_NAME', 'ckan.feeds.authority_name'), - ] - - for envkey, inikey in envvar_to_ini_examples: - assert EnvvarsPlugin._envvar_to_ini(envkey) == inikey - - -class TestEnvVarsConfig(object): - - def _setup_env_vars(self, envvar_list): - for env_var, value in envvar_list: - os.environ[env_var] = value - # plugin.load() will force the config to update - p.load() - - def _teardown_env_vars(self, envvar_list): - for env_var, _ in envvar_list: - if os.environ.get(env_var, None): - del os.environ[env_var] - # plugin.load() will force the config to update - p.load() - - def test_envvars_values_in_config(self): - envvar_to_ini_examples = [ - ('CKAN__SITE_ID', 'my-envvar-site'), - ('CKAN___CKANEXT__EXTENSION_SETTING', 'my-extension-value'), - ('CKANEXT__ANOTHER__EXT_SETTING', 'my-other-extension-value'), - ('CKAN___BEAKER__SESSION__KEY', 'my-beaker-key'), - ('CKAN___CACHE_DIR', '/cache_directory_path/'), - ] - self._setup_env_vars(envvar_to_ini_examples) +if toolkit.check_ckan_version(max_version='2.9.99'): + pytest.skip("Skipping CKAN < 2.10", allow_module_level=True) - 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/' - self._teardown_env_vars(envvar_to_ini_examples) +from unittest import mock class TestCkanCoreEnvVarsConfig(object): @@ -124,21 +64,15 @@ def test_core_ckan_envvar_values_in_config(self, datastore_configure): assert config['smtp.password'] == 'password' assert config['smtp.mail_from'] == 'server@example.com' # I'll expect CKAN 2.10 to transform this to an int - if toolkit.check_ckan_version(min_version='2.10'): - assert config['ckan.datasets_per_page'] == 14 - else: - assert config['ckan.datasets_per_page'] == '14' + assert config['ckan.datasets_per_page'] == 14 self._teardown_env_vars(core_ckan_env_var_list) @mock.patch('ckanext.datastore.plugin.DatastorePlugin.configure') - def test_core_ckan_envvar_values_in_config_take_precedence(self): + 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/'), diff --git a/ckanext/envvars/tests/test_lte_ckan29.py b/ckanext/envvars/tests/test_lte_ckan29.py new file mode 100644 index 0000000..0d0982c --- /dev/null +++ b/ckanext/envvars/tests/test_lte_ckan29.py @@ -0,0 +1,81 @@ + +import os +import pytest +import ckantoolkit as toolkit +import ckan.plugins as p +from ckantoolkit import config + + +if toolkit.check_ckan_version(min_version='2.10'): + pytest.skip("Skipping CKAN >= 2.10", allow_module_level=True) + + +class TestCkanCoreEnvVarsConfig(object): + + ''' + Some values are are transformed into ini settings by core CKAN. These + tests makes sure they still work. + ''' + + def _setup_env_vars(self, envvar_list): + for env_var, value in envvar_list: + os.environ[env_var] = value + # plugin.load() will force the config to update + p.load() + + def _teardown_env_vars(self, envvar_list): + for env_var, _ in envvar_list: + if os.environ.get(env_var, None): + del os.environ[env_var] + # 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') + + core_ckan_env_var_list = [ + ('CKAN_SQLALCHEMY_URL', 'postgresql://mynewsqlurl/'), + ('CKAN_DATASTORE_WRITE_URL', 'http://mynewdbwriteurl/'), + ('CKAN_DATASTORE_READ_URL', 'http://mynewdbreadurl/'), + ('CKAN_SITE_ID', 'my-site'), + ('CKAN_DB', 'postgresql://mydeprectatesqlurl/'), + ('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') + ] + + 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' + + self._teardown_env_vars(core_ckan_env_var_list) + + def test_core_ckan_envvar_values_in_config_take_precedence(self): + '''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/' + + self._teardown_env_vars(combined_list) From 6d6026a4b2798971d5f1d9f60b653ae6547c2da0 Mon Sep 17 00:00:00 2001 From: avdata99 Date: Fri, 24 Mar 2023 16:47:59 -0300 Subject: [PATCH 06/12] Test lists config --- ckanext/envvars/tests/test_gte_ckan210.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ckanext/envvars/tests/test_gte_ckan210.py b/ckanext/envvars/tests/test_gte_ckan210.py index e4d0e35..b156cad 100644 --- a/ckanext/envvars/tests/test_gte_ckan210.py +++ b/ckanext/envvars/tests/test_gte_ckan210.py @@ -49,7 +49,8 @@ def test_core_ckan_envvar_values_in_config(self, datastore_configure): ('CKAN_SMTP_USER', 'my_user'), ('CKAN_SMTP_PASSWORD', 'password'), ('CKAN_SMTP_MAIL_FROM', 'server@example.com'), - ('CKAN__.DATASETS_PER_PAGE', '14'), + ('CKAN__DATASETS_PER_PAGE', '14'), + ('CKAN__HIDE_ACTIVITY_FROM_USERS', 'user1 user2'), ] self._setup_env_vars(core_ckan_env_var_list) @@ -65,6 +66,7 @@ def test_core_ckan_envvar_values_in_config(self, datastore_configure): assert config['smtp.mail_from'] == 'server@example.com' # I'll expect CKAN 2.10 to transform this to an int assert config['ckan.datasets_per_page'] == 14 + assert config['ckan.hide_activity_from_users'] == ['user1', 'user2'] self._teardown_env_vars(core_ckan_env_var_list) From e8de5db63469def365e4df158d76d5707828cc7c Mon Sep 17 00:00:00 2001 From: avdata99 Date: Fri, 24 Mar 2023 17:03:32 -0300 Subject: [PATCH 07/12] Normalize config for CKAN 2.10 --- ckanext/envvars/plugin.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ckanext/envvars/plugin.py b/ckanext/envvars/plugin.py index f97b150..9d48fe6 100644 --- a/ckanext/envvars/plugin.py +++ b/ckanext/envvars/plugin.py @@ -1,8 +1,9 @@ +import logging import os - import ckan.plugins as plugins +import ckantoolkit as toolkit + -import logging log = logging.getLogger(__name__) @@ -35,3 +36,8 @@ def update_config(self, config): # override config settings with new values config.update(dict(ckan_vars)) + + # CKAN 2.10 should normalize config + if toolkit.check_ckan_version(min_version='2.10'): + from ckan.common import config_declaration + config_declaration.normalize(config) From f8f221e09601677f88c3a60f1eb7cd6fb1be68a2 Mon Sep 17 00:00:00 2001 From: avdata99 Date: Tue, 28 Mar 2023 09:22:37 -0300 Subject: [PATCH 08/12] Join tests --- ...{test_gte_ckan210.py => test_core_vars.py} | 23 +++--- ckanext/envvars/tests/test_lte_ckan29.py | 81 ------------------- 2 files changed, 14 insertions(+), 90 deletions(-) rename ckanext/envvars/tests/{test_gte_ckan210.py => test_core_vars.py} (84%) delete mode 100644 ckanext/envvars/tests/test_lte_ckan29.py diff --git a/ckanext/envvars/tests/test_gte_ckan210.py b/ckanext/envvars/tests/test_core_vars.py similarity index 84% rename from ckanext/envvars/tests/test_gte_ckan210.py rename to ckanext/envvars/tests/test_core_vars.py index b156cad..4d5dfc7 100644 --- a/ckanext/envvars/tests/test_gte_ckan210.py +++ b/ckanext/envvars/tests/test_core_vars.py @@ -5,11 +5,10 @@ import ckantoolkit as toolkit -if toolkit.check_ckan_version(max_version='2.9.99'): - pytest.skip("Skipping CKAN < 2.10", allow_module_level=True) - - -from unittest import mock +if toolkit.check_ckan_version(min_version='2.10'): + from unittest import mock +else: + import mock class TestCkanCoreEnvVarsConfig(object): @@ -60,13 +59,19 @@ def test_core_ckan_envvar_values_in_config(self, datastore_configure): assert config['ckan.datastore.read_url'] == 'postgresql://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' - # I'll expect CKAN 2.10 to transform this to an int - assert config['ckan.datasets_per_page'] == 14 - assert config['ckan.hide_activity_from_users'] == ['user1', 'user2'] + + if toolkit.check_ckan_version(min_version='2.10'): + assert config['ckan.datasets_per_page'] == 14 + assert config['ckan.hide_activity_from_users'] == ['user1', 'user2'] + assert config['smtp.starttls'] + else: + assert config['ckan.datasets_per_page'] == '14' + assert config['ckan.hide_activity_from_users'] == 'user1 user2' + assert config['smtp.starttls'] == 'True' self._teardown_env_vars(core_ckan_env_var_list) diff --git a/ckanext/envvars/tests/test_lte_ckan29.py b/ckanext/envvars/tests/test_lte_ckan29.py deleted file mode 100644 index 0d0982c..0000000 --- a/ckanext/envvars/tests/test_lte_ckan29.py +++ /dev/null @@ -1,81 +0,0 @@ - -import os -import pytest -import ckantoolkit as toolkit -import ckan.plugins as p -from ckantoolkit import config - - -if toolkit.check_ckan_version(min_version='2.10'): - pytest.skip("Skipping CKAN >= 2.10", allow_module_level=True) - - -class TestCkanCoreEnvVarsConfig(object): - - ''' - Some values are are transformed into ini settings by core CKAN. These - tests makes sure they still work. - ''' - - def _setup_env_vars(self, envvar_list): - for env_var, value in envvar_list: - os.environ[env_var] = value - # plugin.load() will force the config to update - p.load() - - def _teardown_env_vars(self, envvar_list): - for env_var, _ in envvar_list: - if os.environ.get(env_var, None): - del os.environ[env_var] - # 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') - - core_ckan_env_var_list = [ - ('CKAN_SQLALCHEMY_URL', 'postgresql://mynewsqlurl/'), - ('CKAN_DATASTORE_WRITE_URL', 'http://mynewdbwriteurl/'), - ('CKAN_DATASTORE_READ_URL', 'http://mynewdbreadurl/'), - ('CKAN_SITE_ID', 'my-site'), - ('CKAN_DB', 'postgresql://mydeprectatesqlurl/'), - ('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') - ] - - 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' - - self._teardown_env_vars(core_ckan_env_var_list) - - def test_core_ckan_envvar_values_in_config_take_precedence(self): - '''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/' - - self._teardown_env_vars(combined_list) From fc78d0705f6bfd6aeafce4cb3efccd3af50abc1a Mon Sep 17 00:00:00 2001 From: avdata99 Date: Tue, 28 Mar 2023 09:45:24 -0300 Subject: [PATCH 09/12] Minor fixes and test notes --- .github/workflows/test.yml | 2 +- ckanext/envvars/tests/test_core_vars.py | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 27ff7f5..55d2dc7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -42,7 +42,7 @@ 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 + # required for CKAN 2.10 (if datastore is enabled) CKAN__DATAPUSHER__API_TOKEN: XX steps: diff --git a/ckanext/envvars/tests/test_core_vars.py b/ckanext/envvars/tests/test_core_vars.py index 4d5dfc7..2a2d75b 100644 --- a/ckanext/envvars/tests/test_core_vars.py +++ b/ckanext/envvars/tests/test_core_vars.py @@ -1,5 +1,4 @@ import os -import pytest import ckan.plugins as p from ckantoolkit import config import ckantoolkit as toolkit @@ -31,12 +30,11 @@ def _teardown_env_vars(self, envvar_list): # plugin.load() will force the config to update p.load() + # 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): - if not toolkit.check_ckan_version('2.4.0'): - raise pytest.skip('CKAN version 2.4 or above needed') - core_ckan_env_var_list = [ ('CKAN_SQLALCHEMY_URL', 'postgresql://mynewsqlurl/'), ('CKAN_DATASTORE_WRITE_URL', 'postgresql://mynewdbwriteurl/'), @@ -66,8 +64,8 @@ def test_core_ckan_envvar_values_in_config(self, datastore_configure): if toolkit.check_ckan_version(min_version='2.10'): assert config['ckan.datasets_per_page'] == 14 - assert config['ckan.hide_activity_from_users'] == ['user1', 'user2'] - assert config['smtp.starttls'] + assert config['ckan.hide_activity_from_users'] == ['user1', 'user2'] + assert config['smtp.starttls'] is True else: assert config['ckan.datasets_per_page'] == '14' assert config['ckan.hide_activity_from_users'] == 'user1 user2' From a76e1a94ffd9c01be48ee2a95512d87d88e67456 Mon Sep 17 00:00:00 2001 From: avdata99 Date: Tue, 28 Mar 2023 10:36:07 -0300 Subject: [PATCH 10/12] Fix tests --- ckanext/envvars/tests/test_core_vars.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ckanext/envvars/tests/test_core_vars.py b/ckanext/envvars/tests/test_core_vars.py index 2a2d75b..eadb374 100644 --- a/ckanext/envvars/tests/test_core_vars.py +++ b/ckanext/envvars/tests/test_core_vars.py @@ -41,10 +41,12 @@ def test_core_ckan_envvar_values_in_config(self, datastore_configure): ('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__DATASETS_PER_PAGE', '14'), ('CKAN__HIDE_ACTIVITY_FROM_USERS', 'user1 user2'), @@ -61,15 +63,15 @@ def test_core_ckan_envvar_values_in_config(self, datastore_configure): assert config['smtp.user'] == 'my_user' assert config['smtp.password'] == 'password' assert config['smtp.mail_from'] == 'server@example.com' + # See https://github.com/ckan/ckan/pull/7502 + assert config['smtp.starttls'] == 'True' if toolkit.check_ckan_version(min_version='2.10'): assert config['ckan.datasets_per_page'] == 14 assert config['ckan.hide_activity_from_users'] == ['user1', 'user2'] - assert config['smtp.starttls'] is True else: assert config['ckan.datasets_per_page'] == '14' assert config['ckan.hide_activity_from_users'] == 'user1 user2' - assert config['smtp.starttls'] == 'True' self._teardown_env_vars(core_ckan_env_var_list) From 3c82b909269b8320d32ccc56bdb9df98a08b5a9f Mon Sep 17 00:00:00 2001 From: avdata99 Date: Tue, 28 Mar 2023 11:21:39 -0300 Subject: [PATCH 11/12] Join tests --- ckanext/envvars/tests/test_base.py | 63 --------- ckanext/envvars/tests/test_base_envvars.py | 151 +++++++++++++++++++++ ckanext/envvars/tests/test_core_vars.py | 92 ------------- 3 files changed, 151 insertions(+), 155 deletions(-) delete mode 100644 ckanext/envvars/tests/test_base.py create mode 100644 ckanext/envvars/tests/test_base_envvars.py delete mode 100644 ckanext/envvars/tests/test_core_vars.py diff --git a/ckanext/envvars/tests/test_base.py b/ckanext/envvars/tests/test_base.py deleted file mode 100644 index c6fce29..0000000 --- a/ckanext/envvars/tests/test_base.py +++ /dev/null @@ -1,63 +0,0 @@ -import os -import ckan.plugins as p -from ckantoolkit import config -from ckanext.envvars.plugin import EnvvarsPlugin - - -class TestEnvVarToIni(object): - - def test_envvartoini_expected_output(self): - ''' - EnvvarsPlugin._envvar_to_ini returns expected transformation of env - var formated keys - ''' - - envvar_to_ini_examples = [ - ('CKAN___CKAN__SITE_ID', 'ckan.site_id'), - ('CKAN__SITE_ID', 'ckan.site_id'), - ('CKAN___CKANEXT__EXTENSION_SETTING', 'ckanext.extension_setting'), - ('CKANEXT__EXTENSION_SETTING', 'ckanext.extension_setting'), - ('CKAN___BEAKER__SESSION__KEY', 'beaker.session.key'), - ('CKAN___CACHE_DIR', 'cache_dir'), - ('CKAN___CKAN__FEEDS__AUTHORITY_NAME', - 'ckan.feeds.authority_name'), - ('CKAN__FEEDS__AUTHORITY_NAME', 'ckan.feeds.authority_name'), - ] - - for envkey, inikey in envvar_to_ini_examples: - assert EnvvarsPlugin._envvar_to_ini(envkey) == inikey - - -class TestEnvVarsConfig(object): - - def _setup_env_vars(self, envvar_list): - for env_var, value in envvar_list: - os.environ[env_var] = value - # plugin.load() will force the config to update - p.load() - - def _teardown_env_vars(self, envvar_list): - for env_var, _ in envvar_list: - if os.environ.get(env_var, None): - del os.environ[env_var] - # plugin.load() will force the config to update - p.load() - - def test_envvars_values_in_config(self): - envvar_to_ini_examples = [ - ('CKAN__SITE_ID', 'my-envvar-site'), - ('CKAN___CKANEXT__EXTENSION_SETTING', 'my-extension-value'), - ('CKANEXT__ANOTHER__EXT_SETTING', 'my-other-extension-value'), - ('CKAN___BEAKER__SESSION__KEY', 'my-beaker-key'), - ('CKAN___CACHE_DIR', '/cache_directory_path/'), - ] - - 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/' - - self._teardown_env_vars(envvar_to_ini_examples) diff --git a/ckanext/envvars/tests/test_base_envvars.py b/ckanext/envvars/tests/test_base_envvars.py new file mode 100644 index 0000000..0a33d9f --- /dev/null +++ b/ckanext/envvars/tests/test_base_envvars.py @@ -0,0 +1,151 @@ +import os +import ckan.plugins as p +import ckantoolkit as tk +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): + + def test_envvartoini_expected_output(self): + ''' + EnvvarsPlugin._envvar_to_ini returns expected transformation of env + var formated keys + ''' + + envvar_to_ini_examples = [ + ('CKAN___CKAN__SITE_ID', 'ckan.site_id'), + ('CKAN__SITE_ID', 'ckan.site_id'), + ('CKAN___CKANEXT__EXTENSION_SETTING', 'ckanext.extension_setting'), + ('CKANEXT__EXTENSION_SETTING', 'ckanext.extension_setting'), + ('CKAN___BEAKER__SESSION__KEY', 'beaker.session.key'), + ('CKAN___CACHE_DIR', 'cache_dir'), + ('CKAN___CKAN__FEEDS__AUTHORITY_NAME', + 'ckan.feeds.authority_name'), + ('CKAN__FEEDS__AUTHORITY_NAME', 'ckan.feeds.authority_name'), + ] + + for envkey, inikey in envvar_to_ini_examples: + assert EnvvarsPlugin._envvar_to_ini(envkey) == inikey + + +class TestEnvVarsConfig(object): + + def _setup_env_vars(self, envvar_list): + for env_var, value in envvar_list: + os.environ[env_var] = value + # plugin.load() will force the config to update + p.load() + + def _teardown_env_vars(self, envvar_list): + for env_var, _ in envvar_list: + if os.environ.get(env_var, None): + del os.environ[env_var] + # plugin.load() will force the config to update + p.load() + + def test_envvars_values_in_config(self): + envvar_to_ini_examples = [ + ('CKAN__SITE_ID', 'my-envvar-site'), + ('CKAN___CKANEXT__EXTENSION_SETTING', 'my-extension-value'), + ('CKANEXT__ANOTHER__EXT_SETTING', 'my-other-extension-value'), + ('CKAN___BEAKER__SESSION__KEY', 'my-beaker-key'), + ('CKAN___CACHE_DIR', '/cache_directory_path/'), + ] + + self._setup_env_vars(envvar_to_ini_examples) + + 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) + + +class TestCkanCoreEnvVarsConfig(object): + + ''' + Some values are are transformed into ini settings by core CKAN. These + tests makes sure they still work. + ''' + + def _setup_env_vars(self, envvar_list): + for env_var, value in envvar_list: + os.environ[env_var] = value + # plugin.load() will force the config to update + p.load() + + def _teardown_env_vars(self, envvar_list): + for env_var, _ in envvar_list: + if os.environ.get(env_var, None): + del os.environ[env_var] + # plugin.load() will force the config to update + p.load() + + # 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', '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__DATASETS_PER_PAGE', '14'), + ('CKAN__HIDE_ACTIVITY_FROM_USERS', 'user1 user2'), + ] + + self._setup_env_vars(core_ckan_env_var_list) + + 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) + + @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''' + + combined_list = [ + ('CKAN___SQLALCHEMY__URL', 'postgresql://thisextensionformat/'), + ('CKAN_SQLALCHEMY_URL', 'postgresql://coreckanformat/'), + ] + + self._setup_env_vars(combined_list) + + assert tk.config['sqlalchemy.url'] == 'postgresql://coreckanformat/' + + self._teardown_env_vars(combined_list) diff --git a/ckanext/envvars/tests/test_core_vars.py b/ckanext/envvars/tests/test_core_vars.py deleted file mode 100644 index eadb374..0000000 --- a/ckanext/envvars/tests/test_core_vars.py +++ /dev/null @@ -1,92 +0,0 @@ -import os -import ckan.plugins as p -from ckantoolkit import config -import ckantoolkit as toolkit - - -if toolkit.check_ckan_version(min_version='2.10'): - from unittest import mock -else: - import mock - - -class TestCkanCoreEnvVarsConfig(object): - - ''' - Some values are are transformed into ini settings by core CKAN. These - tests makes sure they still work. - ''' - - def _setup_env_vars(self, envvar_list): - for env_var, value in envvar_list: - os.environ[env_var] = value - # plugin.load() will force the config to update - p.load() - - def _teardown_env_vars(self, envvar_list): - for env_var, _ in envvar_list: - if os.environ.get(env_var, None): - del os.environ[env_var] - # plugin.load() will force the config to update - p.load() - - # 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', '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__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'] == 'postgresql://mynewdbwriteurl/' - assert config['ckan.datastore.read_url'] == 'postgresql://mynewdbreadurl/' - assert config['ckan.site_id'] == 'my-site' - assert config['smtp.server'] == 'mail.example.com' - - assert config['smtp.user'] == 'my_user' - assert config['smtp.password'] == 'password' - assert config['smtp.mail_from'] == 'server@example.com' - # See https://github.com/ckan/ckan/pull/7502 - assert config['smtp.starttls'] == 'True' - - if toolkit.check_ckan_version(min_version='2.10'): - assert config['ckan.datasets_per_page'] == 14 - assert config['ckan.hide_activity_from_users'] == ['user1', 'user2'] - else: - assert config['ckan.datasets_per_page'] == '14' - assert config['ckan.hide_activity_from_users'] == 'user1 user2' - - self._teardown_env_vars(core_ckan_env_var_list) - - @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''' - - combined_list = [ - ('CKAN___SQLALCHEMY__URL', 'postgresql://thisextensionformat/'), - ('CKAN_SQLALCHEMY_URL', 'postgresql://coreckanformat/'), - ] - - self._setup_env_vars(combined_list) - - assert config['sqlalchemy.url'] == 'postgresql://coreckanformat/' - - self._teardown_env_vars(combined_list) From 81a8e0c308288c089e6f6ab399d0b9a6a6907696 Mon Sep 17 00:00:00 2001 From: Andres Vazquez Date: Tue, 28 Mar 2023 08:32:10 -0300 Subject: [PATCH 12/12] Update ckanext/envvars/plugin.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: AdriĆ  Mercader --- ckanext/envvars/plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ckanext/envvars/plugin.py b/ckanext/envvars/plugin.py index 9d48fe6..87b0f02 100644 --- a/ckanext/envvars/plugin.py +++ b/ckanext/envvars/plugin.py @@ -37,7 +37,7 @@ def update_config(self, config): # override config settings with new values config.update(dict(ckan_vars)) - # CKAN 2.10 should normalize config + # 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)