2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-29 20:16:44 +00:00

replace assertation with more targeted logging check (#5045)

This commit is contained in:
Matthias Mair 2023-06-14 23:34:00 +02:00 committed by GitHub
parent be6ab14c9b
commit 2322a98068
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View File

@ -1,12 +1,14 @@
"""Sample plugin which responds to events.""" """Sample plugin which responds to events."""
import warnings import logging
from django.conf import settings from django.conf import settings
from plugin import InvenTreePlugin from plugin import InvenTreePlugin
from plugin.mixins import EventMixin from plugin.mixins import EventMixin
logger = logging.getLogger('inventree')
class EventPluginSample(EventMixin, InvenTreePlugin): class EventPluginSample(EventMixin, InvenTreePlugin):
"""A sample plugin which provides supports for triggered events.""" """A sample plugin which provides supports for triggered events."""
@ -23,4 +25,4 @@ class EventPluginSample(EventMixin, InvenTreePlugin):
# Issue warning that we can test for # Issue warning that we can test for
if settings.PLUGIN_TESTING: if settings.PLUGIN_TESTING:
warnings.warn(f'Event `{event}` triggered', stacklevel=2) logger.debug(f'Event `{event}` triggered in sample plugin')

View File

@ -8,6 +8,8 @@ from plugin.base.event.events import trigger_event
from plugin.helpers import MixinNotImplementedError from plugin.helpers import MixinNotImplementedError
from plugin.mixins import EventMixin from plugin.mixins import EventMixin
from .event_sample import logger
class EventPluginSampleTests(TestCase): class EventPluginSampleTests(TestCase):
"""Tests for EventPluginSample.""" """Tests for EventPluginSample."""
@ -22,9 +24,9 @@ class EventPluginSampleTests(TestCase):
# Enable event testing # Enable event testing
settings.PLUGIN_TESTING_EVENTS = True settings.PLUGIN_TESTING_EVENTS = True
# Check that an event is issued # Check that an event is issued
with self.assertWarns(Warning) as cm: with self.assertLogs(logger=logger, level="DEBUG") as cm:
trigger_event('test.event') trigger_event('test.event')
self.assertEqual(cm.warning.args[0], 'Event `test.event` triggered') self.assertIn('DEBUG:inventree:Event `test.event` triggered in sample plugin', cm[1])
# Disable again # Disable again
settings.PLUGIN_TESTING_EVENTS = False settings.PLUGIN_TESTING_EVENTS = False