Skip to content

Commit b28191b

Browse files
committed
SXDEDPCXZIC-425 / upgrade to CKAN 2.11
1 parent 9bd9f85 commit b28191b

8 files changed

Lines changed: 80 additions & 28 deletions

File tree

ckanext/datavic_odp_theme/plugin.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,27 +68,28 @@ def before_dataset_index(self, pkg_dict: dict[str, Any]) -> dict[str, Any]:
6868

6969
def _is_all_api_format(self, pkg_dict: dict[str, Any]) -> bool:
7070
"""Check if the dataset contains a resource in a format recognized as an API.
71-
This involves determining if the format of the resource is CSV and if this resource exists in the datastore
72-
or matches a format inside a predefined list.
71+
This involves determining if the format of the resource is CSV and if this
72+
resource exists in the datastore or matches a format inside a predefined list.
7373
"""
74-
for resource in tk.get_action("package_show")({"ignore_auth": True},
75-
{"id": pkg_dict["id"]}).get(
76-
"resources", []):
74+
for resource in tk.get_action("package_show")(
75+
{"ignore_auth": True},
76+
{"id": pkg_dict["id"]}
77+
).get("resources", []):
7778
if resource["format"].upper() == "CSV" and resource["datastore_active"]:
7879
return True
7980

8081
if [
8182
res_format
8283
for res_format in pkg_dict["res_format"]
8384
if res_format
84-
in [
85-
"WMS",
86-
"WFS",
87-
"API",
88-
"ARCGIS GEOSERVICES REST API",
89-
"ESRI REST",
90-
"GEOJSON",
91-
]
85+
in [
86+
"WMS",
87+
"WFS",
88+
"API",
89+
"ARCGIS GEOSERVICES REST API",
90+
"ESRI REST",
91+
"GEOJSON",
92+
]
9293
]:
9394
return True
9495
return False
@@ -105,26 +106,27 @@ def get_categories(self):
105106
# IAuthenticator
106107

107108
def login(self) -> Optional[Response]:
108-
session.regenerate_id() # type: ignore
109+
session.modified = True
109110

110111
def logout(self) -> Optional[Response]:
111-
session.regenerate_id() # type: ignore
112+
session.modified = True
113+
112114

113115
@tk.blanket.auth_functions(auth_functions)
114116
class DatavicODPThemeAuth(p.SingletonPlugin):
115117
"""Register auth function inside separate extension.
116118
117119
We are chaining auth functions from activity and overriding its templates
118120
at the same time. The former requires us to put our plugin after the
119-
activty, while the latter will work only if we put our plugin before the
121+
activity, while the latter will work only if we put our plugin before the
120122
activity. The only way to solve this puzzle is to split the logic between
121123
two sub-plugins.
122124
123125
"""
124126
pass
125127

126128

127-
class DatavicXLoaderPlugin(xloaderPlugin):
129+
class DatavicXLoaderPlugin(xloaderPlugin, p.SingletonPlugin):
128130
p.implements(p.IPackageController, inherit=True)
129131

130132
# IPackageController

ckanext/datavic_odp_theme/tests/e2e/__init__.py

Whitespace-only changes.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from __future__ import annotations
2+
3+
from typing import Any
4+
5+
import pytest
6+
7+
8+
@pytest.fixture()
9+
def browser_context_args(
10+
browser_context_args: dict[str, Any], ckan_config: dict[str, Any]
11+
):
12+
"""Modify playwright's standard configuration of browser's context."""
13+
browser_context_args["base_url"] = ckan_config["ckan.site_url"]
14+
return browser_context_args
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from __future__ import annotations
2+
3+
from typing import Any, Callable
4+
5+
import pytest
6+
from playwright.sync_api import Page, expect
7+
8+
import ckan.plugins.toolkit as tk
9+
10+
11+
@pytest.mark.playwright
12+
@pytest.mark.usefixtures("with_plugins", "clean_db", "clean_index")
13+
class TestDatasetSearch:
14+
def test_public_dataset(
15+
self, page: Page, package_factory: Callable[..., dict[str, Any]]
16+
):
17+
dataset = package_factory(private=False)
18+
19+
page.goto(tk.h.url_for("dataset.search"))
20+
expect(page.locator(".privacy-label ")).to_have_text(
21+
"Open to the public"
22+
)
23+
24+
page.get_by_role("link", name=dataset["title"]).click()
25+
26+
expect(page).to_have_url(
27+
tk.h.url_for("dataset.read", id=dataset["name"])
28+
)

dev-requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
pytest-ckan
22
pytest-factoryboy
3+
pytest-mock
4+
pytest-playwright

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ sections = "FUTURE,STDLIB,FIRSTPARTY,THIRDPARTY,CKAN,CKANEXT,SELF,LOCALFOLDER"
1313
profile = "black"
1414

1515
[tool.pytest.ini_options]
16-
addopts = "--ckan-ini test.ini"
16+
addopts = "--ckan-ini test_config/test.ini -m 'not benchmark and not playwright'"
1717
filterwarnings = [
1818
"ignore::sqlalchemy.exc.SADeprecationWarning",
1919
"ignore::sqlalchemy.exc.SAWarning",

test_config/default.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[app:main]
2+
use = config:../../ckan/test-core.ini

test.ini renamed to test_config/test.ini

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,27 @@ debug = false
33
smtp_server = localhost
44
error_email_from = paste@localhost
55

6-
[server:main]
7-
use = egg:Paste#http
8-
host = 0.0.0.0
9-
port = 5000
10-
116
[app:main]
12-
use = config:../ckan/test-core.ini
7+
use = config:default.ini
8+
9+
ckan.site_url = http://127.0.0.1:5000
1310

1411
ckan.plugins =
15-
datavic_odp_theme
16-
datavic_odp_schema
17-
scheming_datasets
12+
datavic_odp_theme
13+
datavic_odp_schema
14+
scheming_datasets
15+
scheming_organizations
1816

1917
## ckanext-scheming settings
2018
scheming.dataset_schemas = ckanext.datavic_odp_schema:odp_dataset_schema.yaml
19+
scheming.organization_schemas = ckanext.datavic_odp_schema:organisation_schema.yaml
2120
scheming.presets = ckanext.scheming:presets.json
2221
scheming.dataset_fallback = false
2322

2423

2524
# Logging configuration
2625
[loggers]
27-
keys = root, ckan, sqlalchemy
26+
keys = root, ckan, sqlalchemy, environment
2827

2928
[handlers]
3029
keys = console
@@ -46,6 +45,11 @@ handlers =
4645
qualname = sqlalchemy.engine
4746
level = WARN
4847

48+
[logger_environment]
49+
handlers =
50+
qualname = ckan.config.environment
51+
level = ERROR
52+
4953
[handler_console]
5054
class = StreamHandler
5155
args = (sys.stdout,)

0 commit comments

Comments
 (0)