Beispiel #1
0
def test_update_datapoint_metric_by_id(app, populated_db, caplog):
    original = deepcopy(db.get_datapoint(1))

    db.update_datapoint(1, metric=4)
    new = db.get_datapoint(1)
    assert new.datapoint_id == original.datapoint_id
    assert new.metric != original.metric
    assert new.metric.metric_id == 4
    assert new.value == original.value
    assert new.timestamp == original.timestamp
    assert "Updating datapoint" in caplog.text
Beispiel #2
0
def test_update_datapoint_by_object(populated_db, caplog):
    datapoint = db.get_datapoint(1)
    original = deepcopy(datapoint)

    db.update_datapoint(datapoint, value=55)
    new = db.get_datapoint(1)
    assert new.datapoint_id == original.datapoint_id
    assert new.value == 55
    assert new.timestamp == original.timestamp
    assert "Updating datapoint" in caplog.text
    assert str(original) in caplog.text
Beispiel #3
0
def test_update_datapoint_value_by_id(populated_db, val, caplog):
    # Get our original datapoint. DeepCopy avoids by-reference issues.
    original = deepcopy(db.get_datapoint(1))

    rv = db.update_datapoint(1, value=val)
    assert isinstance(rv, db.DataPoint)
    new = db.get_datapoint(1)
    assert rv == new
    assert new.datapoint_id == original.datapoint_id
    assert new.value == val
    assert new.timestamp == original.timestamp
    assert "Updating datapoint" in caplog.text
Beispiel #4
0
def test_update_datapoint_timestamp_by_id(populated_db, dt, expected, caplog):
    # Get our original datapoint. DeepCopy avoids by-reference issues.
    original = deepcopy(db.get_datapoint(1))

    # Update the value
    rv = db.update_datapoint(1, timestamp=dt)
    assert isinstance(rv, db.DataPoint)

    # Verify the new value
    new = db.get_datapoint(1)
    assert rv == new
    assert new.datapoint_id == original.datapoint_id
    assert new.value == original.value
    assert isinstance(new.timestamp, datetime)
    assert new.timestamp == expected
    assert "Updating datapoint" in caplog.text
Beispiel #5
0
def test_update_datapoint_by_object_does_not_exist(populated_db, caplog):
    datapoint = orm.DataPoint(metric_id=1, value=1, timestamp=1)
    with pytest.raises(DoesNotExist):
        db.update_datapoint(datapoint, value=55)
Beispiel #6
0
def test_update_datapoint_no_values_given(populated_db, caplog):
    original = deepcopy(db.get_datapoint(1))
    db.update_datapoint(1)
    new = db.get_datapoint(1)
    assert new == original
    assert "No new values given" in caplog.text
Beispiel #7
0
def test_update_datapoint_value_by_id_not_found(populated_db, caplog):
    with pytest.raises(DoesNotExist):
        db.update_datapoint(999, value=123)
    assert "Unable to find datapoint" in caplog.text
    assert "999" in caplog.text
Beispiel #8
0
def test_update_datapoint_metric_by_id_metric_not_found(app, populated_db):
    with pytest.raises(IntegrityError):
        db.update_datapoint(1, metric=99)