Skip to content

Commit a037c79

Browse files
committed
test: update tests with new functionality of heartbeats
1 parent 84c678d commit a037c79

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

tests/unit/test_commands.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ def test_heartbeat_cmd(self, m):
8484
@requests_mock.mock()
8585
def test_heartbeats_cmd(self, m):
8686

87-
heartbeats_response = """
88-
{
87+
heartbeats_response = {
8988
"heartbeats": [
9089
{
9190
"attributes": {
@@ -96,7 +95,7 @@ def test_heartbeats_cmd(self, m):
9695
"region": "EU"
9796
},
9897
"createTime": "2020-03-10T20:25:54.541Z",
99-
"customer": null,
98+
"customer": None,
10099
"href": "http://127.0.0.1/heartbeat/52c202e8-d949-45ed-91e0-cdad4f37de73",
101100
"id": "52c202e8-d949-45ed-91e0-cdad4f37de73",
102101
"latency": 0,
@@ -113,11 +112,10 @@ def test_heartbeats_cmd(self, m):
113112
"status": "ok",
114113
"total": 1
115114
}
116-
"""
117115

118116
heartbeat_alert_response = """
119117
{
120-
"alert": {
118+
"alerts": [{
121119
"attributes": {},
122120
"correlate": [
123121
"HeartbeatFail",
@@ -166,25 +164,31 @@ def test_heartbeats_cmd(self, m):
166164
"type": "heartbeatAlert",
167165
"updateTime": "2020-03-10T21:55:07.916Z",
168166
"value": "22ms"
169-
},
170-
"id": "6cfbc30f-c2d6-4edf-b672-841070995206",
167+
}],
171168
"status": "ok"
172169
}
173170
"""
174171

175-
m.get('/heartbeats', text=heartbeats_response)
176-
m.post('/alert', text=heartbeat_alert_response)
172+
empty_alerts_response="""
173+
{
174+
"alerts":[],
175+
"status": "ok"
176+
}
177+
"""
178+
179+
m.get('/heartbeats', json=heartbeats_response)
180+
m.get('/alerts', text=empty_alerts_response)
181+
m.post('/alerts', text=heartbeat_alert_response)
177182
result = self.runner.invoke(heartbeats_cmd, ['--alert'], obj=self.obj)
178183
self.assertEqual(result.exit_code, 0, result.exception)
179184
self.assertIn('monitoring-01', result.output)
180-
181-
history = m.request_history
182-
data = history[1].json()
183-
self.assertEqual(data['environment'], 'Infrastructure')
185+
186+
data = m.last_request.json()[0]
187+
self.assertEqual(data['environment'], 'Heartbeats')
184188
self.assertEqual(data['severity'], 'major')
185189
self.assertEqual(data['service'], ['Internal'])
186190
self.assertEqual(data['group'], 'Heartbeats')
187-
self.assertEqual(data['attributes'], {'region': 'EU'})
191+
self.assertEqual(data['attributes'], {'environment': 'Infrastructure', 'region': 'EU'})
188192

189193
@requests_mock.mock()
190194
def test_whoami_cmd(self, m):

0 commit comments

Comments
 (0)