-
Notifications
You must be signed in to change notification settings - Fork 86
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
Showing
8 changed files
with
374 additions
and
11 deletions.
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
15 changes: 15 additions & 0 deletions
15
interface/static/data/json/programmatic_interface/bagr/dataset_url/bagr-model-predict.json
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"properties": { | ||
"collection": "bagr-1", | ||
"session_type": "model_predict", | ||
"prediction_input[]": [ | ||
"22.22", | ||
"96.24", | ||
"338", | ||
"72.55", | ||
"0.001", | ||
"28", | ||
"0.678" | ||
] | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
interface/static/data/json/programmatic_interface/bagr/file_upload/bagr-data-append.json
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
2 changes: 1 addition & 1 deletion
2
interface/static/data/json/programmatic_interface/bagr/file_upload/bagr-data-new.json
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
15 changes: 15 additions & 0 deletions
15
interface/static/data/json/programmatic_interface/bagr/file_upload/bagr-model-predict.json
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"properties": { | ||
"collection": "bagr-2", | ||
"session_type": "model_predict", | ||
"prediction_input[]": [ | ||
"22.22", | ||
"96.24", | ||
"338", | ||
"72.55", | ||
"0.001", | ||
"28", | ||
"0.678" | ||
] | ||
} | ||
} |
160 changes: 160 additions & 0 deletions
160
test/live_server/3_programmatic_interface/dataset_url/pytest_bagr_dataset_url.py
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 |
---|---|---|
@@ -0,0 +1,160 @@ | ||
''' | ||
This file will test the following bagr sessions: | ||
- data_new: stores supplied dataset into a SQL database. | ||
- data_append: appends supplied dataset to an already stored dataset in an | ||
SQL database. | ||
- model_generate: generate an model by selecting a particular range of | ||
dataset (session), and store it into a NoSQL cache. | ||
- model_predict: generate a prediction by selecting a particular cached | ||
model from the NoSQL cache. | ||
Note: the 'pytest' instances can further be reviewed: | ||
- https://pytest-flask.readthedocs.io/en/latest | ||
- http://docs.pytest.org/en/latest/usage.html | ||
''' | ||
|
||
import json | ||
import os.path | ||
from flask import current_app, url_for | ||
|
||
|
||
def get_sample_json(jsonfile, model_type): | ||
''' | ||
Get a sample json dataset. | ||
''' | ||
|
||
# local variables | ||
root = current_app.config.get('ROOT') | ||
|
||
# open file | ||
json_dataset = None | ||
|
||
with open( | ||
os.path.join( | ||
root, | ||
'interface', | ||
'static', | ||
'data', | ||
'json', | ||
'programmatic_interface', | ||
model_type, | ||
'dataset_url', | ||
jsonfile | ||
), | ||
'r' | ||
) as json_file: | ||
json_dataset = json.load(json_file) | ||
|
||
return json.dumps(json_dataset) | ||
|
||
|
||
def test_data_new(client, live_server): | ||
''' | ||
This method tests the 'data_new' session. | ||
''' | ||
|
||
@live_server.app.route('/load-data') | ||
def get_endpoint(): | ||
return url_for('name.load_data', _external=True) | ||
|
||
live_server.start() | ||
|
||
res = client.post( | ||
get_endpoint(), | ||
headers={'Content-Type': 'application/json'}, | ||
data=get_sample_json('bagr-data-new.json', 'bagr') | ||
) | ||
|
||
# assertion checks | ||
assert res.status_code == 200 | ||
assert res.json['status'] == 0 | ||
|
||
|
||
def test_data_append(client, live_server): | ||
''' | ||
This method tests the 'data_new' session. | ||
''' | ||
|
||
@live_server.app.route('/load-data') | ||
def get_endpoint(): | ||
return url_for('name.load_data', _external=True) | ||
|
||
live_server.start() | ||
|
||
res = client.post( | ||
get_endpoint(), | ||
headers={'Content-Type': 'application/json'}, | ||
data=get_sample_json('bagr-data-append.json', 'bagr') | ||
) | ||
|
||
# assertion checks | ||
assert res.status_code == 200 | ||
assert res.json['status'] == 0 | ||
|
||
|
||
def test_model_generate(client, live_server): | ||
''' | ||
This method tests the 'model_generate' session. | ||
''' | ||
|
||
@live_server.app.route('/load-data') | ||
def get_endpoint(): | ||
return url_for('name.load_data', _external=True) | ||
|
||
live_server.start() | ||
|
||
res = client.post( | ||
get_endpoint(), | ||
headers={'Content-Type': 'application/json'}, | ||
data=get_sample_json('bagr-model-generate.json', 'bagr') | ||
) | ||
|
||
# assertion checks | ||
assert res.status_code == 200 | ||
assert res.json['status'] == 0 | ||
|
||
|
||
def test_model_predict(client, live_server): | ||
''' | ||
This method tests the 'model_predict' session. | ||
Note: for debugging, the following syntax will output the corresponding | ||
json values, nested within 'json.loads()', to the travis ci: | ||
raise ValueError(res.json['result']['key1']) | ||
''' | ||
|
||
@live_server.app.route('/load-data') | ||
def get_endpoint(): | ||
return url_for('name.load_data', _external=True) | ||
|
||
live_server.start() | ||
|
||
res = client.post( | ||
get_endpoint(), | ||
headers={'Content-Type': 'application/json'}, | ||
data=get_sample_json('bagr-model-predict.json', 'bagr') | ||
) | ||
|
||
# assertion checks | ||
assert res.status_code == 200 | ||
assert res.json['status'] == 0 | ||
assert res.json['result'] | ||
assert res.json['result']['confidence'] | ||
assert res.json['result']['confidence']['score'] == '0.96282488659958954' | ||
assert res.json['result']['model'] == 'bagr' | ||
assert res.json['result']['result'] == '33.4442' |
Oops, something went wrong.