From 9cb4adb4500d5c60e33af543c40f24156b8b51b6 Mon Sep 17 00:00:00 2001 From: Harsha Kethineni Date: Wed, 9 Aug 2017 10:13:35 -0500 Subject: [PATCH] added abao tests --- api/handlers/savedsearchhandler.py | 3 +- raml/api.raml | 1 + raml/resources/savesearch.raml | 29 +++++++++ raml/schemas/output/search-list.json | 11 ++++ raml/schemas/output/search-output.json | 8 +++ .../integration_tests/abao/abao_test_hooks.js | 65 ++++++++++++++++++- 6 files changed, 113 insertions(+), 4 deletions(-) create mode 100644 raml/resources/savesearch.raml create mode 100644 raml/schemas/output/search-list.json create mode 100644 raml/schemas/output/search-output.json diff --git a/api/handlers/savedsearchhandler.py b/api/handlers/savedsearchhandler.py index 362f47b1b..64ed62ea6 100644 --- a/api/handlers/savedsearchhandler.py +++ b/api/handlers/savedsearchhandler.py @@ -52,12 +52,11 @@ def replace_search(self, sid): if payload.get('_id'): del(payload['_id']) if payload.get('permissions'): - perms = payload['permissions'] del(payload['permissions']) validators.validate_data(payload, 'search-input.json', 'input', 'POST') payload['_id'] = bson.ObjectId(sid) - payload['permissions'] = perms search = storage.get_container(sid) + payload['permissions'] = search['permissions'] permchecker = groupauth.default(self, search) permchecker(noop)('DELETE', sid) result = storage.replace_el(payload) diff --git a/raml/api.raml b/raml/api.raml index 27623b518..8ade5bf47 100644 --- a/raml/api.raml +++ b/raml/api.raml @@ -55,3 +55,4 @@ resourceTypes: /acquisitions: !include resources/acquisitions.raml /projects: !include resources/projects.raml /report: !include resources/report.raml +/savesearch: !include resources/savesearch.raml diff --git a/raml/resources/savesearch.raml b/raml/resources/savesearch.raml new file mode 100644 index 000000000..2e6751783 --- /dev/null +++ b/raml/resources/savesearch.raml @@ -0,0 +1,29 @@ +type: container +get: + description: List all saved searches user has access to. + responses: + 200: + body: + application/json: + schema: !include ../schemas/output/search-list.json +post: + body: + application/json: + schema: !include ../schemas/input/search-input.json +/{SearchId}: + type: container + get: + responses: + 200: + body: + application/json: + schema: !include ../schemas/output/search-output.json + delete: + description: Delete a saved search + responses: + 200: + body: + application/json: + schema: !include ../schemas/output/container-delete.json + example: !include ../examples/output/container-delete.json + diff --git a/raml/schemas/output/search-list.json b/raml/schemas/output/search-list.json new file mode 100644 index 000000000..058612f9c --- /dev/null +++ b/raml/schemas/output/search-list.json @@ -0,0 +1,11 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type":"array", + "items":{ + "type":"object", + "allOf":[{"$ref":"../definitions/search.json#/definitions/search-output"}], + "required":[ + "_id", "label", "permissions", "search" + ] + } +} \ No newline at end of file diff --git a/raml/schemas/output/search-output.json b/raml/schemas/output/search-output.json new file mode 100644 index 000000000..03fb92b8a --- /dev/null +++ b/raml/schemas/output/search-output.json @@ -0,0 +1,8 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type":"object", + "allOf":[{"$ref":"../definitions/search.json#/definitions/search-output"}], + "required":[ + "_id", "label", "permissions", "search" + ] +} \ No newline at end of file diff --git a/test/integration_tests/abao/abao_test_hooks.js b/test/integration_tests/abao/abao_test_hooks.js index 270c43aae..99814b096 100644 --- a/test/integration_tests/abao/abao_test_hooks.js +++ b/test/integration_tests/abao/abao_test_hooks.js @@ -21,8 +21,9 @@ var example_acquisition_id = ''; var test_project_1 = null; var test_project_tag = 'test-project-tag'; var delete_project_id = ''; -var device_id = 'bootstrapper_Bootstrapper' -var injected_api_key = 'XZpXI40Uk85eozjQkU1zHJ6yZHpix+j0mo1TMeGZ4dPzIqVPVGPmyfeK' +var device_id = 'bootstrapper_Bootstrapper'; +var injected_api_key = 'XZpXI40Uk85eozjQkU1zHJ6yZHpix+j0mo1TMeGZ4dPzIqVPVGPmyfeK'; +var search_id = ''; // Tests we're skipping, fix these @@ -1461,3 +1462,63 @@ hooks.before("GET /devices/{DeviceId} -> 404", function(test, done) { test.request.params.DeviceId = 'bad_device_id'; done(); }); + +// Save Search Tests +hooks.before("POST /savesearch -> 200", function(test, done) { + test.request.body = { + "label": "Lable", + "search": { + "return_type": "session" + } + }; + done(); +}) +hooks.after("POST /savesearch -> 200", function(test, done) { + search_id = test.response.body['_id']; + done(); +}) + +hooks.before("POST /savesearch -> 400", function(test, done) { + test.request.body = { + "not-label": "Label" + }; + done(); +}) + +hooks.before("GET /savesearch/{SearchId} -> 200", function(test, done) { + test.request.params = { + SearchId: search_id + }; + done(); +}) + +hooks.before("POST /savesearch/{SearchId} -> 200", function(test, done) { + test.request.params = { + SearchId: search_id + }; + test.request.body = { + "label": "New Label", + "search": { + "return_type": "session" + }, + "_id": search_id + }; + done(); +}) + +hooks.before("POST /savesearch/{SearchId} -> 400", function(test, done) { + test.request.params = { + SearchId: search_id + }; + test.request.body = { + "not-label": "Label2" + }; + done(); +}) + +hooks.before("DELETE /savesearch/{SearchId} -> 200", function(test, done) { + test.request.params = { + SearchId: search_id + }; + done(); +})