Skip to content

Commit

Permalink
Merge 33f42c2 into 1bce29d
Browse files Browse the repository at this point in the history
  • Loading branch information
dougthor42 committed Feb 25, 2019
2 parents 1bce29d + 33f42c2 commit 30f95ea
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -15,6 +15,7 @@
+ `POST /api/v1/metric` has been implemented (#74)
+ `PUT /api/v1/metric/<metric_name>` has been implemented (#75)
+ `PATCH /api/v1/metric/<metric_name>` has been implemented (#83)
+ `DELETE /api/v1/datapoint/<datapoint_id>` has been implemented (#57)
+ Error responses for the REST API have been refactored (#85)
+ Additional tests for PUT/PATCH metric have been added (#86)
+ Make use of peewee's `playhouse` extensions for converting model instances
Expand Down
5 changes: 5 additions & 0 deletions src/trendlines/error_responses.py
Expand Up @@ -32,6 +32,11 @@ def metric_not_found(cls, name):
detail = "The metric '{}' does not exist".format(name)
return error_response(404, ErrorResponseType.NOT_FOUND, detail)

@classmethod
def datapoint_not_found(cls, datapoint_id):
detail = "The datapoint '{}' does not exist".format(datapoint_id)
return error_response(404, ErrorResponseType.NOT_FOUND, detail)

@classmethod
def metric_has_no_data(cls, name):
detail = "No data exists for metric '{}'.".format(name)
Expand Down
10 changes: 9 additions & 1 deletion src/trendlines/routes.py
Expand Up @@ -153,7 +153,15 @@ def api_delete_datapoint(datapoint_id):
"""
Delete a datapoint.
"""
pass
logger.debug("'api: DELETE datapoint '%s'" % datapoint_id)

try:
found = db.DataPoint.get(db.DataPoint.datapoint_id == datapoint_id)
found.delete_instance()
except DoesNotExist:
return ErrorResponse.datapoint_not_found(datapoint_id)
else:
return "", 204


@api.route("/api/v1/metric", methods=["GET"])
Expand Down
22 changes: 22 additions & 0 deletions tests/test_routes.py
Expand Up @@ -77,6 +77,28 @@ def test_api_get_data_as_json_no_data_for_metric(client, populated_db):
assert 'No data exists for metric' in d['detail']


def test_api_delete_datapoint(client, populated_db):
datapoint_id = 6
rv = client.delete("/api/v1/datapoint/{}".format(datapoint_id))
assert rv.status_code == 204

# Verify it's actually been deleted
# TODO: needs the datapoint GET route
# after = client.get("/api/v1/datapoint/{}".format(datapoint_id))
# assert after.status_code == 404


def test_api_delete_datapoint_not_found(client, populated_db, caplog):
datapoint_id = 103132
rv = client.delete("/api/v1/datapoint/{}".format(datapoint_id))
assert rv.status_code == 404
assert rv.is_json
d = rv.get_json()
assert str(datapoint_id) in d['detail']
assert d['title'] == "NOT_FOUND"
assert "API error" in caplog.text


def test_api_get_metric_as_json(client, populated_db, caplog):
rv = client.get("/api/v1/metric/foo")
assert rv.status_code == 200
Expand Down

0 comments on commit 30f95ea

Please sign in to comment.