mirror of
https://github.com/pretix/pretix.git
synced 2026-05-06 15:24:02 +00:00
Organizer-level plugins (#5305)
* Add version notes to the docs * Adapt signal handling * Add UI * Add API * API and tests * Fix registry * Update doc/development/api/plugins.rst Co-authored-by: Felix Rindt <felix@rindt.me> * Fix failing tests * Apply suggestions from code review Co-authored-by: Richard Schreiber <schreiber@rami.io> * Update src/pretix/control/templates/pretixcontrol/organizers/plugin_events.html Co-authored-by: luelista <weller@rami.io> * Update src/pretix/control/templates/pretixcontrol/organizers/plugins.html Co-authored-by: luelista <weller@rami.io> * Update src/pretix/control/templates/pretixcontrol/organizers/plugins.html Co-authored-by: luelista <weller@rami.io> * Update src/pretix/control/navigation.py Co-authored-by: luelista <weller@rami.io> * Update src/pretix/control/urls.py Co-authored-by: luelista <weller@rami.io> * Apply suggestion from @wiffbi * REbase migration * Fix review note * Fix test cases * Remove plugin from all events if disabled on org level * Update doc/development/api/plugins.rst * Unify registries * Rebase migration --------- Co-authored-by: Felix Rindt <felix@rindt.me> Co-authored-by: Richard Schreiber <schreiber@rami.io> Co-authored-by: luelista <weller@rami.io>
This commit is contained in:
@@ -182,6 +182,11 @@ def _register_with_fake_plugin_name(registry, obj, plugin_name):
|
||||
|
||||
class App:
|
||||
name = plugin_name
|
||||
|
||||
class PretixPluginMeta:
|
||||
pass
|
||||
|
||||
obj.__mocked_app = App
|
||||
registry.register(obj)
|
||||
registry.registered_entries[obj]['plugin'] = App
|
||||
|
||||
|
||||
@@ -22,10 +22,12 @@
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
from django.apps import apps
|
||||
|
||||
from pretix.base.logentrytypes import (
|
||||
ItemLogEntryType, LogEntryType, LogEntryTypeRegistry,
|
||||
)
|
||||
from pretix.base.models import Event
|
||||
from pretix.base.signals import Registry
|
||||
|
||||
|
||||
@@ -140,29 +142,38 @@ def test_logentrytype_registry():
|
||||
reg = LogEntryTypeRegistry()
|
||||
|
||||
with mock.patch('pretix.base.signals.get_defining_app') as mock_get_defining_app:
|
||||
mock_get_defining_app.return_value = 'my_plugin'
|
||||
mock_get_defining_app.return_value = apps.get_app_config("testdummy")
|
||||
|
||||
@reg.new("foo.mytype")
|
||||
class MyType(LogEntryType):
|
||||
pass
|
||||
|
||||
@reg.new("foo.myothertype")
|
||||
class MyOtherType(LogEntryType):
|
||||
pass
|
||||
with mock.patch('pretix.base.signals.get_defining_app') as mock_get_defining_app:
|
||||
mock_get_defining_app.return_value = "CORE"
|
||||
|
||||
@reg.new("foo.myothertype")
|
||||
class MyOtherType(LogEntryType):
|
||||
pass
|
||||
|
||||
typ, meta = reg.get(action_type="foo.mytype")
|
||||
assert isinstance(typ, MyType)
|
||||
assert meta['action_type'] == "foo.mytype"
|
||||
assert meta['plugin'] == 'my_plugin'
|
||||
assert meta['plugin'] == apps.get_app_config("testdummy")
|
||||
|
||||
typ, meta = reg.get(action_type="foo.myothertype")
|
||||
assert isinstance(typ, MyOtherType)
|
||||
assert meta['action_type'] == "foo.myothertype"
|
||||
assert meta['plugin'] is None
|
||||
assert meta['plugin'] == "CORE"
|
||||
|
||||
by_my_plugin = reg.filter(plugin='my_plugin')
|
||||
by_my_plugin = reg.filter(plugin=apps.get_app_config("testdummy"))
|
||||
assert set(type(typ) for typ, meta in by_my_plugin) == {MyType}
|
||||
|
||||
by_active_plugin = reg.filter(active_in=Event(plugins=""))
|
||||
assert set(type(typ) for typ, meta in by_active_plugin) == {MyOtherType}
|
||||
|
||||
by_active_plugin = reg.filter(active_in=Event(plugins="tests.testdummy"))
|
||||
assert set(type(typ) for typ, meta in by_active_plugin) == {MyType, MyOtherType}
|
||||
|
||||
|
||||
def test_logentrytype_registry_validation():
|
||||
reg = LogEntryTypeRegistry()
|
||||
|
||||
Reference in New Issue
Block a user