예제 #1
0
def test_operator_validator(setup_database):
    dbsession = setup_database

    # Test passing with empty SQL result
    alert1 = create_alert(dbsession,
                          "SELECT first FROM test_table WHERE first = -1")
    observe(alert1.id, dbsession)
    assert operator_validator(alert1, '{"op": ">=", "threshold": 60}') is False
    # ensure that 0 threshold works
    assert operator_validator(alert1, '{"op": ">=", "threshold": 0}') is False

    # Test passing with result that doesn't pass a greater than threshold
    alert2 = create_alert(dbsession, "SELECT 55")
    observe(alert2.id, dbsession)
    assert operator_validator(alert2, '{"op": ">=", "threshold": 60}') is False

    # Test passing with result that passes a greater than threshold
    assert operator_validator(alert2, '{"op": ">=", "threshold": 40}') is True

    # Test passing with result that doesn't pass a less than threshold
    assert operator_validator(alert2, '{"op": "<=", "threshold": 40}') is False

    # Test passing with result that passes threshold
    assert operator_validator(alert2, '{"op": "<=", "threshold": 60}') is True

    # Test passing with result that doesn't equal threshold
    assert operator_validator(alert2, '{"op": "==", "threshold": 60}') is False

    # Test passing with result that equals threshold
    assert operator_validator(alert2, '{"op": "==", "threshold": 55}') is True

    # Test passing with result that equals decimal threshold
    assert operator_validator(alert2,
                              '{"op": ">", "threshold": 54.999}') is True
예제 #2
0
def test_operator_validator(setup_database):
    dbsession = setup_database

    # Test passing SQLObserver with empty SQL result
    alert1 = create_alert(dbsession,
                          "SELECT first FROM test_table WHERE first = -1")
    observe(alert1.id, dbsession)
    assert (operator_validator(alert1.sql_observer[0],
                               '{"op": ">=", "threshold": 60}') is False)

    # Test passing SQLObserver with result that doesn't pass a greater than threshold
    alert2 = create_alert(dbsession, "SELECT 55")
    observe(alert2.id, dbsession)
    assert (operator_validator(alert2.sql_observer[0],
                               '{"op": ">=", "threshold": 60}') is False)

    # Test passing SQLObserver with result that passes a greater than threshold
    assert (operator_validator(alert2.sql_observer[0],
                               '{"op": ">=", "threshold": 40}') is True)

    # Test passing SQLObserver with result that doesn't pass a less than threshold
    assert (operator_validator(alert2.sql_observer[0],
                               '{"op": "<=", "threshold": 40}') is False)

    # Test passing SQLObserver with result that passes threshold
    assert (operator_validator(alert2.sql_observer[0],
                               '{"op": "<=", "threshold": 60}') is True)

    # Test passing SQLObserver with result that doesn't equal threshold
    assert (operator_validator(alert2.sql_observer[0],
                               '{"op": "==", "threshold": 60}') is False)

    # Test passing SQLObserver with result that equals threshold
    assert (operator_validator(alert2.sql_observer[0],
                               '{"op": "==", "threshold": 55}') is True)