Skip to content

Commit

Permalink
Add test to verify removing tags in a plugin works (alerta#1241)
Browse files Browse the repository at this point in the history
  • Loading branch information
satterly committed Jun 10, 2020
1 parent 8747289 commit 79e73a2
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion tests/test_plugins.py
Expand Up @@ -145,7 +145,7 @@ def test_take_action(self):
data = json.loads(response.data.decode('utf-8'))
self.assertEqual(data['alert']['status'], 'assign')
self.assertEqual(sorted(data['alert']['tags']), sorted(
['Development', 'Production', 'more', 'other', 'that', 'the', 'this']))
['Development', 'Production', 'more', 'other', 'that', 'the', 'this', 'aSingleTag', 'a:Triple:Tag']))
self.assertEqual(data['alert']['history'][1]['text'],
'ticket created by bob (ticket #12345)-plugin1-plugin3', data['alert']['history'])

Expand Down Expand Up @@ -221,6 +221,32 @@ def test_heartbeat_alert(self):
data = json.loads(response.data.decode('utf-8'))
self.assertEqual(data['message'], 'Alert converted to heartbeat')

def test_add_and_remove_tags(self):

plugins.plugins['action1'] = CustActionPlugin1()
plugins.plugins['action2'] = CustActionPlugin2()

# create alert
response = self.client.post('/alert', json=self.critical_alert, headers=self.headers)
self.assertEqual(response.status_code, 201)
data = json.loads(response.data.decode('utf-8'))

alert_id = data['id']

payload = {
'action': 'ack',
'text': 'this is a test'
}
response = self.client.put('/alert/' + alert_id + '/action', json=payload, headers=self.headers)
self.assertEqual(response.status_code, 200)

response = self.client.get('/alert/' + alert_id)
self.assertEqual(response.status_code, 200)
data = json.loads(response.data.decode('utf-8'))
self.assertIn('aSingleTag', data['alert']['tags'])
self.assertIn('a:Triple:Tag', data['alert']['tags'])
self.assertNotIn('aDouble:Tag', data['alert']['tags'])


class OldPlugin1(PluginBase):

Expand Down Expand Up @@ -324,6 +350,27 @@ def take_action(self, alert, action, text, **kwargs):
alert.tags.append('true')
text = text + ' (ticket #12345)'

alert.tags.append('aSingleTag') # one tag only
alert.tags.extend(['aDouble:Tag', 'a:Triple:Tag']) # multiple tags as a list

return alert, action, text


class CustActionPlugin2(PluginBase):

def pre_receive(self, alert, **kwargs):
return alert

def post_receive(self, alert, **kwargs):
return

def status_change(self, alert, status, text, **kwargs):
return alert, status, text

def take_action(self, alert, action, text, **kwargs):

alert.tags.remove('aDouble:Tag')

return alert, action, text


Expand Down

0 comments on commit 79e73a2

Please sign in to comment.