-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtests.py
57 lines (49 loc) · 2.04 KB
/
tests.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import unittest
import main
from main import Dyno, parse_dyno_from_event, app_is_in_allowlist
TEST_PAYLOAD = {
"max_id": "1172555559466221570",
"min_id": "1172555559466221570",
"frequency": "minute",
"saved_search": {
"id": 47359282,
"name": "HTTP 5xx Alert",
"query": '" status=5"',
"html_edit_url": "https://papertrailapp.com/heroku/go/123?a=app123&app=test-app&s=edit&search_id=123",
"html_search_url": "https://papertrailapp.com/heroku/go/123?a=app123&app=test-app&search_id=123",
},
"events": [
{
"id": 1172555559466221570,
"message": 'at=error code=H12 desc="Request timeout" method=GET path="/timeout" host=timeouter-test.herokuapp.com request_id=6eb9db3e-13ed-41e3-ab78-083ca0c89828 fwd="146.200.199.39" dyno=web.1 connect=0ms service=30001ms status=503 bytes=0 protocol=https\n',
"program": "heroku/router",
"source_ip": "54.152.45.17",
"facility": "",
"severity": "",
"hostname": "timeouter-test",
"source_name": "timeouter-test",
"source_id": 5174160982,
"display_received_at": "Mar 6 12:04:12 GMT",
"received_at": "2020-03-06T12:04:12Z",
}
],
"counts": None,
"min_time_at": "2020-03-06T12:04:12Z",
}
class TestAppDynoParser(unittest.TestCase):
def test_parses_valid_message(self):
event = TEST_PAYLOAD["events"][0]
parsed = parse_dyno_from_event(event)
expected = Dyno(app="timeouter-test", dyno="web.1")
self.assertEqual(parsed, expected)
class TestAllowlist(unittest.TestCase):
def test_allowlist_matches_valid(self):
main.ALLOWLIST_APP_PATTERNS = ["*-production"]
matches = app_is_in_allowlist("test-production")
self.assertTrue(matches)
def test_allowlist_matches_invalid(self):
main.ALLOWLIST_APP_PATTERNS = ["*-production"]
matches = app_is_in_allowlist("test-staging")
self.assertFalse(matches)
if __name__ == "__main__":
unittest.main()