Ejemplo n.º 1
0
def test_add_metric(app):
    rv = db.add_metric("foo", "bar")
    assert rv.name == "foo"
    assert rv.units == "bar"

    # Verify that we've actually written to the DB.
    assert len(db.Metric.select()) == 1
Ejemplo n.º 2
0
def populated_db(app):
    # XXX: Should this be using my functions or should it use pure PeeWee
    # stuff like `DataPoint.create(metric=1, value=15, timestamp=1546450008)`?
    db.add_metric("empty_metric", "units")
    db.add_metric("foo")
    db.add_metric("foo.bar")
    db.add_metric("metric_with_units", "apples")
    db.add_metric("old_data")
    db.add_metric("with_everything", "percent", 20, 100)
    db.insert_datapoint("foo", 15)
    db.insert_datapoint("foo", 17)
    db.insert_datapoint("foo", 25)
    db.insert_datapoint("foo", 9)
    db.insert_datapoint("foo.bar", 1)
    db.insert_datapoint("foo.bar", -2)
    db.insert_datapoint("old_data", 0, 0)  # 1970-01-01T00:00:00Z
    db.insert_datapoint("old_data", 1, 1545321236)  # 2018-12-20T15:53:56Z
    db.insert_datapoint("old_data", 5, 1546532003)  # 2019-01-03T16:13:23Z
    db.insert_datapoint("old_data", 8, 1546532067)  # 2019-01-03T16:14:27Z
Ejemplo n.º 3
0
def test_add_metric_raises_type_error(caplog, lower, upper):
    with pytest.raises(TypeError):
        db.add_metric("foo", "bar", lower, upper)
    assert "Invalid type for limits" in caplog.text
Ejemplo n.º 4
0
def test_add_metric_with_invalid_limits_raises_value_error(caplog):
    with pytest.raises(ValueError):
        db.add_metric("foo", "bar", 16, -54.452)
    assert "upper_limit not greater than lower_limit" in caplog.text
Ejemplo n.º 5
0
def test_add_metric_with_lower_limit(app):
    rv = db.add_metric("foo", "bar", -16.33)
    assert rv.name == "foo"
    assert rv.units == "bar"
    assert rv.upper_limit is None
    assert rv.lower_limit == -16.33
Ejemplo n.º 6
0
def test_add_metric_with_upper_limit(app):
    rv = db.add_metric("foo", "bar", None, 15)
    assert rv.name == "foo"
    assert rv.units == "bar"
    assert rv.upper_limit == 15
    assert rv.lower_limit is None