Skip to content
Snippets Groups Projects
Commit 6ae7df81 authored by Nathaniel Kofalt's avatar Nathaniel Kofalt Committed by GitHub
Browse files

Merge pull request #496 from scitran/validate-gear-post

Add gear submission tests
parents a803bbb7 68b5089c
No related branches found
No related tags found
No related merge requests found
......@@ -6,5 +6,5 @@
/runtime
bootstrap.json
.cache
.coverage
/.coverage*
coverage.xml
......@@ -89,6 +89,8 @@ def suggest_container(gear, cont_name, cid):
return root
def insert_gear(doc):
gear_tools.validate_manifest(doc['manifest'])
config.db.singletons.update(
{"_id" : "gears"},
{'$push': {'gear_list': doc} }
......@@ -118,5 +120,7 @@ def remove_gear(name):
)
def upsert_gear(doc):
gear_tools.validate_manifest(doc['manifest'])
remove_gear(doc['name'])
insert_gear(doc)
......@@ -74,7 +74,20 @@ class GearHandler(base.RequestHandler):
if _id != doc.get('name', ''):
self.abort(400, 'Name key must be present and match URL')
upsert_gear(self.request.json)
try:
upsert_gear(self.request.json)
except ValidationError as err:
key = None
if len(err.relative_path) > 0:
key = err.relative_path[0]
self.response.set_status(400)
return {
'reason': 'Gear manifest does not match schema',
'error': err.message.replace("u'", "'"),
'key': key
}
return { 'name': _id }
def delete(self, _id):
......
{
"name": "dcm_convert",
"name": "test-case-gear",
"manifest": {
"config": {},
"name": "test-case-gear",
"label": "Test Case Gear",
"version": "0",
"author": "Nathaniel Kofalt",
"description": "A gear built to drive test cases",
"url": "http://none.example",
"source": "http://none.example",
"license": "MIT",
"config": {
"two-digit multiple of ten": {
"exclusiveMaximum": true,
"type": "number",
"multipleOf": 10,
"maximum": 100
}
},
"inputs": {
"dicom": {
"any text file <= 100 KB": {
"base": "file",
"type": {
"enum": [
"dicom"
]
"name": {
"pattern": "^.*.txt$"
},
"size": {
"maximum": 100000
}
}
}
}
}
\ No newline at end of file
},
"input": {}
}
{
"gear": "dcm_convert",
"inputs": {
"dicom": {
"type": "acquisition",
"id": "573c9e6a844eac7fc01747cd",
"name" : "1_1_dicom.zip"
}
},
"destination": {
"type": "acquisition",
"id": "573c9e6a844eac7fc01747cd"
},
"tags": [
"ad-hoc"
]
"gear": "test-case-gear",
"inputs": {
"dicom": {
"type": "acquisition",
"id": "573c9e6a844eac7fc01747cd",
"name" : "1_1_dicom.zip"
}
},
"config": {
"two-digit multiple of ten": 20
},
"destination": {
"type": "acquisition",
"id": "573c9e6a844eac7fc01747cd"
},
"tags": [
"ad-hoc"
]
}
......@@ -2,7 +2,7 @@ var hooks = require('hooks');
// Variables for passing results as input to subsequent tests
var job_id = '';
var gear_name = '';
var gear_name = 'test-case-gear';
var group_id = 'test_group';
// Tests we're skipping, fix these
......@@ -140,14 +140,14 @@ hooks.before("GET /gears/{GearName} -> 200", function(test, done) {
hooks.before("POST /gears/{GearName} -> 200", function(test, done) {
test.request.params = {
GearName: "dcm_convert"
GearName: gear_name
};
done();
});
hooks.before("GET /gears/{GearName} -> 200", function(test, done) {
test.request.params = {
GearName: "dcm_convert"
GearName: gear_name
};
done();
});
......
......@@ -2,7 +2,7 @@
"variables": [],
"info": {
"name": "test",
"_postman_id": "76371a5e-113e-8773-bb5a-1fb6e3d7ec08",
"_postman_id": "fc8f9020-aa70-327d-4e99-9c8a98db1009",
"description": "",
"schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json"
},
......@@ -118,35 +118,6 @@
},
"response": []
},
{
"name": "Add dcm_convert gear",
"event": [
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": "tests[\"Status code is 200\"] = responseCode.code === 200;\n\ntests[\"Response time is less than 200ms\"] = responseTime < 200;"
}
}
],
"request": {
"url": "{{baseUri}}/gears/dcm_convert?root=true",
"method": "POST",
"header": [
{
"key": "Authorization",
"value": "scitran-user {{test_user_api_key}}",
"description": ""
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"name\": \"dcm_convert\",\n\t\"manifest\": {\n\t\t\"config\": {},\n\t\t\"inputs\": {\n\t\t\t\"dicom\": {\n\t\t\t\t\"base\": \"file\",\n\t\t\t\t\"type\": {\n\t\t\t\t\t\"enum\": [\n\t\t\t\t\t\t\"dicom\"\n\t\t\t\t\t]\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t},\n\t\"input\": {}\n}"
},
"description": ""
},
"response": []
},
{
"name": "Create test-group",
"event": [
......@@ -298,7 +269,7 @@
"src": "test/integration_tests/postman/test_files/test-1.dcm",
"type": "file",
"enabled": true,
"value": "test-1.dcm"
"value": ""
}
]
},
......@@ -306,6 +277,64 @@
},
"response": []
},
{
"name": "Submit invalid gear",
"event": [
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": "tests[\"Status code is 400\"] = responseCode.code === 400;"
}
}
],
"request": {
"url": "{{baseUri}}/gears/test_gear?root=true",
"method": "post",
"header": [
{
"key": "Authorization",
"value": "scitran-user {{test_user_api_key}}",
"description": ""
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"category\": \"converter\",\n\t\"input\": { },\n\t\"name\": \"test_gear\",\n\t\"manifest\": {\n\t\t\"name\": \"test_gear\",\n\t\t\"inputs\": {\n\t\t\t\"any text file <= 100 KB\": {\n\t\t\t\t\"base\": \"file\",\n\t\t\t\t\"name\": {\n\t\t\t\t\t\"pattern\": \"^.*.txt$\"\n\t\t\t\t},\n\t\t\t\t\"size\": {\n\t\t\t\t\t\"maximum\": 100000\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t\"description\": \"A gear to test the API\",\n\t\t\"license\": \"Other\",\n\t\t\"author\": \"\",\n\t\t\"url\": \"https://unknown.example\",\n\t\t\"label\": \"An exported gear\",\n\t\t\"source\": \"https://unknown.example\",\n\t\t\"config\": {\n\t\t\t\"two-digit multiple of ten\": {\n\t\t\t\t\"exclusiveMaximum\": true,\n\t\t\t\t\"type\": \"number\",\n\t\t\t\t\"multipleOf\": 10,\n\t\t\t\t\"maximum\": 100\n\t\t\t}\n\t\t}\n\t}\n}"
},
"description": "Create or update a gear.\n\"Name\" field of gear must match \"GearName\" uri parameter\nIf no existing gear is found, one will be created\nOtherwise, the specified gear will be updated\n\n\nParameters:\n\nGearName: Name of the gear to interact with\n\n"
},
"response": []
},
{
"name": "Add test-case-gear gear",
"event": [
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": "tests[\"Status code is 200\"] = responseCode.code === 200;\n\ntests[\"Response time is less than 200ms\"] = responseTime < 200;"
}
}
],
"request": {
"url": "{{baseUri}}/gears/test-case-gear?root=true",
"method": "POST",
"header": [
{
"key": "Authorization",
"value": "scitran-user {{test_user_api_key}}",
"description": ""
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"name\": \"test-case-gear\",\n\t\"manifest\": {\n\t\t\"name\": \"test-case-gear\",\n\t\t\"label\": \"Test Case Gear\",\n\t\t\"version\": \"0\",\n\t\t\n\t\t\"author\": \"Nathaniel Kofalt\",\n\t\t\"description\": \"A gear built to drive test cases\",\n\t\t\n\t\t\"url\": \"http://none.example\",\n\t\t\"source\": \"http://none.example\",\n\t\t\"license\": \"MIT\",\n\t\t\n\t\t\"config\": {\n\t\t\t\"two-digit multiple of ten\": {\n\t\t\t\t\"exclusiveMaximum\": true,\n\t\t\t\t\"type\": \"number\",\n\t\t\t\t\"multipleOf\": 10,\n\t\t\t\t\"maximum\": 100\n\t\t\t}\n\t\t},\n\t\t\n\t\t\"inputs\": {\n\t\t\t\"any text file <= 100 KB\": {\n\t\t\t\t\"base\": \"file\",\n\t\t\t\t\"name\": {\n\t\t\t\t\t\"pattern\": \"^.*.txt$\"\n\t\t\t\t},\n\t\t\t\t\"size\": {\n\t\t\t\t\t\"maximum\": 100000\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t},\n\t\"input\": {}\n}"
},
"description": ""
},
"response": []
},
{
"name": "Add job",
"event": [
......@@ -329,7 +358,7 @@
],
"body": {
"mode": "raw",
"raw": "{\n \"gear\": \"dcm_convert\",\n \"inputs\": {\n \"dicom\": {\n \"type\": \"acquisition\",\n \"id\": \"{{test-acquisition-id}}\",\n \"name\" : \"1_1_dicom.zip\"\n }\n },\n \"destination\": {\n \"type\": \"acquisition\",\n \"id\": \"{{test-acquisition-id}}\"\n },\n \"tags\": [\n \"ad-hoc\"\n ]\n}\n"
"raw": "{\n \"gear\": \"test-case-gear\",\n \"inputs\": {\n \"dicom\": {\n \"type\": \"acquisition\",\n \"id\": \"{{test-acquisition-id}}\",\n \"name\" : \"1_1_dicom.zip\"\n }\n },\n \"config\": {\n\t\t\"two-digit multiple of ten\": 20\n\t},\n \"destination\": {\n \"type\": \"acquisition\",\n \"id\": \"{{test-acquisition-id}}\"\n },\n \"tags\": [\n \"ad-hoc\"\n ]\n}\n"
},
"description": ""
},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment