Skip to content

Commit

Permalink
removal(dev): ckantoolkit;
Browse files Browse the repository at this point in the history
- Use `ckan.plugins.toolkit`
  • Loading branch information
JVickery-TBS committed Jan 21, 2025
1 parent 5ce30cf commit d59a87d
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 31 deletions.
6 changes: 1 addition & 5 deletions ckanext/scheming/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import six

from jinja2 import Environment
from ckantoolkit import config, _
from ckan.plugins.toolkit import config, _, h

from ckanapi import LocalCKAN, NotFound, NotAuthorized

Expand All @@ -24,7 +24,6 @@ def helper(fn):
def lang():
# access this function late in case ckan
# is not set up fully when importing this module
from ckantoolkit import h
return h.lang()


Expand Down Expand Up @@ -77,7 +76,6 @@ def scheming_field_choices(field):
if 'choices' in field:
return field['choices']
if 'choices_helper' in field:
from ckantoolkit import h
choices_fn = getattr(h, field['choices_helper'])
return choices_fn(field)

Expand Down Expand Up @@ -409,8 +407,6 @@ def scheming_render_from_string(source, **kwargs):
# Temporary solution for rendering defaults and including the CKAN
# helpers. The core CKAN lib does not include a string rendering
# utility that works across 2.6-2.8.
from ckantoolkit import h

