From ec5b8d2ac2c0a3b7d7778652e025631a329ee16d Mon Sep 17 00:00:00 2001 From: Ian Ward Date: Wed, 3 Apr 2024 11:23:48 -0400 Subject: [PATCH] drop ckan 2.8 test support --- .github/workflows/test.yml | 10 ++----- README.md | 4 +-- ckanext/scheming/tests/mock_pylons_request.py | 26 ----------------- ckanext/scheming/tests/test_form.py | 28 ++----------------- ckanext/scheming/tests/test_form_snippets.py | 23 +++++---------- ckanext/scheming/tests/test_validation.py | 26 +++++++---------- 6 files changed, 24 insertions(+), 93 deletions(-) delete mode 100644 ckanext/scheming/tests/mock_pylons_request.py diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8c146062..7f9810da 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,7 +17,7 @@ jobs: needs: lint strategy: matrix: - ckan-version: ["2.10", 2.9, 2.9-py2, 2.8] + ckan-version: ["2.10", "2.9", "2.9-py2"] fail-fast: false name: CKAN ${{ matrix.ckan-version }} @@ -51,16 +51,10 @@ jobs: # 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 sed -i -e 's/use = config:.*/use = config:\/srv\/app\/src\/ckan\/test-core.ini/' test_subclass.ini - - name: Setup extension (CKAN >= 2.9) - if: ${{ matrix.ckan-version != '2.8' }} + - name: Setup extension run: | pip install -r test-requirements.txt ckan -c test.ini db init - - name: Setup extension (CKAN < 2.9) - if: ${{ matrix.ckan-version == '2.8' }} - run: | - pip install -r test-requirements-py2.txt - paster --plugin=ckan db init -c test.ini - name: Run all tests run: pytest --ckan-ini=test.ini --cov=ckanext.scheming ckanext/scheming/tests - name: Run plugin subclassing tests diff --git a/README.md b/README.md index 8773b3ef..1b6ce2b8 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ Table of contents: Requirements ============ -This plugin is compatible with CKAN 2.8 or later. +This plugin is compatible with CKAN 2.9 or later. Installation @@ -397,7 +397,7 @@ If a choices list is not provided you must provide a `choices_helper` function that will return a list of choices in the same format as the `choices` list above. -You may [register your own helper function](https://docs.ckan.org/en/2.8/theming/templates.html#adding-your-own-template-helper-functions) or use the +You may [register your own helper function](https://docs.ckan.org/en/2.9/theming/templates.html#adding-your-own-template-helper-functions) or use the `scheming_datastore_choices` helper included in ckanext-scheming: ```yaml diff --git a/ckanext/scheming/tests/mock_pylons_request.py b/ckanext/scheming/tests/mock_pylons_request.py deleted file mode 100644 index 75f47409..00000000 --- a/ckanext/scheming/tests/mock_pylons_request.py +++ /dev/null @@ -1,26 +0,0 @@ -from contextlib import contextmanager - -import pylons - -class FakeSession(object): - last_accessed = None - -class FakeRequest(object): - def __init__(self): - self.environ = {} - self.params = {} - -@contextmanager -def mock_pylons_request(): - # enough pylons to render a snippet - pylons.response._push_object(pylons.Response()) - pylons.request._push_object(FakeRequest()) - pylons.session._push_object(FakeSession()) - pylons.tmpl_context._push_object({}) - pylons.url._push_object(None) - yield - pylons.response._pop_object() - pylons.request._pop_object() - pylons.session._pop_object() - pylons.tmpl_context._pop_object() - pylons.url._pop_object() diff --git a/ckanext/scheming/tests/test_form.py b/ckanext/scheming/tests/test_form.py index f38b15ca..b441ba8d 100644 --- a/ckanext/scheming/tests/test_form.py +++ b/ckanext/scheming/tests/test_form.py @@ -31,21 +31,14 @@ def _get_package_update_page(app, id, env): def _get_resource_new_page(app, id, env): - if ckantoolkit.check_ckan_version(min_version="2.9"): - url = '/dataset/{}/resource/new'.format(id) - else: - url = '/dataset/new_resource/{}'.format(id) - + url = '/dataset/{}/resource/new'.format(id) return app.get( url, extra_environ=env ) def _get_resource_update_page(app, id, resource_id, env): - if ckantoolkit.check_ckan_version(min_version="2.9"): - url = '/dataset/{}/resource/{}/edit'.format(id, resource_id) - else: - url = '/dataset/{}/resource_edit/{}'.format(id, resource_id) + url = '/dataset/{}/resource/{}/edit'.format(id, resource_id) return app.get( url, extra_environ=env, ) @@ -76,10 +69,7 @@ def test_dataset_form_slug_says_dataset(self, app, sysadmin_env): def test_resource_form_includes_custom_fields(self, app, sysadmin_env): dataset = Dataset(type="test-schema", name="resource-includes-custom") - if ckantoolkit.check_ckan_version(min_version="2.9"): - url = '/dataset/{}/resource/new'.format(dataset["id"]) - else: - url = '/dataset/new_resource/{}'.format(dataset["id"]) + url = '/dataset/{}/resource/new'.format(dataset["id"]) response = app.get( url, @@ -121,10 +111,6 @@ def test_organization_form_slug_says_organization(self, app, sysadmin_env): @pytest.mark.usefixtures("clean_db") class TestGroupFormNew(object): - @pytest.mark.skipif( - not ckantoolkit.check_ckan_version(min_version="2.7.0"), - reason="Unspecified" - ) def test_group_form_includes_custom_field(self, app, sysadmin_env): response = _get_group_new_page(app, sysadmin_env) @@ -144,10 +130,6 @@ def test_group_form_slug_says_group(self, app, sysadmin_env): @pytest.mark.usefixtures("clean_db") class TestCustomGroupFormNew(object): - @pytest.mark.skipif( - not ckantoolkit.check_ckan_version(min_version="2.8.0"), - reason="Unspecified" - ) def test_group_form_includes_custom_field(self, app, sysadmin_env): response = _get_group_new_page(app, sysadmin_env, "theme") form = BeautifulSoup(response.body).select("form")[1] @@ -162,10 +144,6 @@ def test_group_form_slug_uses_custom_type(self, app, sysadmin_env): @pytest.mark.usefixtures("clean_db") class TestCustomOrgFormNew(object): - @pytest.mark.skipif( - not ckantoolkit.check_ckan_version(min_version="2.8.0"), - reason="Unspecified" - ) def test_org_form_includes_custom_field(self, app, sysadmin_env): response = _get_organization_new_page( app, sysadmin_env, "publisher" diff --git a/ckanext/scheming/tests/test_form_snippets.py b/ckanext/scheming/tests/test_form_snippets.py index 4ec1e2a7..1e464ec7 100644 --- a/ckanext/scheming/tests/test_form_snippets.py +++ b/ckanext/scheming/tests/test_form_snippets.py @@ -11,26 +11,17 @@ import ckantoolkit -if ckantoolkit.check_ckan_version(min_version='2.9.0'): - from contextlib import contextmanager - @contextmanager - def mock_pylons_request(): - yield -else: - from ckanext.scheming.tests.mock_pylons_request import mock_pylons_request - def render_form_snippet(name, data=None, extra_args=None, errors=None, **kwargs): field = {"field_name": "test", "label": "Test"} field.update(kwargs) - with mock_pylons_request(): - return render_snippet( - "scheming/form_snippets/" + name, - field=field, - data=data or {}, - errors=errors or {}, - **(extra_args or {}) - ) + return render_snippet( + "scheming/form_snippets/" + name, + field=field, + data=data or {}, + errors=errors or {}, + **(extra_args or {}) + ) @pytest.mark.usefixtures("with_request_context") diff --git a/ckanext/scheming/tests/test_validation.py b/ckanext/scheming/tests/test_validation.py index 94ef0bb5..590c43d3 100644 --- a/ckanext/scheming/tests/test_validation.py +++ b/ckanext/scheming/tests/test_validation.py @@ -15,7 +15,7 @@ SchemingDatasetsPlugin, SchemingGroupsPlugin, ) -from ckantoolkit import get_validator, check_ckan_version, navl_validate +from ckantoolkit import get_validator, navl_validate ignore_missing = get_validator("ignore_missing") not_empty = get_validator("not_empty") @@ -43,21 +43,15 @@ def test_choice_field_only_accepts_given_choices(self): type="test-schema", name="fred_choices1", category="rocker" ) except ValidationError as e: - if check_ckan_version("2.9"): - expected = "Value must be one of {}".format( - [ - u"bactrian", - u"hybrid", - u"f2hybrid", - u"snowwhite", - u"black", - ] - ) - else: - expected = ( - "Value must be one of: bactrian; hybrid; f2hybrid; " - "snowwhite; black (not 'rocker')" - ) + expected = "Value must be one of {}".format( + [ + u"bactrian", + u"hybrid", + u"f2hybrid", + u"snowwhite", + u"black", + ] + ) assert e.error_dict["category"] == [expected] else: raise AssertionError("ValidationError not raised")