forked from trainindata/deploying-machine-learning-models
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
17948c1
commit b02a156
Showing
2 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,36 @@ | ||
from regression_model.config import config as model_config | ||
from regression_model.processing.data_management import load_dataset | ||
from regression_model import __version__ as _version | ||
|
||
import json | ||
import math | ||
|
||
|
||
def test_health_endpoint_returns_200(flask_test_client): | ||
# When | ||
response = flask_test_client.get('/health') | ||
|
||
# Then | ||
assert response.status_code == 200 | ||
|
||
|
||
def test_prediction_endpoint_returns_prediction(flask_test_client): | ||
# Given | ||
# Load the test data from the regression_model package | ||
# This is important as it makes it harder for the test | ||
# data versions to get confused by not spreading it | ||
# across packages. | ||
test_data = load_dataset(file_name=model_config.TESTING_DATA_FILE) | ||
post_json = test_data[0:1].to_json(orient='records') | ||
|
||
# When | ||
response = flask_test_client.post('/v1/predict/regression', | ||
json=post_json) | ||
|
||
# Then | ||
assert response.status_code == 200 | ||
response_json = json.loads(response.data) | ||
prediction = response_json['predictions'] | ||
response_version = response_json['version'] | ||
assert math.ceil(prediction) == 112476 | ||
assert response_version == _version |