Esempio n. 1
0
 def test_sync_alerts(self, mock_list_alerts, mock_fill_storage_attributes,
                      mock_dispatch):
     task = alerts.AlertSyncTask()
     storage_id = fake_storage['id']
     # No alert
     mock_list_alerts.return_value = []
     task.sync_alerts(context, storage_id, None)
     self.assertEqual(db.storage_get.call_count, 1)
     self.assertEqual(mock_list_alerts.call_count, 1)
     self.assertEqual(mock_dispatch.call_count, 0)
     self.assertEqual(mock_fill_storage_attributes.call_count, 0)
     # Has alert
     mock_list_alerts.return_value = fake_alerts
     task.sync_alerts(context, storage_id, None)
     self.assertEqual(db.storage_get.call_count, 2)
     self.assertEqual(mock_list_alerts.call_count, 2)
     self.assertEqual(mock_dispatch.call_count, 1)
     self.assertEqual(mock_fill_storage_attributes.call_count,
                      len(fake_alerts))
Esempio n. 2
0
    def test_clear_alerts(self, mock_clear_alert):
        task = alerts.AlertSyncTask()
        storage_id = fake_storage['id']
        task.clear_alerts(context, storage_id, [])
        self.assertEqual(mock_clear_alert.call_count, 0)

        sequence_number_list = ['sequence_number_1', 'sequence_number_2']
        task.clear_alerts(context, storage_id, sequence_number_list)
        self.assertEqual(mock_clear_alert.call_count,
                         len(sequence_number_list))

        mock_clear_alert.side_effect = \
            exception.AccessInfoNotFound(storage_id)
        ret = task.clear_alerts(context, storage_id, sequence_number_list)
        self.assertEqual(ret, [])

        mock_clear_alert.side_effect = \
            exception.Invalid('Fake exception')
        ret = task.clear_alerts(context, storage_id, sequence_number_list)
        self.assertEqual(ret, sequence_number_list)
Esempio n. 3
0
 def __init__(self, service_name=None, *args, **kwargs):
     self.alert_task = alerts.AlertSyncTask()
     super(TaskManager, self).__init__(*args, **kwargs)