diff --git a/dockereve-master/eve-app/settings.py b/dockereve-master/eve-app/settings.py index 5132f72..1eff30e 100644 --- a/dockereve-master/eve-app/settings.py +++ b/dockereve-master/eve-app/settings.py @@ -560,6 +560,7 @@ 'RESOURCE_METHODS': ['GET', 'POST'], 'ITEM_METHODS': ['GET'], 'X_DOMAINS': '*', + 'X_HEADERS': ['Authorization', 'Content-Type'], 'DOMAIN': { 'bold': { 'item_title': 'bold', @@ -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( @@ -588,7 +625,12 @@ 'type': 'dict', 'required': True, 'schema': deepcopy(prov_schema) - } + }, + 'rating': { + 'type': 'dict', + 'required': False, + 'schema': deepcopy(rating_schema) + }, } ) @@ -613,9 +655,8 @@ 'type': 'dict', 'required': True, 'schema': deepcopy(prov_schema) - } + }, } ) settings['DOMAIN']['T2w']['schema'] = deepcopy(settings['DOMAIN']['T1w']['schema']) - diff --git a/test/rating/validData/sub-50137_rating.json b/test/rating/validData/sub-50137_rating.json new file mode 100644 index 0000000..239f672 --- /dev/null +++ b/test/rating/validData/sub-50137_rating.json @@ -0,0 +1,4 @@ +{ + "rating": "good", + "md5sum": "57cd35190da3c813a3c3dadccd8a4ad7" +} diff --git a/test/rating/validData/sub-50137_rating_1.json b/test/rating/validData/sub-50137_rating_1.json new file mode 100644 index 0000000..239f672 --- /dev/null +++ b/test/rating/validData/sub-50137_rating_1.json @@ -0,0 +1,4 @@ +{ + "rating": "good", + "md5sum": "57cd35190da3c813a3c3dadccd8a4ad7" +} diff --git a/test/rating/validData/sub-50137_rating_2.json b/test/rating/validData/sub-50137_rating_2.json new file mode 100644 index 0000000..239f672 --- /dev/null +++ b/test/rating/validData/sub-50137_rating_2.json @@ -0,0 +1,4 @@ +{ + "rating": "good", + "md5sum": "57cd35190da3c813a3c3dadccd8a4ad7" +} diff --git a/test/rating/validData/sub-50137_rating_3.json b/test/rating/validData/sub-50137_rating_3.json new file mode 100644 index 0000000..3f4b479 --- /dev/null +++ b/test/rating/validData/sub-50137_rating_3.json @@ -0,0 +1,4 @@ +{ + "rating": "bad", + "md5sum": "57cd35190da3c813a3c3dadccd8a4ad7" +} diff --git a/test/testGetPost.py b/test/testGetPost.py index a6003ec..ca37f23 100644 --- a/test/testGetPost.py +++ b/test/testGetPost.py @@ -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') @@ -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 @@ -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)