Ejemplo n.º 1
0
    def test_no_warning_period(self, mock):
        observer = ObserverFactory.create(value=4, waiting_period=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
Ejemplo 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
Ejemplo n.º 3
0
    def test_warn_observer(self, mock):
        observer = ObserverFactory.create(value=4, waiting_period=5)
        Alert.set(2, observer=observer)

        assert Alert.objects.all().count() == 1
        assert Alert.objects.first().state == Alert.STATE_WAITING
        assert mock.call_count == 1
Ejemplo n.º 4
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
Ejemplo n.º 5
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
Ejemplo n.º 6
0
    def test_warn_critical(self, mock):
        observer = ObserverFactory.create(value=4, waiting_period=0)
        AlertFactory.create(observer=observer, state=Alert.STATE_WAITING)

        Alert.set(observer, 2)

        assert Alert.objects.all().count() == 1
        assert Alert.objects.first().state == Alert.STATE_NOTIFIED
        assert mock.call_count == 1
Ejemplo n.º 7
0
    def test_get_alert(self, value, compare_value, count_objects):
        obj = ObserverFactory.create(value=value)

        assert Alert.objects.all().count() == 0
        alert = obj.get_alert(compare_value)
        assert Alert.objects.all().count() == count_objects

        if alert:
            assert alert == Alert.objects.first()
Ejemplo n.º 8
0
    def test_warn_notified_observer(self, mock):
        observer = ObserverFactory.create(value=4, waiting_period=0)
        AlertFactory.create(
            identifier=observer.get_alert_identifier(), state=Alert.STATE_NOTIFIED)
        Alert.set(2, observer=observer)

        assert Alert.objects.all().count() == 1
        assert Alert.objects.first().state == Alert.STATE_NOTIFIED
        assert mock.call_count == 0
Ejemplo n.º 9
0
    def test_warn_every_time(self, mock):
        observer = ObserverFactory.create(value=4, waiting_period=0, alert_every_time=True)
        AlertFactory.create(observer=observer, 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(observer, 2)

        assert Alert.objects.all().count() == 1
        assert Alert.objects.first().state == Alert.STATE_NOTIFIED
        assert mock.call_count == 1
Ejemplo n.º 10
0
 def test_alert_identifier(self):
     obj = ObserverFactory.create(name='test observer')
     assert obj.get_alert_identifier() == 'howl-observer:{0}'.format(obj.pk)
Ejemplo n.º 11
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)
Ejemplo n.º 12
0
    def test_compare(self, value, compare_value, return_value, count_objects):
        obj = ObserverFactory.create(value=value)

        assert Alert.objects.all().count() == 0
        assert obj.compare(compare_value) is return_value
        assert Alert.objects.all().count() == count_objects
Ejemplo n.º 13
0
 def test_alert_identifier_from_kwargs(self):
     obj = ObserverFactory.create(name='test observer')
     assert obj.get_alert_identifier(identifier='foo-bar') == 'foo-bar'
Ejemplo n.º 14
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
Ejemplo n.º 15
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'
Ejemplo n.º 16
0
    def test_repr(self):
        obj = ObserverFactory.create(name='test observer')

        assert str(obj) == 'test observer'
Ejemplo n.º 17
0
    def test_compare(self, operator_class, value, compare_value, return_value):
        observer = ObserverFactory.create(operator=operator_class.__name__, value=value)

        operator_class(observer).compare(value) is return_value
Ejemplo n.º 18
0
 def test_compare_not_implemented(self):
     observer = ObserverFactory.create()
     with pytest.raises(NotImplementedError):
         BaseOperator(observer).compare(1)