Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
1.1.6
- tests: add tests for the CLI commands, the i18n branding, and the
contact, imprint, and privacy pages
1.1.5
- fix: DCOR colors were not applied to colors in `rgb()` notation, which
CKAN 2.11.7 uses in `main.css` for some colors
Expand Down
42 changes: 42 additions & 0 deletions ckanext/dcor_theme/tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import pathlib

import ckan
from ckan.cli.cli import ckan as ckan_cli
import pytest

from ckanext.dcor_theme.css import make_dcor_main_css as mdc


@pytest.mark.ckan_config('ckan.plugins', 'dcor_theme')
@pytest.mark.usefixtures('with_plugins')
def test_cli_main_css_branding(cli):
result = cli.invoke(ckan_cli, ["dcor-theme-main-css-branding"])
assert result.exit_code == 0, result.output
path_css = (pathlib.Path(mdc.__file__).parent.parent
/ "assets_theme" / "dcor_main.css")
assert path_css.exists()
css = path_css.read_text()
# the custom CSS files are appended
css_theme = (pathlib.Path(mdc.__file__).parent
/ "dcor_theme.css").read_text()
assert css_theme in css
# CKAN colors are replaced
for color in mdc.color_map:
assert color not in css


@pytest.mark.ckan_config('ckan.plugins', 'dcor_theme')
@pytest.mark.usefixtures('with_plugins')
def test_cli_patch_ckan_templates(cli):
for _ in range(2): # patching twice must not break anything
result = cli.invoke(ckan_cli, ["dcor-patch-ckan-templates"])
assert result.exit_code == 0, result.output
path_templates = pathlib.Path(ckan.__file__).parent / "templates"
res_item = (path_templates / "package" / "snippets"
/ "resource_item.html").read_text()
assert "| truncate(50)" not in res_item
assert 'style="overflow-wrap: break-word" class="heading"' in res_item
resources = (path_templates / "package" / "snippets"
/ "resources.html").read_text()
assert "|truncate(25)" not in resources
assert "overflow-wrap" in resources
39 changes: 39 additions & 0 deletions ckanext/dcor_theme/tests/test_i18n.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from importlib import resources as importlib_resources
import pathlib

import pytest

from ckan.cli.cli import ckan as ckan_cli

from ckanext.dcor_theme.cli.i18n_branding import replace_branding


@pytest.mark.parametrize("msgid,expected", [
("Create an Organization", "Create a Circle"),
("organization", "circle"),
("Add to group", "Add to collection"),
# placeholders and identifiers are preserved
("{organization} was deleted", "{organization} was deleted"),
("organization_id", "organization_id"),
("Group {group}", "Collection {group}"),
# unrelated strings are not modified
("Dataset", "Dataset"),
# plural forms
(("organization", "organizations"), ("circle", "circles")),
])
def test_replace_branding(msgid, expected):
assert replace_branding(msgid) == expected


@pytest.mark.ckan_config('ckan.plugins', 'dcor_theme')
@pytest.mark.usefixtures('with_plugins')
def test_cli_i18n_branding(cli):
result = cli.invoke(ckan_cli, ["dcor-theme-i18n-branding"])
assert result.exit_code == 0, result.output
path_po = (pathlib.Path(str(importlib_resources.files("ckan.i18n")))
/ "en_US" / "LC_MESSAGES" / "ckan.po")
assert path_po.exists()
assert path_po.with_suffix(".mo").exists()
data = path_po.read_text(encoding="utf-8")
assert 'msgstr "Circle"' in data
assert "Plural-Forms" in data
25 changes: 25 additions & 0 deletions ckanext/dcor_theme/tests/test_plugin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
"""Tests for plugin.py."""
import re

import pytest

import ckanext.dcor_theme.plugin as plugin # noqa: F401


Expand All @@ -20,3 +24,24 @@ def test_plugin_get_blueprint():
assert "contact" in endpoints
assert "imprint" in endpoints
assert "privacy" in endpoints


def test_plugin_get_commands():
p = plugin.DCORThemePlugin()
names = [c.name for c in p.get_commands()]
assert names == ["dcor-patch-ckan-templates",
"dcor-theme-i18n-branding",
"dcor-theme-main-css-branding"]


@pytest.mark.ckan_config('ckan.plugins', 'dcor_theme')
@pytest.mark.usefixtures('with_plugins')
@pytest.mark.parametrize("page,title", [
("contact", "Contact"),
("imprint", "Imprint"),
("privacy", "Privacy"),
])
def test_plugin_pages(app, page, title):
resp = app.get(f"/{page}")
assert resp.status_code == 200
assert re.search(rf"<title>\s*{title}", resp.body)
Loading