Skip to content

Commit

Permalink
added abao tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hkethi002 committed Nov 1, 2017
1 parent 5af5208 commit 9cb4adb
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 4 deletions.
3 changes: 1 addition & 2 deletions api/handlers/savedsearchhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions raml/api.raml
Original file line number Diff line number Diff line change
Expand Up @@ -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
29 changes: 29 additions & 0 deletions raml/resources/savesearch.raml
Original file line number Diff line number Diff line change
@@ -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

11 changes: 11 additions & 0 deletions raml/schemas/output/search-list.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
8 changes: 8 additions & 0 deletions raml/schemas/output/search-output.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
65 changes: 63 additions & 2 deletions test/integration_tests/abao/abao_test_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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();
})

0 comments on commit 9cb4adb

Please sign in to comment.