Skip to content

Commit

Permalink
Merge pull request #35 from rwblair/report_feedback
Browse files Browse the repository at this point in the history
Allow api to take user report feedback
  • Loading branch information
oesteban authored Mar 22, 2018
2 parents 449bb93 + e17b856 commit f5fce8d
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 3 deletions.
47 changes: 44 additions & 3 deletions dockereve-master/eve-app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@
'RESOURCE_METHODS': ['GET', 'POST'],
'ITEM_METHODS': ['GET'],
'X_DOMAINS': '*',
'X_HEADERS': ['Authorization', 'Content-Type'],
'DOMAIN': {
'bold': {
'item_title': 'bold',
Expand All @@ -574,6 +575,42 @@
}
}

rating_schema = {
'rating': {
'type': 'string',
'required': True
},
'name': {
'type': 'string',
'required': False
},
'comment': {
'type': 'string',
'required': False
},
'md5sum': {
'type': 'string',
'required': True
}
}
settings['DOMAIN']['rating'] ={
'type': 'dict',
'required': False,
'schema': deepcopy(rating_schema)
}

settings['DOMAIN']['rating_counts'] = {
'datasource': {
'source': 'rating',
'aggregation': {
'pipeline': [
{"$match": {"md5sum": "$value"}},
{"$unwind": "$rating"},
{"$group": {"_id": "$rating", "count": {"$sum": 1}}},
],
}
}
}

settings['DOMAIN']['bold']['schema'] = deepcopy(bold_iqms_schema)
settings['DOMAIN']['bold']['schema'].update(
Expand All @@ -588,7 +625,12 @@
'type': 'dict',
'required': True,
'schema': deepcopy(prov_schema)
}
},
'rating': {
'type': 'dict',
'required': False,
'schema': deepcopy(rating_schema)
},
}
)

Expand All @@ -613,9 +655,8 @@
'type': 'dict',
'required': True,
'schema': deepcopy(prov_schema)
}
},
}
)

settings['DOMAIN']['T2w']['schema'] = deepcopy(settings['DOMAIN']['T1w']['schema'])

4 changes: 4 additions & 0 deletions test/rating/validData/sub-50137_rating.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"rating": "good",
"md5sum": "57cd35190da3c813a3c3dadccd8a4ad7"
}
4 changes: 4 additions & 0 deletions test/rating/validData/sub-50137_rating_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"rating": "good",
"md5sum": "57cd35190da3c813a3c3dadccd8a4ad7"
}
4 changes: 4 additions & 0 deletions test/rating/validData/sub-50137_rating_2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"rating": "good",
"md5sum": "57cd35190da3c813a3c3dadccd8a4ad7"
}
4 changes: 4 additions & 0 deletions test/rating/validData/sub-50137_rating_3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"rating": "bad",
"md5sum": "57cd35190da3c813a3c3dadccd8a4ad7"
}
25 changes: 25 additions & 0 deletions test/testGetPost.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# test data directory
boldPattern = os.path.join('test/bold/validData', '*.json')
T1wPattern = os.path.join('test/T1w/validData', '*.json')
ratingPattern = os.path.join('test/rating/validData', '*.json')

# missing field data directory
boldMissingPattern = os.path.join('test/bold/missingField', '*.json')
Expand All @@ -35,6 +36,8 @@ def getRequest(post_resp, url):
numOfTestData = 84
urlBold = "http://0.0.0.0:80/api/v1/bold"
urlT1w = "http://0.0.0.0:80/api/v1/T1w"
urlRating = "http://0.0.0.0:80/api/v1/rating"
urlRatingCounts = 'http://0.0.0.0:80/api/v1/rating_counts?{}'
codeForInvalid = 422


Expand Down Expand Up @@ -208,6 +211,28 @@ def test_09_failedAuth(self):
headers=header)
self.assertTrue(postResponse.status_code == 401) # ****************

def test_10_ratingDataValid(self):
for file_name in glob(ratingPattern):
with open(file_name) as fp:
input_data = json.load(fp)

# 2. POST request
post_resp = requests.post(
urlRating, data=json.dumps(input_data),
headers=authenticated_header)
self.assertTrue(post_resp.raise_for_status() is None)

# retrive counts of ratings we just submitted
get_resp = requests.get(
urlRatingCounts.format('aggregate={"$value":"57cd35190da3c813a3c3dadccd8a4ad7"}'),
headers=authenticated_header
)
data = get_resp.json()
for elem in data['_items']:
if elem['_id'] == "good":
self.assertTrue(elem['count'] == 3)
if elem['_id'] == "bad":
self.assertTrue(elem['count'] == 1)

if __name__ == '__main__':
logging.basicConfig(stream=sys.stderr)
Expand Down

0 comments on commit f5fce8d

Please sign in to comment.