2015-12-01 13:44:08 +00:00
|
|
|
from tests import BaseTestCase
|
2016-11-30 21:48:31 +00:00
|
|
|
from redash.models import Alert, db
|
2015-12-01 13:44:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestAlertAll(BaseTestCase):
|
|
|
|
def test_returns_all_alerts_for_given_groups(self):
|
|
|
|
ds1 = self.factory.data_source
|
|
|
|
group = self.factory.create_group()
|
|
|
|
ds2 = self.factory.create_data_source(group=group)
|
|
|
|
|
|
|
|
query1 = self.factory.create_query(data_source=ds1)
|
|
|
|
query2 = self.factory.create_query(data_source=ds2)
|
|
|
|
|
2016-11-30 21:48:31 +00:00
|
|
|
alert1 = self.factory.create_alert(query_rel=query1)
|
|
|
|
alert2 = self.factory.create_alert(query_rel=query2)
|
|
|
|
db.session.flush()
|
2015-12-01 13:44:08 +00:00
|
|
|
|
2016-11-29 15:53:06 +00:00
|
|
|
alerts = Alert.all(group_ids=[group.id, self.factory.default_group.id])
|
2015-12-01 13:44:08 +00:00
|
|
|
self.assertIn(alert1, alerts)
|
|
|
|
self.assertIn(alert2, alerts)
|
|
|
|
|
2016-11-29 15:53:06 +00:00
|
|
|
alerts = Alert.all(group_ids=[self.factory.default_group.id])
|
2015-12-01 13:44:08 +00:00
|
|
|
self.assertIn(alert1, alerts)
|
|
|
|
self.assertNotIn(alert2, alerts)
|
|
|
|
|
2016-11-29 15:53:06 +00:00
|
|
|
alerts = Alert.all(group_ids=[group.id])
|
2015-12-01 13:44:08 +00:00
|
|
|
self.assertNotIn(alert1, alerts)
|
|
|
|
self.assertIn(alert2, alerts)
|
2016-05-30 11:39:58 +00:00
|
|
|
|
|
|
|
def test_return_each_alert_only_once(self):
|
|
|
|
group = self.factory.create_group()
|
|
|
|
self.factory.data_source.add_group(group)
|
|
|
|
|
|
|
|
alert = self.factory.create_alert()
|
|
|
|
|
2016-11-29 15:53:06 +00:00
|
|
|
alerts = Alert.all(group_ids=[self.factory.default_group.id, group.id])
|
2016-05-30 11:39:58 +00:00
|
|
|
self.assertEqual(1, len(list(alerts)))
|
|
|
|
self.assertIn(alert, alerts)
|