mirror of
https://github.com/inventree/InvenTree.git
synced 2026-10-14 22:20:59 +00:00
Add missing timeout to Slack notification plugin (#12990)
Co-authored-by: Matthias Mair <code@mjmair.com>
This commit is contained in:
1 parent
104adebbf4
commit
2341d5ff44
2 files changed
+30
No files matched your search
@@ -204,6 +204,7 @@ class InvenTreeSlackNotifications(NotificationMixin, SettingsMixin, InvenTreePlu
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
timeout=10,
|
||||||
)
|
)
|
||||||
|
|
||||||
return ret.ok
|
return ret.ok
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
"""Tests for core_notifications."""
|
"""Tests for core_notifications."""
|
||||||
|
|
||||||
|
from unittest import mock
|
||||||
|
|
||||||
from django.core import mail
|
from django.core import mail
|
||||||
|
|
||||||
from common.models import NotificationEntry
|
from common.models import NotificationEntry
|
||||||
@@ -61,3 +63,30 @@ class CoreNotificationTestTests(InvenTreeTestCase):
|
|||||||
self.notify()
|
self.notify()
|
||||||
|
|
||||||
self.assertEqual(len(mail.outbox), 1)
|
self.assertEqual(len(mail.outbox), 1)
|
||||||
|
|
||||||
|
def test_slack_timeout(self):
|
||||||
|
"""Ensure that the slack webhook call cannot block indefinitely."""
|
||||||
|
slug = 'inventree-slack-notification'
|
||||||
|
registry.set_plugin_state(slug, True)
|
||||||
|
|
||||||
|
plugin = registry.get_plugin(slug)
|
||||||
|
self.assertIsNotNone(plugin, 'Slack notification plugin should be available')
|
||||||
|
|
||||||
|
plugin.set_setting('NOTIFICATION_SLACK_URL', 'https://hooks.slack.com/test')
|
||||||
|
|
||||||
|
with mock.patch(
|
||||||
|
'plugin.builtin.integration.core_notifications.requests.post'
|
||||||
|
) as mock_post:
|
||||||
|
plugin.send_notification(
|
||||||
|
self.user,
|
||||||
|
'test_notification',
|
||||||
|
[self.user],
|
||||||
|
{
|
||||||
|
'name': 'Test Slack Notification',
|
||||||
|
'message': 'This is a test slack notification.',
|
||||||
|
'link': 'http://localhost:8000/',
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
mock_post.assert_called_once()
|
||||||
|
self.assertEqual(mock_post.call_args.kwargs['timeout'], 10)
|
||||||
Reference in new issue
Block a user