env = Environment(autoescape=True)
template = env.from_string(
source,
Expand Down
2 changes: 1 addition & 1 deletion ckanext/scheming/logic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ckantoolkit import get_or_bust, side_effect_free, ObjectNotFound
from ckan.plugins.toolkit import get_or_bust, side_effect_free, ObjectNotFound

from ckanext.scheming.helpers import (
scheming_dataset_schemas, scheming_get_dataset_schema,
Expand Down
2 changes: 1 addition & 1 deletion ckanext/scheming/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
except ImportError: # CKAN <= 2.5
core_helper_functions = None

from ckantoolkit import (
from ckan.plugins.toolkit import (
DefaultDatasetForm,
DefaultGroupForm,
DefaultOrganizationForm,
Expand Down
2 changes: 1 addition & 1 deletion ckanext/scheming/tests/test_dataset_display.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
import six
from ckantoolkit.tests.factories import Sysadmin, Dataset
from ckan.tests.factories import Sysadmin, Dataset


@pytest.mark.usefixtures("clean_db")
Expand Down
35 changes: 18 additions & 17 deletions ckanext/scheming/tests/test_form.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
import json

import pytest
import ckantoolkit
from bs4 import BeautifulSoup

from ckantoolkit.tests.factories import Dataset
from ckantoolkit.tests.helpers import call_action
from ckan.plugins.toolkit import check_ckan_version, h

from ckan.tests.factories import Dataset
from ckan.tests.helpers import call_action


@pytest.fixture
def sysadmin_env():
try:
from ckantoolkit.tests.factories import SysadminWithToken
from ckan.tests.factories import SysadminWithToken
user = SysadminWithToken()
return {'Authorization': user['token']}
except ImportError:
# ckan <= 2.9
from ckantoolkit.tests.factories import Sysadmin
from ckan.tests.factories import Sysadmin
user = Sysadmin()
return {"REMOTE_USER": user["name"].encode("ascii")}


def _get_package_new_page(app, env, type_='test-schema'):
if ckantoolkit.check_ckan_version(min_version="2.10.0"):
if check_ckan_version(min_version="2.10.0"):
return app.get(url="/{0}/new".format(type_), headers=env)
else:
return app.get(url="/{0}/new".format(type_), extra_environ=env)


def _get_package_update_page(app, id, env):

if ckantoolkit.check_ckan_version(min_version="2.10.0"):
if check_ckan_version(min_version="2.10.0"):
return app.get(url="/test-schema/edit/{}".format(id), headers=env)
else:
return app.get(url="/test-schema/edit/{}".format(id), extra_environ=env)
Expand All @@ -39,7 +40,7 @@ def _get_package_update_page(app, id, env):
def _get_resource_new_page(app, id, env):
url = '/dataset/{}/resource/new'.format(id)

if ckantoolkit.check_ckan_version(min_version="2.10.0"):
if check_ckan_version(min_version="2.10.0"):
return app.get(url, headers=env)
else:
return app.get(url, extra_environ=env)
Expand All @@ -48,31 +49,31 @@ def _get_resource_new_page(app, id, env):
def _get_resource_update_page(app, id, resource_id, env):
url = '/dataset/{}/resource/{}/edit'.format(id, resource_id)

if ckantoolkit.check_ckan_version(min_version="2.10.0"):
if check_ckan_version(min_version="2.10.0"):
return app.get(url, headers=env)
else:
return app.get(url, extra_environ=env)


def _get_organization_new_page(app, env, type_="organization"):

if ckantoolkit.check_ckan_version(min_version="2.10.0"):
if check_ckan_version(min_version="2.10.0"):
return app.get(url="/{0}/new".format(type_), headers=env)
else:
return app.get(url="/{0}/new".format(type_), extra_environ=env)


def _get_group_new_page(app, env, type_="group"):

if ckantoolkit.check_ckan_version(min_version="2.10.0"):
if check_ckan_version(min_version="2.10.0"):
return app.get(url="/{0}/new".format(type_), headers=env)
else:
return app.get(url="/{0}/new".format(type_), extra_environ=env)


def _get_organization_form(html):
# FIXME: add an id to this form
if ckantoolkit.check_ckan_version(min_version="2.11.0a0"):
if check_ckan_version(min_version="2.11.0a0"):
form = BeautifulSoup(html).select("form")[2]
else:
form = BeautifulSoup(html).select("form")[1]
Expand All @@ -85,7 +86,7 @@ def _get_group_form(html):

def _post_data(app, url, data, env):
try:
if ckantoolkit.check_ckan_version(min_version="2.11.0a0"):
if check_ckan_version(min_version="2.11.0a0"):
app.post(url, headers=env, data=data, follow_redirects=False)
else:
app.post(
Expand Down Expand Up @@ -267,7 +268,7 @@ def test_resource_form_create(self, app, sysadmin_env):

response = _get_resource_new_page(app, dataset["id"], sysadmin_env)

url = ckantoolkit.h.url_for(
url = h.url_for(
"test-schema_resource.new", id=dataset["id"]
)
if not url.startswith('/'): # ckan < 2.9
Expand Down Expand Up @@ -310,7 +311,7 @@ def test_resource_form_update(self, app, sysadmin_env):
"textarea[name=a_resource_json_field]"
).text == json.dumps(value, indent=2)

url = ckantoolkit.h.url_for(
url = h.url_for(
"test-schema_resource.edit",
id=dataset["id"],
resource_id=dataset["resources"][0]["id"],
Expand Down Expand Up @@ -405,7 +406,7 @@ def test_resource_form_create(self, app, sysadmin_env):

response = _get_resource_new_page(app, dataset["id"], sysadmin_env)

url = ckantoolkit.h.url_for(
url = h.url_for(
"test-subfields_resource.new", id=dataset["id"]
)
if not url.startswith('/'): # ckan < 2.9
Expand Down Expand Up @@ -444,7 +445,7 @@ def test_resource_form_update(self, app, sysadmin_env):
assert 'selected' in opt7d[1].attrs
assert 'selected' not in opt7d[2].attrs # blank subfields

url = ckantoolkit.h.url_for(
url = h.url_for(
"test-schema_resource.edit",
id=dataset["id"],
resource_id=dataset["resources"][0]["id"],
Expand Down
2 changes: 0 additions & 2 deletions ckanext/scheming/tests/test_form_snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
# old way
from jinja2 import Markup

import ckantoolkit


def render_form_snippet(name, data=None, extra_args=None, errors=None, **kwargs):
field = {"field_name": "test", "label": "Test"}
Expand Down
2 changes: 1 addition & 1 deletion ckanext/scheming/tests/test_group_display.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from ckantoolkit.tests.factories import Sysadmin, Organization, Group
from ckan.tests.factories import Sysadmin, Organization, Group


@pytest.mark.usefixtures("clean_db")
Expand Down
2 changes: 1 addition & 1 deletion ckanext/scheming/tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
SchemingDatasetsPlugin,
SchemingGroupsPlugin,
)
from ckantoolkit import get_validator, navl_validate
from ckan.plugins.toolkit import get_validator, navl_validate

ignore_missing = get_validator("ignore_missing")
not_empty = get_validator("not_empty")
Expand Down
2 changes: 1 addition & 1 deletion ckanext/scheming/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import ckan.lib.helpers as h
from ckan.lib.navl.dictization_functions import convert
from ckantoolkit import (
from ckan.plugins.toolkit import (
get_validator,
UnknownValidator,
missing,
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
install_requires=[
'pyyaml',
'ckanapi',
'ckantoolkit>=0.0.7',
'pytz',
'six',
],
Expand Down

0 comments on commit d59a87d

Please sign in to comment.