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
2 changes: 0 additions & 2 deletions goodmap/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
from goodmap.plugin import GoodmapPluginBase

__all__ = ["GoodmapPluginBase"]
20 changes: 2 additions & 18 deletions goodmap/goodmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
from platzky import platzky
from platzky.config import AttachmentConfig, languages_dict
from platzky.models import CmsModule
from platzky.plugin.content_transformer import ContentTransformerPluginBase
from platzky.shortcodes import Shortcode
from pydantic import BaseModel

from goodmap.admin_api import admin_pages
Expand All @@ -28,7 +26,7 @@

logger = logging.getLogger(__name__)

_PLUGIN_ENTRY_POINT_GROUP = "goodmap.plugins"
_PLUGIN_ENTRY_POINT_GROUP = "platzky.plugins"


def _register_plugin_static_resources(
Expand Down Expand Up @@ -169,20 +167,6 @@ def create_app_from_config(config: GoodmapConfig) -> platzky.Engine:
max_size=5 * 1024 * 1024, # 5MB - reasonable for location photos
)

shortcodes: dict[str, Shortcode] = {}
for plugin in app.loaded_plugins:
if isinstance(plugin, ContentTransformerPluginBase):
for name, sc in plugin.shortcodes.items():
if name in shortcodes:
logger.warning(
"Shortcode '%s' from plugin '%s' conflicts with "
"an already-registered shortcode; skipping",
name,
type(plugin).__name__,
)
else:
shortcodes[name] = sc

cp = core_pages(
app.db,
languages_dict(config.languages),
Expand All @@ -191,7 +175,7 @@ def create_app_from_config(config: GoodmapConfig) -> platzky.Engine:
location_model,
photo_attachment_config=photo_attachment_config,
feature_flags=config.feature_flags,
shortcodes=shortcodes,
shortcodes=app.shortcodes,
)
app.register_blueprint(cp)

Expand Down
12 changes: 0 additions & 12 deletions goodmap/plugin.py

This file was deleted.

10 changes: 5 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Flask-WTF = "^1.2.1"
gql = "^3.4.0"
aiohttp = "^3.8.4"
pydantic = "^2.12.0"
platzky = "2.0.0a3"
platzky = "2.0.0a2"
deprecation = "^2.1.0"
numpy = "^2.2.0"
# Using fork because official PyPI version (0.7.7) has outdated numpy setup hack
Expand Down
70 changes: 0 additions & 70 deletions tests/unit_tests/test_goodmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,76 +263,6 @@ def test_admin_route_logged_in():
assert "Test User" in response_text


def test_field_renderer_shortcodes_collected_from_content_transformer_plugins() -> None:
"""Shortcodes from all ContentTransformerPluginBase plugins are passed to core_pages."""
from typing import ClassVar

from platzky.content_types import ALL_CONTENT_TYPES
from platzky.plugin.content_transformer import ContentTransformerPluginBase
from platzky.shortcodes import Shortcode, ShortcodeAttrs

class _FieldSC(Shortcode):
name = "testfieldsc"
description = "Field-capable shortcode"

def render(self, attrs: ShortcodeAttrs, content: str) -> str:
return content

class _PostSC(Shortcode):
name = "testpostsc"
description = "Post-only shortcode"

def render(self, attrs: ShortcodeAttrs, content: str) -> str:
return content

class _PluginA(ContentTransformerPluginBase):
shortcodes: ClassVar[dict[str, Shortcode]] = {"testfieldsc": _FieldSC()}

class _PluginB(ContentTransformerPluginBase):
shortcodes: ClassVar[dict[str, Shortcode]] = {"testpostsc": _PostSC()}

config = _make_test_app_config(
extra_data={
"plugins": [
{
"name": "field_plugin",
"config": {},
"allowed_content_types": list(ALL_CONTENT_TYPES),
"allowed_topics": ["general", "content", "security"],
},
{
"name": "post_plugin",
"config": {},
"allowed_content_types": list(ALL_CONTENT_TYPES),
"allowed_topics": ["general", "content", "security"],
},
]
}
)

captured: dict[str, Any] = {}
orig_core_pages = goodmap.core_pages

def _spy_core_pages(*args: Any, **kwargs: Any) -> Any:
captured["shortcodes"] = kwargs.get("shortcodes", {})
return orig_core_pages(*args, **kwargs)

field_ep = mock.MagicMock()
field_ep.name = "field_plugin"
field_ep.load.return_value = _PluginA

post_ep = mock.MagicMock()
post_ep.name = "post_plugin"
post_ep.load.return_value = _PluginB

with mock.patch("goodmap.goodmap.core_pages", side_effect=_spy_core_pages):
with mock.patch("importlib.metadata.entry_points", return_value=[field_ep, post_ep]):
goodmap.create_app_from_config(config)

assert "testfieldsc" in captured["shortcodes"]
assert "testpostsc" in captured["shortcodes"]


def test_plugin_blueprint_sets_cors_header():
"""Should set Access-Control-Allow-Origin on plugin blueprint responses."""
config = _make_test_app_config()
Expand Down
Loading