mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
replace assertation with more targeted logging check (#5045)
This commit is contained in:
parent
be6ab14c9b
commit
2322a98068
@ -1,12 +1,14 @@
|
||||
"""Sample plugin which responds to events."""
|
||||
|
||||
import warnings
|
||||
import logging
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
from plugin import InvenTreePlugin
|
||||
from plugin.mixins import EventMixin
|
||||
|
||||
logger = logging.getLogger('inventree')
|
||||
|
||||
|
||||
class EventPluginSample(EventMixin, InvenTreePlugin):
|
||||
"""A sample plugin which provides supports for triggered events."""
|
||||
@ -23,4 +25,4 @@ class EventPluginSample(EventMixin, InvenTreePlugin):
|
||||
|
||||
# Issue warning that we can test for
|
||||
if settings.PLUGIN_TESTING:
|
||||
warnings.warn(f'Event `{event}` triggered', stacklevel=2)
|
||||
logger.debug(f'Event `{event}` triggered in sample plugin')
|
||||
|
@ -8,6 +8,8 @@ from plugin.base.event.events import trigger_event
|
||||
from plugin.helpers import MixinNotImplementedError
|
||||
from plugin.mixins import EventMixin
|
||||
|
||||
from .event_sample import logger
|
||||
|
||||
|
||||
class EventPluginSampleTests(TestCase):
|
||||
"""Tests for EventPluginSample."""
|
||||
@ -22,9 +24,9 @@ class EventPluginSampleTests(TestCase):
|
||||
# Enable event testing
|
||||
settings.PLUGIN_TESTING_EVENTS = True
|
||||
# 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')
|
||||
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
|
||||
settings.PLUGIN_TESTING_EVENTS = False
|
||||
|
Loading…
Reference in New Issue
Block a user