forked from alerta/alerta-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_slack.py
40 lines (29 loc) · 1.23 KB
/
test_slack.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import json
import unittest
from alerta.app import create_app, plugins
from alerta_slack import ServiceIntegration
class SlackPluginTestCase(unittest.TestCase):
def setUp(self):
test_config = {
'TESTING': True,
'AUTH_REQUIRED': False,
'SLACK_WEBHOOK_URL': 'https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX'
}
self.app = create_app(test_config)
self.client = self.app.test_client()
def test_syslog_plugin(self):
plugins.plugins['slack'] = ServiceIntegration()
self.alert = {
'event': 'node_down',
'resource': 'net5',
'environment': 'Production',
'service': ['Network'],
'severity': 'critical',
'correlate': ['node_down', 'node_marginal', 'node_up'],
'tags': []
}
response = self.client.post('/alert', data=json.dumps(self.alert), headers={'Content-type': 'application/json'})
self.assertEqual(response.status_code, 201)
data = json.loads(response.data.decode('utf-8'))
self.assertEqual(data['status'], 'ok')
self.assertRegex(data['id'], '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}')