This repository has been archived by the owner on Dec 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_main.py
76 lines (56 loc) · 1.74 KB
/
test_main.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import unittest
import main
TEST_ENV = "prod"
TEST_QUEUE = "restyled:agent:webhooks"
TEST_PARAM = "/restyled/{}/redis-url".format(TEST_ENV)
TEST_REDIS_URL = "http://redis.restyled.com:6379/1"
class TestMain(unittest.TestCase):
def test_handler(self):
aws = MockAWS()
aws.ssm_parameters[TEST_PARAM] = TEST_REDIS_URL
redis = MockRedis()
redis.llens[TEST_QUEUE] = 3
logger = main.get_logger("ERROR")
expected_metric = {
"Dimensions": [
{
"Name": "Environment",
"Value": TEST_ENV
},
{
"Name": "QueueName",
"Value": TEST_QUEUE
},
],
"MetricName":
"QueueDepth",
"Unit":
"Count",
"Value":
3,
}
expected_metrics = [{
"MetricData": [expected_metric],
"Namespace": "Restyled",
}]
result = main.handler_(aws, redis, TEST_ENV, TEST_QUEUE, logger)
self.assertEqual(aws.cloudwatch_metrics, expected_metrics)
class MockAWS:
def __init__(self):
self.ssm_parameters = {}
self.cloudwatch_metrics = []
def ssm_get_parameter(self, *args, **kwargs):
name = kwargs.get("Name")
value = self.ssm_parameters[name]
return {"Parameter": {"Value": value}}
def cloudwatch_put_metric_data(self, *args, **kwargs):
self.cloudwatch_metrics.append(kwargs)
class MockRedis:
def __init__(self):
self.llens = {}
def setup(self, *args, **kwargs):
pass
def llen(self, queue):
return self.llens[queue]
if __name__ == "__main__":
unittest.main()