Esempio n. 1
0
    def test_clear(self, mock):
        observer = ObserverFactory.create()
        AlertFactory.create(observer=observer)
        Alert.clear(observer, observer.value)

        assert Alert.objects.all().count() == 0
        assert mock.call_count == 1
Esempio n. 2
0
    def test_clear_observer(self, mock):
        observer = ObserverFactory.create()
        AlertFactory.create(identifier=observer.get_alert_identifier())
        Alert.clear(observer.value, observer=observer)

        assert Alert.objects.all().count() == 0
        assert mock.call_count == 1
Esempio n. 3
0
    def test_warn_critical_waiting_priod_not_achieved(self, mock):
        observer = ObserverFactory.create(value=4, waiting_period=5)
        AlertFactory.create(identifier=observer.get_alert_identifier())
        Alert.set(2, observer=observer)

        assert Alert.objects.all().count() == 1
        assert Alert.objects.first().state == Alert.STATE_WAITING
        assert mock.call_count == 0
Esempio n. 4
0
    def test_warn_notified(self, mock):
        observer = ObserverFactory.create(value=4, waiting_period=0)
        AlertFactory.create(observer=observer, state=Alert.STATE_NOTIFIED)
        Alert.set(observer, 2)

        assert Alert.objects.all().count() == 1
        assert Alert.objects.first().state == Alert.STATE_NOTIFIED
        assert mock.call_count == 0
Esempio n. 5
0
    def test_warn_every_time(self, mock):
        observer = ObserverFactory.create(
            value=4, waiting_period=0, alert_every_time=True)
        AlertFactory.create(
            identifier=observer.get_alert_identifier(), state=Alert.STATE_NOTIFIED)

        assert Alert.objects.all().count() == 1
        assert Alert.objects.first().state == Alert.STATE_NOTIFIED
        assert mock.call_count == 0

        Alert.set(2, observer=observer)

        assert Alert.objects.all().count() == 1
        assert Alert.objects.first().state == Alert.STATE_NOTIFIED
        assert mock.call_count == 1
Esempio n. 6
0
    def test_warn_notified_identifier(self, mock):
        alert = AlertFactory.create(state=Alert.STATE_NOTIFIED)
        Alert.set(identifier=alert.identifier)

        assert Alert.objects.all().count() == 1
        assert Alert.objects.first().state == Alert.STATE_NOTIFIED
        assert mock.call_count == 0
Esempio n. 7
0
    def test_repr(self, activate_en):
        observer = ObserverFactory.create(name='my observer')
        obj = AlertFactory.create(id=23, identifier=observer.get_alert_identifier())

        assert str(obj) == 'Alert for howl-observer:{0}'.format(observer.pk)
Esempio n. 8
0
    def test_clear_identifier(self, mock):
        alert = AlertFactory.create()
        Alert.clear(identifier=alert.identifier)

        assert Alert.objects.all().count() == 0
        assert mock.call_count == 1
Esempio n. 9
0
    def test_get_observer_name(self, rf):
        observer = ObserverFactory.create()
        alert = AlertFactory.create(observer=observer)

        modeladmin = AlertAdmin(Alert, admin.site)
        assert modeladmin.get_observer_name(alert) == observer.name
Esempio n. 10
0
    def test_repr(self, activate_en):
        observer = ObserverFactory.create(name='my observer')
        obj = AlertFactory.create(id=23, observer=observer)

        assert str(obj) == 'Alert (ID: 23) for my observer'