def test_delete_datapoint(populated_db, caplog): db.delete_datapoint(1) with pytest.raises(DoesNotExist): db.get_datapoint(1) assert "Deleting datapoint" in caplog.text datapoint = db.get_datapoint(5) db.delete_datapoint(datapoint) with pytest.raises(DoesNotExist): db.get_datapoint(5) assert str(datapoint) in caplog.text
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
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
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
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
def test_get_datapoint(populated_db): rv = db.get_datapoint(5) assert isinstance(rv, orm.DataPoint) assert rv.metric_id == 3 assert rv.metric.name == "foo.bar" assert rv.value == 1 # Check that the timestamp is naive # https://docs.python.org/3/library/datetime.html#datetime.timezone d = rv.timestamp assert (d.tzinfo is None) or (d.tzinfo.utcoffset(d) is None)
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
def test_get_datapoint_not_found(populated_db, caplog): with pytest.raises(DoesNotExist): db.get_datapoint(999)