forked from alerta/alerta
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_logging.py
More file actions
49 lines (37 loc) · 1.4 KB
/
test_logging.py
File metadata and controls
49 lines (37 loc) · 1.4 KB
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
40
41
42
43
44
45
46
47
48
49
import json
import unittest
from alerta.app import create_app, custom_webhooks
from alerta.models.alert import Alert
from alerta.webhooks import WebhookBase
class LoggingTestCase(unittest.TestCase):
def setUp(self):
test_config = {
'TESTING': True,
'AUTH_REQUIRED': False,
'LOG_HANDLERS': ['console'],
'LOG_FORMAT': 'verbose',
'AUDIT_TRAIL': ['admin', 'write', 'auth'],
'AUDIT_LOG': True
}
self.app = create_app(test_config)
self.client = self.app.test_client()
def test_custom_webhook(self):
# setup custom webhook
custom_webhooks.webhooks['json'] = DummyJsonWebhook()
payload = """
{"baz": "quux %X %%"}
"""
# test json payload
response = self.client.post('/webhooks/json?foo=bar', json=json.loads(payload), content_type='application/json')
self.assertEqual(response.status_code, 201, response.data)
data = json.loads(response.data.decode('utf-8'))
self.assertEqual(data['alert']['resource'], 'bar')
self.assertEqual(data['alert']['event'], 'quux %X %%')
class DummyJsonWebhook(WebhookBase):
def incoming(self, query_string, payload):
return Alert(
resource=query_string['foo'],
event=payload['baz'],
environment='Production',
service=['Foo']
)