diff --git a/Dockerfile b/Dockerfile index 0e301a2ab..2a9fd085e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -36,9 +36,6 @@ CMD ["unitd", "--control", "*:8080", "--no-daemon", "--log", "/dev/stdout"] FROM dist as testing RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/community mongodb=3.4.4-r0 -RUN apk add --no-cache nodejs-npm=6.10.3-r1 \ - && npm install tests/integration_tests/abao -ENV PATH=/src/core/node_modules/.bin:$PATH RUN pip install -r tests/requirements.txt diff --git a/TESTING.md b/TESTING.md index a6c168171..277e7e752 100644 --- a/TESTING.md +++ b/TESTING.md @@ -13,7 +13,6 @@ All tests are executed by default. Subsets can be run using the filtering option * To run linting, use `--lint` (`-l`) * To run unit tests, use `--unit` (`-u`) * To run integration tests, use `--integ` (`-i`) -* To run abao tests, use `--abao` (`-a`) * To pass any arguments to `py.test`, use `-- PYTEST_ARGS` See [py.test usage](https://docs.pytest.org/en/latest/usage.html) for more. @@ -32,13 +31,3 @@ Without rebuilding the image, run only integration tests matching `foo`, use the ``` ./tests/bin/run-tests-docker.sh -B -- -i -- -k foo -vvv --pdb ``` - -**NOTE:** The mongodb version is pinned via the `MONGO_VERSION` variable in `tests/bin/run-tests-docker.sh`. - -### Tools -- [abao](https://github.com/cybertk/abao/) - -### Testing API against RAML with Abao -Abao is one of the testing tools run during our TravisCI build. It tests the API implementation against what’s defined in the RAML spec. Adding a new resource / url to the RAML spec will cause Abao to verify that resource during integration tests. Sometimes abao cannot properly test a resource (file field uploads) or a test may require chaining variable. Abao has before and after hooks for tests, written in javascript. These can be used to skip a test, inject variables into the request, or make extra assertions about the response. See tests/integration/abao in the repo for the hooks file. See [abao github readme](https://github.com/cybertk/abao/blob/master/README.md) for more information on how to use hooks. - -Abao tests can depend on specific resources (eg. group, project, session, etc.) pre-existing in the DB. That resource loading should be maintained within `tests/integration_tests/abao/load_fixture.py` and is executed automatically via the integration test scripts at `test/bin`. diff --git a/tests/bin/run-tests-docker.sh b/tests/bin/run-tests-docker.sh index 33aefe269..88f400ea4 100755 --- a/tests/bin/run-tests-docker.sh +++ b/tests/bin/run-tests-docker.sh @@ -9,7 +9,8 @@ USAGE=" Usage: $0 [OPTION...] [-- TEST_ARGS...] -Build scitran-core image and run tests in a Docker container. +Build scitran/core image and run tests in a Docker container. +Also displays coverage report and saves HTML in htmlcov dir. Options: -h, --help Print this help and exit @@ -20,10 +21,10 @@ Options: " + main() { local DOCKER_IMAGE= local TEST_ARGS= - local MONGO_VERSION=3.2 while [ $# -gt 0 ]; do case "$1" in @@ -83,10 +84,10 @@ main() { --network core-test \ --volume $(pwd)/api:/src/core/api \ --volume $(pwd)/tests:/src/core/tests \ + --env SCITRAN_SITE_API_URL=http://core-test-service/api \ --env SCITRAN_CORE_DRONE_SECRET=$SCITRAN_CORE_DRONE_SECRET \ --env SCITRAN_PERSISTENT_DB_URI=mongodb://core-test-service:27017/scitran \ --env SCITRAN_PERSISTENT_DB_LOG_URI=mongodb://core-test-service:27017/logs \ - --env SCITRAN_SITE_API_URL=http://core-test-service/api \ scitran/core:testing \ tests/bin/run-tests-ubuntu.sh $TEST_ARGS } @@ -98,6 +99,8 @@ clean_up() { log "INFO: Test return code = $TEST_RESULT_CODE" if [ "${TEST_RESULT_CODE}" = "0" ]; then + log "INFO: Collecting coverage..." + # Copy unit test coverage docker cp core-test-runner:/src/core/.coverage .coverage.unit-tests 2>/dev/null diff --git a/tests/bin/run-tests-ubuntu.sh b/tests/bin/run-tests-ubuntu.sh index 2a9b31959..55538d2cc 100755 --- a/tests/bin/run-tests-ubuntu.sh +++ b/tests/bin/run-tests-ubuntu.sh @@ -11,12 +11,9 @@ Usage: Runs linting and all tests if no options are provided. Runs subset of tests when using the filtering options. -Displays coverage report if all tests ran and passed. -Assumes running in scitran-core container or that core and all of its -dependencies are installed the same way as in the Dockerfile, and that - * TODO scitran-core instance is running at... - * TODO mongodb is runnin at... +Assumes running in a scitran/core:testing container or that core and all +of its dependencies are installed the same way as in the Dockerfile. Options: -h, --help Print this help and exit @@ -24,17 +21,22 @@ Options: -l, --lint Run linting -u, --unit Run unit tests -i, --integ Run integration tests - -a, --abao Run abao tests -- PYTEST_ARGS Arguments passed to py.test +Envvars (required for integration tests): + SCITRAN_SITE_API_URL URI to a running core instance (including /api) + SCITRAN_CORE_DRONE_SECRET API shared secret + SCITRAN_PERSISTENT_DB_URI Mongo URI to the scitran DB + SCITRAN_PERSISTENT_DB_LOG_URI Mongo URI to the scitran log DB + " + main() { export RUN_ALL=true local RUN_LINT=false local RUN_UNIT=false local RUN_INTEG=false - local RUN_ABAO=false local PYTEST_ARGS= while [ $# -gt 0 ]; do @@ -51,10 +53,6 @@ main() { RUN_ALL=false RUN_INTEG=true ;; - -a|--abao) - RUN_ALL=false - RUN_ABAO=true - ;; --) shift PYTEST_ARGS="$@" @@ -78,8 +76,7 @@ main() { RUN_LINT=true RUN_UNIT=true RUN_INTEG=true - RUN_ABAO=true - elif ${RUN_LINT} && ${RUN_UNIT} && ${RUN_INTEG} && ${RUN_ABAO}; then + elif ${RUN_LINT} && ${RUN_UNIT} && ${RUN_INTEG}; then # All filtering options were used, the same as none RUN_ALL=true fi @@ -104,17 +101,6 @@ main() { log "Running integration tests ..." PYTHONDONTWRITEBYTECODE=1 py.test tests/integration_tests/python $PYTEST_ARGS fi - - if ${RUN_ABAO}; then - log "Running abao tests ..." - # Create resources that Abao relies on - python tests/integration_tests/abao/load_fixture.py - - local BASEDIR=$(pwd) - cd raml/schemas/definitions - abao ../../api.raml "--server=$SCITRAN_SITE_API_URL" "--hookfiles=../../../tests/integration_tests/abao/abao_test_hooks.js" - cd $BASEDIR - fi } diff --git a/tests/integration_tests/abao/abao_test_hooks.js b/tests/integration_tests/abao/abao_test_hooks.js deleted file mode 100644 index 270c43aae..000000000 --- a/tests/integration_tests/abao/abao_test_hooks.js +++ /dev/null @@ -1,1463 +0,0 @@ -var hooks = require('hooks'); -var chai = require('chai'); -var assert = chai.assert; - -// Variables for passing results as input to subsequent tests -var gear_name = 'test-case-gear'; -var group_id = 'test-group'; -var delete_group_id = 'example_group'; -var test_group_tag = 'test-group-tag'; -var collection_id = 'test-collection-1'; -var delete_collection_id = ''; -var test_collection_1 = null; -var test_collection_tag = 'test-collection-tag'; -var test_session_1 = null; -var test_session_2_id = null; -var test_session_tag = 'test-session-tag'; -var test_session_1_analysis_2_id = null; -var test_acquisition_1 = null; -var test_acquisition_tag = 'test-acq-tag'; -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' - -// Tests we're skipping, fix these - -// Fails only in travis -hooks.skip("GET /version -> 200"); - -// Should 400 to say invalid json -hooks.skip("GET /download -> 400"); - -// Should 422 for missing metadata field -hooks.skip("POST /upload/label -> 402"); -hooks.skip("POST /upload/uid -> 402"); -hooks.skip("POST /upload/uid-match -> 402"); - -// Should 404 -hooks.skip("GET /jobs/{JobId} -> 404"); - -// Can only retry a failed job -hooks.skip("POST /jobs/{JobId}/retry -> 200"); - -// Cannot get JobId without GET /jobs endpoint -hooks.skip("GET /jobs/{JobId} -> 200"); -hooks.skip("GET /jobs/{JobId}/config.json -> 200"); -hooks.skip("POST /jobs/{JobId}/retry -> 200"); -hooks.skip("GET /jobs/{JobId} -> 404"); - -// https://github.com/cybertk/abao/issues/160 -hooks.skip("GET /users/self/avatar -> 307"); -hooks.skip("GET /users/{UserId}/avatar -> 307"); - -// drones currently use shared secret, allow when using API keys -hooks.skip("POST /devices -> 200") -hooks.skip("GET /devices/self -> 200") - -// Tests that are skipped because we do them in python - -// Skipping because abao doesn't support file fields -hooks.skip("POST /download -> 200"); -hooks.skip("GET /download -> 200"); -hooks.skip("POST /upload/label -> 200"); -hooks.skip("POST /upload/uid -> 200"); -hooks.skip("POST /upload/uid-match -> 200"); -hooks.skip("POST /upload/uid-match -> 404"); -hooks.skip("POST /engine -> 200"); -hooks.skip("POST /collections/{CollectionId}/packfile-start -> 200"); -hooks.skip("POST /collections/{CollectionId}/packfile -> 200"); -hooks.skip("GET /collections/{CollectionId}/packfile-end -> 200"); -hooks.skip("POST /sessions/{SessionId}/packfile-start -> 200"); -hooks.skip("POST /sessions/{SessionId}/packfile -> 200"); -hooks.skip("GET /sessions/{SessionId}/packfile-end -> 200"); -hooks.skip("POST /acquisitions/{AcquisitionId}/packfile-start -> 200"); -hooks.skip("POST /acquisitions/{AcquisitionId}/packfile -> 200"); -hooks.skip("GET /acquisitions/{AcquisitionId}/packfile-end -> 200"); -hooks.skip("POST /projects/{ProjectId}/packfile-start -> 200"); -hooks.skip("POST /projects/{ProjectId}/packfile -> 200"); -hooks.skip("GET /projects/{ProjectId}/packfile-end -> 200"); - - -// Skipping until merge with rest of project raml (So we have a ProjectId) -hooks.skip("POST /projects/{ProjectId}/template -> 200") -hooks.skip("DELETE /projects/{ProjectId}/template -> 200") -hooks.skip("POST /projects/{ProjectId}/recalc -> 200") -hooks.skip("GET /projects/{ProjectId}/rules -> 200") - -// Porting to python as per #600 -hooks.skip("POST /jobs/add -> 200") -hooks.skip("PUT /jobs/{JobId} -> 200") -hooks.skip("GET /gears/{GearId} -> 200") -hooks.skip("GET /sessions/{SessionId}/jobs -> 200") - -// Cannot be ran due to gear IDs being used as per # -hooks.skip("POST /sessions/{SessionId}/analyses -> 200") -hooks.skip("GET /sessions/{SessionId}/analyses/{AnalysisId} -> 200") -hooks.skip("DELETE /sessions/{SessionId}/analyses/{AnalysisId} -> 200") -// Related, ref #696 -hooks.skip("DELETE /gears/{GearId} -> 200") - - -hooks.before("POST /login -> 200", function(test, done) { - test.request.body = { - 'code': injected_api_key, - 'auth_type': 'api-key' - }; - done(); -}); - -hooks.beforeEach(function (test, done) { - test.request.query.root = "true" - test.request.headers.Authorization = "scitran-user XZpXI40Uk85eozjQkU1zHJ6yZHpix+j0mo1TMeGZ4dPzIqVPVGPmyfeK"; - done(); -}); - -hooks.before("GET /download -> 404", function(test, done) { - test.request.query = { - ticket: '1234' - }; - done(); -}); - -hooks.before("POST /users -> 400", function(test, done) { - test.request.body = {api_key:{key:"test"}}; - done(); -}); - -hooks.before("GET /users/{UserId} -> 200", function(test, done) { - test.request.params = { - UserId: "jane.doe@gmail.com" - }; - done(); -}); - -hooks.before("PUT /users/{UserId} -> 200", function(test, done) { - test.request.params = { - UserId: "jane.doe@gmail.com" - }; - done(); -}); - -hooks.before("PUT /users/{UserId} -> 400", function(test, done) { - test.request.params = { - UserId: "jane.doe@gmail.com" - }; - test.request.body = {"not_a_valid_property":"foo"}; - done(); -}); - -hooks.before("DELETE /users/{UserId} -> 200", function(test, done) { - test.request.params = { - UserId: "jane.doe@gmail.com" - }; - done(); -}); - -hooks.before("GET /users/{UserId}/acquisitions -> 200", function(test, done) { - test.request.params = { - UserId: "admin@user.com" - }; - done(); -}); - -hooks.before("GET /users/{UserId}/collections -> 200", function(test, done) { - test.request.params = { - UserId: "admin@user.com" - }; - done(); -}); - -hooks.before("GET /users/{UserId}/projects -> 200", function(test, done) { - test.request.params = { - UserId: "admin@user.com" - }; - done(); -}); - -hooks.before("GET /users/{UserId}/sessions -> 200", function(test, done) { - test.request.params = { - UserId: "admin@user.com" - }; - done(); -}); - -hooks.before("PUT /groups/{GroupId} -> 400", function(test, done) { - test.request.params = { - GroupId: group_id - }; - test.request.body = {"not_a_real_property":"foo"}; - done(); -}); - -hooks.before("POST /groups -> 400", function(test, done) { - test.request.body = {"not_a_real_property":"foo"}; - done(); -}); - - -hooks.before("GET /groups/{GroupId} -> 200", function(test, done) { - test.request.params = { - GroupId: group_id - }; - done(); -}); - -hooks.before("DELETE /groups/{GroupId} -> 200", function(test, done) { - test.request.params = { - GroupId: delete_group_id - }; - done(); -}); - -hooks.before("POST /groups/{GroupId}/permissions -> 200", function(test, done) { - test.request.params = { - GroupId: group_id - }; - test.request.body = { - _id: "test@user.com", - access: "ro" - } - done(); -}); - -hooks.before("POST /groups/{GroupId}/permissions -> 400", function(test, done) { - test.request.params = { - GroupId: group_id - }; - test.request.body.foo = "bar"; - done(); -}); - -hooks.before("GET /groups/{GroupId}/permissions/{UserId} -> 200", function(test, done) { - test.request.params = { - GroupId: group_id, - UserId: "test@user.com" - }; - done(); -}); - -hooks.before("PUT /groups/{GroupId}/permissions/{UserId} -> 200", function(test, done) { - test.request.params = { - GroupId: group_id, - UserId: "test@user.com" - }; - test.request.body = { - _id: "test@user.com", - access: "admin" - }; - done(); -}); - -hooks.before("PUT /groups/{GroupId}/permissions/{UserId} -> 400", function(test, done) { - test.request.params = { - GroupId: group_id, - UserId:"test@user.com" - }; - test.request.body = { - _id: "test@user.com", - access: "rw", - not_a_real_property: "foo" - }; - done(); -}); - -hooks.before("DELETE /groups/{GroupId}/permissions/{UserId} -> 200", function(test, done) { - test.request.params = { - GroupId: group_id, - UserId: "test@user.com" - }; - done(); -}); - -hooks.before("POST /groups/{GroupId}/tags -> 200", function(test, done) { - test.request.params = { - GroupId: group_id - }; - test.request.body = { - "value":test_group_tag - }; - done(); -}); - -hooks.before("POST /groups/{GroupId}/tags -> 400", function(test, done) { - test.request.params = { - GroupId: group_id - }; - test.request.body = { - "value":test_group_tag, - "bad property": "foo" - }; - done(); -}); - -hooks.before("GET /groups/{GroupId}/tags/{TagValue} -> 200", function(test, done) { - test.request.params = { - GroupId: group_id, - TagValue: test_group_tag - }; - done(); -}); - -hooks.before("PUT /groups/{GroupId}/tags/{TagValue} -> 200", function(test, done) { - test.request.params = { - GroupId: group_id, - TagValue: test_group_tag - }; - test_group_tag = "a-new-tag"; - test.request.body = { - "value":test_group_tag - }; - done(); -}); - -hooks.before("PUT /groups/{GroupId}/tags/{TagValue} -> 400", function(test, done) { - test.request.params = { - GroupId: group_id, - TagValue: test_group_tag - }; - test.request.body = { - "value":test_group_tag, - "bad proeprty":"blah" - }; - done(); -}); - -hooks.before("DELETE /groups/{GroupId}/tags/{TagValue} -> 200", function(test, done) { - test.request.params = { - GroupId: group_id, - TagValue: test_group_tag - }; - done(); -}); - -hooks.before("GET /groups/{GroupId}/projects -> 200", function(test, done) { - test.request.params = { - GroupId: group_id - }; - done(); -}); - - -// set initial test_collection_1 -hooks.after("GET /collections -> 200", function(test, done) { - test_collection_1 = test.response.body[0]; - collection_id = test.response.body[0]._id; - delete_collection_id = test.response.body[1]._id; - done(); -}); - -hooks.before("GET /collections/{CollectionId} -> 200", function(test, done) { - test.request.params.CollectionId = collection_id; - done(); -}); - -// set detailed test_collection_1 (including analyses, that are omitted during listing) -hooks.after("GET /collections/{CollectionId} -> 200", function(test, done) { - test_collection_1 = test.response.body; - done(); -}); - -hooks.before("GET /collections/{CollectionId}/sessions -> 200", function(test, done) { - test.request.params.CollectionId = collection_id; - done(); -}); - -hooks.before("GET /collections/{CollectionId}/acquisitions -> 200", function(test, done) { - test.request.params.CollectionId = collection_id; - done(); -}); - -hooks.before("POST /collections -> 400", function(test, done) { - test.request.params.CollectionId = collection_id; - test.request.body.foo = "not an allowed property"; - done(); -}); - -hooks.before("PUT /collections/{CollectionId} -> 400", function(test, done) { - test.request.params.CollectionId = collection_id; - test.request.body.foo = "not an allowed property"; - done(); -}); - -hooks.before("DELETE /collections/{CollectionId} -> 200", function(test, done) { - test.request.params.CollectionId = delete_collection_id; - done(); -}); - -hooks.before("POST /collections/{CollectionId}/tags -> 200", function(test, done) { - test.request.params.CollectionId = collection_id; - test.request.body = { - "value":test_collection_tag - }; - done(); -}); - -hooks.before("POST /collections/{CollectionId}/tags -> 400", function(test, done) { - test.request.params.CollectionId = collection_id; - test.request.body = { - "value":"" - }; - done(); -}); - -hooks.before("GET /collections/{CollectionId}/tags/{TagValue} -> 200", function(test, done) { - test.request.params = { - CollectionId : collection_id, - TagValue : test_collection_tag - }; - done(); -}); - -hooks.before("PUT /collections/{CollectionId}/tags/{TagValue} -> 200", function(test, done) { - test.request.params = { - CollectionId : collection_id, - TagValue : test_collection_tag - }; - test_collection_tag = "new-tag-value"; - test.request.body = { - "value":test_collection_tag - }; - done(); -}); - -hooks.before("PUT /collections/{CollectionId}/tags/{TagValue} -> 400", function(test, done) { - test.request.params = { - CollectionId : collection_id, - TagValue : test_collection_tag - }; - test.request.body = { - "value":"" - }; - done(); -}); - -hooks.before("DELETE /collections/{CollectionId}/tags/{TagValue} -> 200", function(test, done) { - test.request.params = { - CollectionId : collection_id, - TagValue : test_collection_tag - }; - done(); -}); - -hooks.before("GET /collections/{CollectionId}/files/{FileName} -> 200", function(test, done) { - test.request.params = { - CollectionId : collection_id, - FileName : "notes.txt" - }; - test.request.query = { - "ticket":"" - }; - done(); -}); - -hooks.before("POST /collections/{CollectionId}/permissions -> 200", function(test, done) { - test.request.params = { - CollectionId : collection_id - }; - test.request.body = { - "_id":"test@user.com", - "access":"ro" - }; - done(); -}); - -hooks.before("POST /collections/{CollectionId}/permissions -> 400", function(test, done) { - test.request.params = { - CollectionId : collection_id - }; - test.request.body = { - "not a valid":"permissions entry" - }; - done(); -}); - -hooks.before("GET /collections/{CollectionId}/permissions/{UserId} -> 200", function(test, done) { - test.request.params = { - CollectionId : collection_id, - UserId: "test@user.com" - }; - done(); -}); - -hooks.before("PUT /collections/{CollectionId}/permissions/{UserId} -> 200", function(test, done) { - test.request.params = { - CollectionId : collection_id, - UserId: "test@user.com" - }; - test.request.body = { - "access":"rw", - "_id":"test@user.com" - }; - done(); -}); - -hooks.before("PUT /collections/{CollectionId}/permissions/{UserId} -> 400", function(test, done) { - test.request.params = { - CollectionId : collection_id, - UserId: "test@user.com" - }; - test.request.body = { - "not a valid":"permissions entry" - }; - done(); -}); - -hooks.before("DELETE /collections/{CollectionId}/permissions/{UserId} -> 200", function(test, done) { - test.request.params = { - CollectionId : collection_id, - UserId: "test@user.com" - }; - done(); -}); - -hooks.before("POST /collections/{CollectionId}/notes -> 200", function(test, done) { - test.request.params = { - CollectionId : collection_id - }; - done(); -}); - -hooks.before("POST /collections/{CollectionId}/notes -> 400", function(test, done) { - test.request.params = { - CollectionId : collection_id - }; - test.request.body = { - "not real":"property" - }; - done(); -}); - -hooks.before("GET /collections/{CollectionId}/notes/{NoteId} -> 200", function(test, done) { - test.request.params = { - CollectionId : collection_id, - NoteId: test_collection_1.notes[0]._id - }; - done(); -}); - -hooks.before("PUT /collections/{CollectionId}/notes/{NoteId} -> 200", function(test, done) { - test.request.params = { - CollectionId : collection_id, - NoteId: test_collection_1.notes[0]._id - }; - test.request.body = { - "text":"new note" - }; - done(); -}); - -hooks.before("PUT /collections/{CollectionId}/notes/{NoteId} -> 400", function(test, done) { - test.request.params = { - CollectionId : collection_id, - NoteId: test_collection_1.notes[0]._id - }; - test.request.body = { - "note a":"real property" - }; - done(); -}); - -hooks.before("DELETE /collections/{CollectionId}/notes/{NoteId} -> 200", function(test, done) { - test.request.params = { - CollectionId : collection_id, - NoteId: test_collection_1.notes[0]._id - }; - done(); -}); - -hooks.before("GET /collections/{CollectionId}/analyses/{AnalysisId} -> 200", function(test, done) { - test.request.params = { - CollectionId : collection_id, - AnalysisId: test_collection_1.analyses[0]._id - }; - done(); -}); - -hooks.before("DELETE /collections/{CollectionId}/analyses/{AnalysisId} -> 200", function(test, done) { - test.request.params = { - CollectionId : collection_id, - AnalysisId: test_collection_1.analyses[1]._id - }; - done(); -}); - -hooks.before("GET /collections/{CollectionId}/analyses/{AnalysisId}/files -> 200", function(test, done) { - test.request.params = { - CollectionId : collection_id, - AnalysisId: test_collection_1.analyses[0]._id - }; - test.request.query.ticket = ""; - done(); -}); - -hooks.before("GET /collections/{CollectionId}/analyses/{AnalysisId}/files/{Filename} -> 200", function(test, done) { - test.request.params = { - CollectionId : collection_id, - AnalysisId: test_collection_1.analyses[0]._id, - Filename: "test-1.dcm" - }; - test.request.query.ticket = ""; - done(); -}); - -hooks.before("POST /collections/{CollectionId}/analyses/{AnalysisId}/notes -> 200", function(test, done) { - test.request.params = { - CollectionId : collection_id, - AnalysisId: test_collection_1.analyses[0]._id - }; - done(); -}); - -hooks.before("POST /collections/{CollectionId}/analyses/{AnalysisId}/notes -> 400", function(test, done) { - test.request.params = { - CollectionId : collection_id, - AnalysisId: test_collection_1.analyses[0]._id - }; - test.request.body = { - "not a":"real property" - }; - done(); -}); - -hooks.before("DELETE /collections/{CollectionId}/analyses/{AnalysisId}/notes/{NoteId} -> 200", function(test, done) { - test.request.params = { - CollectionId : collection_id, - AnalysisId: test_collection_1.analyses[0]._id, - NoteId: test_collection_1.analyses[0].notes[0]._id - }; - done(); -}); - - -// set initial test_session_1 -hooks.after("GET /sessions -> 200", function(test, done) { - test_session_1 = test.response.body[0]; - assert.equal(test_session_1.label, "test-session-1"); - done(); -}); - -hooks.before("GET /sessions/{SessionId} -> 200", function(test, done) { - test.request.params.SessionId = test_session_1._id; - done(); -}); - -// set detailed test_session_1 (including analyses, that are omitted during listing) -hooks.after("GET /sessions/{SessionId} -> 200", function(test, done) { - test_session_1 = test.response.body; - done(); -}); - -hooks.after("GET /sessions/{SessionId} -> 200", function(test, done) { - test_session_1 = test.response.body; - assert.equal(test_session_1.label, "test-session-1"); - done(); -}); - -hooks.before("POST /sessions -> 200", function(test, done) { - test.request.body.project = test_session_1.project; - done(); -}); - -hooks.after("POST /sessions -> 200", function(test, done) { - test_session_2_id = test.response.body._id - done(); -}); - -hooks.before("POST /sessions -> 400", function(test, done) { - test.request.body.foo = "not an allowed property"; - test.request.body.project = test_session_1.project; - done(); -}); - -hooks.before("PUT /sessions/{SessionId} -> 200", function(test, done) { - test.request.params.SessionId = test_session_1._id; - test.request.body = { - project: test_session_1.project, - label: "new-label-test-session-1" - }; - done(); -}); - -hooks.before("PUT /sessions/{SessionId} -> 400", function(test, done) { - test.request.params.SessionId = test_session_1._id; - test.request.body = { - project: test_session_1.project, - "not_a_real_property": "new-label-test-session-1" - }; - done(); -}); - -hooks.before("DELETE /sessions/{SessionId} -> 200", function(test, done) { - test.request.params.SessionId = test_session_2_id; - done(); -}); - - -hooks.before("GET /sessions/{SessionId}/jobs -> 200", function(test, done) { - test.request.params.SessionId = test_session_1._id; - done(); -}); - -hooks.before("POST /sessions/{SessionId}/tags -> 200", function(test, done) { - test.request.params.SessionId = test_session_1._id; - test.request.body = { - value: test_session_tag - }; - done(); -}); - -hooks.before("POST /sessions/{SessionId}/tags -> 400", function(test, done) { - test.request.params.SessionId = test_session_1._id; - test.request.body = { - value: "" - }; - done(); -}); - -hooks.before("GET /sessions/{SessionId}/tags/{TagValue} -> 200", function(test, done) { - test.request.params = { - SessionId : test_session_1._id, - TagValue: test_session_tag - }; - done(); -}); - -hooks.before("PUT /sessions/{SessionId}/tags/{TagValue} -> 200", function(test, done) { - test.request.params = { - SessionId : test_session_1._id, - TagValue: test_session_tag - }; - test_session_tag = 'new-tag-value'; - test.request.body = { - value: test_session_tag - }; - done(); -}); - -hooks.before("PUT /sessions/{SessionId}/tags/{TagValue} -> 400", function(test, done) { - test.request.params = { - SessionId : test_session_1._id, - TagValue: test_session_tag - }; - test.request.body = { - value: "" - }; - done(); -}); - -hooks.before("DELETE /sessions/{SessionId}/tags/{TagValue} -> 200", function(test, done) { - test.request.params = { - SessionId : test_session_1._id, - TagValue: test_session_tag - }; - done(); -}); - -hooks.before("GET /sessions/{SessionId}/files/{FileName} -> 200", function(test, done) { - test.request.params = { - SessionId : test_session_1._id, - FileName : "notes.txt" - }; - test.request.query = { - "ticket":"" - }; - done(); -}); - -hooks.before("POST /sessions/{SessionId}/notes -> 200", function(test, done) { - test.request.params = { - SessionId : test_session_1._id - }; - test.request.body = { - "text":"test note" - }; - done(); -}); - -hooks.before("POST /sessions/{SessionId}/notes -> 400", function(test, done) { - test.request.params = { - SessionId : test_session_1._id - }; - test.request.body = { - "note a real":"property" - }; - done(); -}); - -hooks.before("GET /sessions/{SessionId}/notes/{NoteId} -> 200", function(test, done) { - test.request.params = { - SessionId : test_session_1._id, - NoteId: test_session_1.notes[0]._id - }; - done(); -}); - -hooks.before("PUT /sessions/{SessionId}/notes/{NoteId} -> 200", function(test, done) { - test.request.params = { - SessionId : test_session_1._id, - NoteId: test_session_1.notes[0]._id - }; - test.request.body = { - "text":"new note" - }; - done(); -}); - -hooks.before("PUT /sessions/{SessionId}/notes/{NoteId} -> 400", function(test, done) { - test.request.params = { - SessionId : test_session_1._id, - NoteId: test_session_1.notes[0]._id - }; - test.request.body = { - "not a real":"property" - }; - done(); -}); - -hooks.before("DELETE /sessions/{SessionId}/notes/{NoteId} -> 200", function(test, done) { - test.request.params = { - SessionId : test_session_1._id, - NoteId: test_session_1.notes[0]._id - }; - done(); -}); - -hooks.before("GET /sessions/{SessionId}/acquisitions -> 200", function(test, done) { - test.request.params.SessionId = test_session_1._id; - done(); -}); - -hooks.before("POST /sessions/{SessionId}/analyses -> 200", function(test, done) { - test.request.params.SessionId = test_session_1._id; - test.request.query = {"job":"true"}; - test.request.body = { - "analysis": { - "label": "Test Analysis 1" - }, - "job" : { - "gear": "test-case-gear", - "inputs": {}, - "tags": ["example"] - } - } - done(); -}); - -hooks.after("POST /sessions/{SessionId}/analyses -> 200", function(test, done) { - test_session_1_analysis_2_id = test.response.body._id; - done(); -}); - -hooks.before("GET /sessions/{SessionId}/analyses/{AnalysisId} -> 200", function(test, done) { - test.request.params.SessionId = test_session_1._id; - test.request.params.AnalysisId = test_session_1_analysis_2_id; - done(); -}); - -hooks.before("DELETE /sessions/{SessionId}/analyses/{AnalysisId} -> 200", function(test, done) { - test.request.params.SessionId = test_session_1._id; - test.request.params.AnalysisId = test_session_1_analysis_2_id; - done(); -}); - -hooks.before("GET /sessions/{SessionId}/analyses/{AnalysisId}/files -> 200", function(test, done) { - test.request.params.SessionId = test_session_1._id; - test.request.params.AnalysisId = test_session_1.analyses[0]._id; - test.request.query.ticket = ""; - done(); -}); - -hooks.before("GET /sessions/{SessionId}/analyses/{AnalysisId}/files/{Filename} -> 200", function(test, done) { - test.request.params.SessionId = test_session_1._id; - test.request.params.AnalysisId = test_session_1.analyses[0]._id; - test.request.params.Filename = "test-1.dcm"; - test.request.query.ticket = ""; - done(); -}); - -hooks.before("POST /sessions/{SessionId}/analyses/{AnalysisId}/notes -> 200", function(test, done) { - test.request.params.SessionId = test_session_1._id; - test.request.params.AnalysisId = test_session_1.analyses[0]._id; - done(); -}); - -hooks.before("POST /sessions/{SessionId}/analyses/{AnalysisId}/notes -> 400", function(test, done) { - test.request.params.SessionId = test_session_1._id; - test.request.params.AnalysisId = test_session_1.analyses[0]._id; - test.request.body = { - "not a":"real property" - }; - done(); -}); - -hooks.before("DELETE /sessions/{SessionId}/analyses/{AnalysisId}/notes/{NoteId} -> 200", function(test, done) { - test.request.params.SessionId = test_session_1._id; - test.request.params.AnalysisId = test_session_1.analyses[0]._id; - test.request.params.NoteId = test_session_1.analyses[0].notes[0]._id; - done(); -}); - - - -// set initial test_acquisition_1 -hooks.after("GET /acquisitions -> 200", function(test, done) { - test_acquisition_1 = test.response.body[0]; - assert.equal(test_acquisition_1.label, "test-acquisition-1"); - done(); -}); - -hooks.before("GET /acquisitions/{AcquisitionId} -> 200", function(test, done) { - test.request.params.AcquisitionId = test_acquisition_1._id; - done(); -}); - -// set detailed test_acquisition_1 (including analyses, that are omitted during listing) -hooks.after("GET /acquisitions/{AcquisitionId} -> 200", function(test, done) { - test_acquisition_1 = test.response.body; - done(); -}); - -hooks.before("POST /acquisitions -> 200", function(test, done) { - test.request.body.session = test_session_1._id; - done(); -}); - -hooks.after("POST /acquisitions -> 200", function(test, done) { - example_acquisition_id = test.response.body._id; - done(); -}); - -hooks.before("POST /acquisitions -> 400", function(test, done) { - test.request.body.session = test_session_1._id; - test.request.body.foo = "bar"; - done(); -}); - -hooks.before("PUT /acquisitions/{AcquisitionId} -> 200", function(test, done) { - test.request.params.AcquisitionId = test_acquisition_1._id; - test.request.body = {"label":"test-acquisition-1-new-label"}; - done(); -}); - - -hooks.before("PUT /acquisitions/{AcquisitionId} -> 400", function(test, done) { - test.request.params.AcquisitionId = test_acquisition_1._id; - test.request.body = {"not-real":"an invalid property"}; - done(); -}); - -hooks.before("DELETE /acquisitions/{AcquisitionId} -> 200", function(test, done) { - test.request.params.AcquisitionId = example_acquisition_id; - done(); -}); - -hooks.before("POST /acquisitions/{AcquisitionId}/tags -> 200", function(test, done) { - test.request.params.AcquisitionId = test_acquisition_1._id; - test.request.body = { - "value": test_acquisition_tag - }; - done(); -}); - -hooks.before("POST /acquisitions/{AcquisitionId}/tags -> 400", function(test, done) { - test.request.params.AcquisitionId = test_acquisition_1._id; - test.request.body = { - "value": test_acquisition_tag, - "bad property": "not a real property" - }; - done(); -}); - -hooks.before("GET /acquisitions/{AcquisitionId}/tags/{TagValue} -> 200", function(test, done) { - test.request.params = { - AcquisitionId : test_acquisition_1._id, - TagValue : test_acquisition_tag - }; - done(); -}); - -hooks.before("PUT /acquisitions/{AcquisitionId}/tags/{TagValue} -> 200", function(test, done) { - test.request.params = { - AcquisitionId : test_acquisition_1._id, - TagValue : test_acquisition_tag - }; - test_acquisition_tag = "new-tag-value"; - test.request.body = { - "value": test_acquisition_tag - }; - done(); -}); - -hooks.before("PUT /acquisitions/{AcquisitionId}/tags/{TagValue} -> 400", function(test, done) { - test.request.params = { - AcquisitionId : test_acquisition_1._id, - TagValue : test_acquisition_tag - }; - test.request.body = { - "value": test_acquisition_tag, - "bad property": "not a real property" - }; - done(); -}); - -hooks.before("DELETE /acquisitions/{AcquisitionId}/tags/{TagValue} -> 200", function(test, done) { - test.request.params = { - AcquisitionId : test_acquisition_1._id, - TagValue : test_acquisition_tag - }; - done(); -}); - -hooks.before("GET /acquisitions/{AcquisitionId}/files/{FileName} -> 200", function(test, done) { - test.request.params = { - AcquisitionId : test_acquisition_1._id, - FileName : "test-1.dcm" - }; - test.request.query = { - "ticket":"" - }; - done(); -}); - -hooks.before("POST /acquisitions/{AcquisitionId}/notes -> 200", function(test, done) { - test.request.params = { - AcquisitionId : test_acquisition_1._id - }; - done(); -}); - -hooks.before("POST /acquisitions/{AcquisitionId}/notes -> 400", function(test, done) { - test.request.params = { - AcquisitionId : test_acquisition_1._id - }; - test.request.body.not_real = "invalid property"; - done(); -}); - -hooks.before("GET /acquisitions/{AcquisitionId}/notes/{NoteId} -> 200", function(test, done) { - test.request.params = { - AcquisitionId : test_acquisition_1._id, - NoteId: test_acquisition_1.notes[0]._id - }; - done(); -}); - -hooks.before("PUT /acquisitions/{AcquisitionId}/notes/{NoteId} -> 200", function(test, done) { - test.request.params = { - AcquisitionId : test_acquisition_1._id, - NoteId: test_acquisition_1.notes[0]._id - }; - test.request.body = { - "text":"updated note text" - }; - done(); -}); - -hooks.before("PUT /acquisitions/{AcquisitionId}/notes/{NoteId} -> 400", function(test, done) { - test.request.params = { - AcquisitionId : test_acquisition_1._id, - NoteId: test_acquisition_1.notes[0]._id - }; - test.request.body = { - "invalid property":"specified" - }; - done(); -}); - -hooks.before("DELETE /acquisitions/{AcquisitionId}/notes/{NoteId} -> 200", function(test, done) { - test.request.params = { - AcquisitionId : test_acquisition_1._id, - NoteId: test_acquisition_1.notes[0]._id - }; - done(); -}); - -hooks.before("GET /acquisitions/{AcquisitionId}/analyses/{AnalysisId} -> 200", function(test, done) { - test.request.params = { - AcquisitionId : test_acquisition_1._id, - AnalysisId: test_acquisition_1.analyses[0]._id - }; - done(); -}); - -hooks.before("DELETE /acquisitions/{AcquisitionId}/analyses/{AnalysisId} -> 200", function(test, done) { - test.request.params = { - AcquisitionId : test_acquisition_1._id, - AnalysisId: test_acquisition_1.analyses[1]._id - }; - done(); -}); - -hooks.before("GET /acquisitions/{AcquisitionId}/analyses/{AnalysisId}/files -> 200", function(test, done) { - test.request.params = { - AcquisitionId : test_acquisition_1._id, - AnalysisId: test_acquisition_1.analyses[0]._id - }; - test.request.query.ticket = ""; - done(); -}); - -hooks.before("GET /acquisitions/{AcquisitionId}/analyses/{AnalysisId}/files/{Filename} -> 200", function(test, done) { - test.request.params = { - AcquisitionId : test_acquisition_1._id, - AnalysisId: test_acquisition_1.analyses[0]._id, - Filename: "test-1.dcm" - }; - test.request.query.ticket = ""; - done(); -}); - -hooks.before("POST /acquisitions/{AcquisitionId}/analyses/{AnalysisId}/notes -> 200", function(test, done) { - test.request.params = { - AcquisitionId : test_acquisition_1._id, - AnalysisId: test_acquisition_1.analyses[0]._id - }; - done(); -}); - -hooks.before("POST /acquisitions/{AcquisitionId}/analyses/{AnalysisId}/notes -> 400", function(test, done) { - test.request.params = { - AcquisitionId : test_acquisition_1._id, - AnalysisId: test_acquisition_1.analyses[0]._id - }; - test.request.body = { - "not a":"real property" - }; - done(); -}); - -hooks.before("GET /acquisitions/{AcquisitionId}/analyses/{AnalysisId}/notes/{NoteId} -> 200", function(test, done) { - test.request.params = { - AcquisitionId : test_acquisition_1._id, - AnalysisId: test_acquisition_1.analyses[0]._id, - NoteId: test_acquisition_1.analyses[0].notes[0]._id - }; - done(); -}); - -hooks.before("DELETE /acquisitions/{AcquisitionId}/analyses/{AnalysisId}/notes/{NoteId} -> 200", function(test, done) { - test.request.params = { - AcquisitionId : test_acquisition_1._id, - AnalysisId: test_acquisition_1.analyses[0]._id, - NoteId: test_acquisition_1.analyses[0].notes[0]._id - }; - done(); -}); - - -// set initial test_project_1 -hooks.after("GET /projects -> 200", function(test, done) { - test_project_1 = test.response.body[0]; - assert.equal(test_project_1.label, "test-project-1"); - done(); -}); - -hooks.after("POST /projects -> 200", function(test, done) { - delete_project_id = test.response.body._id; - done(); -}); - -hooks.before("POST /projects -> 400", function(test, done) { - test.request.body.not_real = "an invalid property"; - done(); -}); - -hooks.before("GET /projects/{ProjectId} -> 200", function(test, done) { - test.request.params.ProjectId = test_project_1._id; - done(); -}); - -// set detailed test_project_1 (including analyses, that are omitted during listing) -hooks.after("GET /projects/{ProjectId} -> 200", function(test, done) { - test_project_1 = test.response.body; - done(); -}); - -hooks.before("PUT /projects/{ProjectId} -> 400", function(test, done) { - test.request.params.ProjectId = test_project_1._id; - test.request.body = {"not_real":"fake property"}; - done(); -}); - -hooks.before("DELETE /projects/{ProjectId} -> 200", function(test, done) { - test.request.params.ProjectId = delete_project_id; - done(); -}); - -hooks.before("POST /projects/{ProjectId}/tags -> 200", function(test, done) { - test.request.params.ProjectId = test_project_1._id; - test.request.body = { - "value":test_project_tag - }; - done(); -}); - -hooks.before("POST /projects/{ProjectId}/tags -> 400", function(test, done) { - test.request.params.ProjectId = test_project_1._id; - test.request.body = { - "value":"" - }; - done(); -}); - -hooks.before("GET /projects/{ProjectId}/tags/{TagValue} -> 200", function(test, done) { - test.request.params = { - ProjectId : test_project_1._id, - TagValue : test_project_tag - }; - done(); -}); - -hooks.before("PUT /projects/{ProjectId}/tags/{TagValue} -> 200", function(test, done) { - test.request.params = { - ProjectId : test_project_1._id, - TagValue : test_project_tag - }; - test_project_tag = "new-tag-value"; - test.request.body = { - "value":test_project_tag - }; - done(); -}); - -hooks.before("PUT /projects/{ProjectId}/tags/{TagValue} -> 400", function(test, done) { - test.request.params = { - ProjectId : test_project_1._id, - TagValue : test_project_tag - }; - test.request.body = { - "value":"" - }; - done(); -}); - -hooks.before("DELETE /projects/{ProjectId}/tags/{TagValue} -> 200", function(test, done) { - test.request.params = { - ProjectId : test_project_1._id, - TagValue : test_project_tag - }; - done(); -}); - -hooks.before("GET /projects/{ProjectId}/files/{FileName} -> 200", function(test, done) { - test.request.params = { - ProjectId : test_project_1._id, - FileName : "notes.txt" - }; - test.request.query = { - "ticket":"" - }; - done(); -}); - -hooks.before("POST /projects/{ProjectId}/permissions -> 200", function(test, done) { - test.request.params = { - ProjectId : test_project_1._id - }; - test.request.body = { - "_id":"test@user.com", - "access":"ro" - }; - done(); -}); - -hooks.before("POST /projects/{ProjectId}/permissions -> 400", function(test, done) { - test.request.params = { - ProjectId : test_project_1._id - }; - test.request.body = { - "not a valid":"permissions entry" - }; - done(); -}); - -hooks.before("GET /projects/{ProjectId}/permissions/{UserId} -> 200", function(test, done) { - test.request.params = { - ProjectId : test_project_1._id, - UserId: "test@user.com" - }; - done(); -}); - -hooks.before("PUT /projects/{ProjectId}/permissions/{UserId} -> 200", function(test, done) { - test.request.params = { - ProjectId : test_project_1._id, - UserId: "test@user.com" - }; - test.request.body = { - "access":"rw", - "_id":"test@user.com" - }; - done(); -}); - -hooks.before("PUT /projects/{ProjectId}/permissions/{UserId} -> 400", function(test, done) { - test.request.params = { - ProjectId : test_project_1._id, - UserId: "test@user.com" - }; - test.request.body = { - "not a valid":"permissions entry" - }; - done(); -}); - -hooks.before("DELETE /projects/{ProjectId}/permissions/{UserId} -> 200", function(test, done) { - test.request.params = { - ProjectId : test_project_1._id, - UserId: "test@user.com" - }; - done(); -}); - -hooks.before("POST /projects/{ProjectId}/notes -> 200", function(test, done) { - test.request.params = { - ProjectId : test_project_1._id - }; - test.request.body = { - "text":"test note" - }; - done(); -}); - -hooks.before("POST /projects/{ProjectId}/notes -> 400", function(test, done) { - test.request.params = { - ProjectId : test_project_1._id - }; - test.request.body = { - "not a real":"property" - }; - done(); -}); - -hooks.before("GET /projects/{ProjectId}/notes/{NoteId} -> 200", function(test, done) { - test.request.params = { - ProjectId : test_project_1._id, - NoteId: test_project_1.notes[0]._id - }; - done(); -}); - -hooks.before("PUT /projects/{ProjectId}/notes/{NoteId} -> 200", function(test, done) { - test.request.params = { - ProjectId : test_project_1._id, - NoteId: test_project_1.notes[0]._id - }; - test.request.body = { - "text":"updated note" - }; - done(); -}); - -hooks.before("PUT /projects/{ProjectId}/notes/{NoteId} -> 400", function(test, done) { - test.request.params = { - ProjectId : test_project_1._id, - NoteId: test_project_1.notes[0]._id - }; - test.request.body = { - "not a real":"property" - }; - done(); -}); - -hooks.before("DELETE /projects/{ProjectId}/notes/{NoteId} -> 200", function(test, done) { - test.request.params = { - ProjectId : test_project_1._id, - NoteId: test_project_1.notes[0]._id - }; - done(); -}); - -hooks.before("GET /projects/{ProjectId}/sessions -> 200", function(test, done) { - test.request.params.ProjectId = test_project_1._id; - done(); -}); - -hooks.before("GET /projects/{ProjectId}/acquisitions -> 200", function(test, done) { - test.request.params.ProjectId = test_project_1._id; - done(); -}); - -hooks.before("GET /report/project -> 200", function(test, done) { - test.request.query = { - "projects":test_project_1._id - }; - done(); -}); - -hooks.before("GET /projects/{ProjectId}/analyses/{AnalysisId} -> 200", function(test, done) { - test.request.params = { - ProjectId: test_project_1._id, - AnalysisId: test_project_1.analyses[0]._id - }; - done(); -}); - -hooks.before("DELETE /projects/{ProjectId}/analyses/{AnalysisId} -> 200", function(test, done) { - test.request.params = { - ProjectId: test_project_1._id, - AnalysisId: test_project_1.analyses[1]._id - }; - done(); -}); - -hooks.before("GET /projects/{ProjectId}/analyses/{AnalysisId}/files -> 200", function(test, done) { - test.request.params = { - ProjectId: test_project_1._id, - AnalysisId: test_project_1.analyses[0]._id - }; - test.request.query.ticket = ""; - done(); -}); - -hooks.before("GET /projects/{ProjectId}/analyses/{AnalysisId}/files/{Filename} -> 200", function(test, done) { - test.request.params = { - ProjectId: test_project_1._id, - AnalysisId: test_project_1.analyses[0]._id, - Filename: "test-1.dcm" - }; - test.request.query.ticket = ""; - done(); -}); - -hooks.before("POST /projects/{ProjectId}/analyses/{AnalysisId}/notes -> 200", function(test, done) { - test.request.params = { - ProjectId: test_project_1._id, - AnalysisId: test_project_1.analyses[0]._id - }; - done(); -}); - - -hooks.before("POST /projects/{ProjectId}/analyses/{AnalysisId}/notes -> 400", function(test, done) { - test.request.params = { - ProjectId: test_project_1._id, - AnalysisId: test_project_1.analyses[0]._id - }; - test.request.body = { - "not a":"real property" - } - done(); -}); - -hooks.before("DELETE /projects/{ProjectId}/analyses/{AnalysisId}/notes/{NoteId} -> 200", function(test, done) { - test.request.params = { - ProjectId: test_project_1._id, - AnalysisId: test_project_1.analyses[0]._id, - NoteId: test_project_1.analyses[0].notes[0]._id - }; - done(); -}); - -hooks.before("GET /devices/{DeviceId} -> 200", function(test, done) { - test.request.params.DeviceId = device_id; - done(); -}); - -hooks.before("GET /devices/{DeviceId} -> 404", function(test, done) { - test.request.params.DeviceId = 'bad_device_id'; - done(); -}); diff --git a/tests/integration_tests/abao/load_fixture.py b/tests/integration_tests/abao/load_fixture.py deleted file mode 100644 index 32c036bdc..000000000 --- a/tests/integration_tests/abao/load_fixture.py +++ /dev/null @@ -1,433 +0,0 @@ -import datetime -import json -import os - -import pymongo -import requests - - -# load required envvars w/ the same name -SCITRAN_CORE_DRONE_SECRET = os.environ['SCITRAN_CORE_DRONE_SECRET'] -SCITRAN_PERSISTENT_DB_URI = os.environ['SCITRAN_PERSISTENT_DB_URI'] -SCITRAN_SITE_API_URL = os.environ['SCITRAN_SITE_API_URL'] - - -class BaseUrlSession(requests.Session): - """Requests session subclass using core api's base url""" - def request(self, method, url, **kwargs): - return super(BaseUrlSession, self).request(method, SCITRAN_SITE_API_URL + url, **kwargs) - - -def main(): - abao_user = 'abao@user.com' - abao_api_key = 'XZpXI40Uk85eozjQkU1zHJ6yZHpix+j0mo1TMeGZ4dPzIqVPVGPmyfeK' - - as_drone = BaseUrlSession() - as_drone.headers.update({ - 'X-SciTran-Method': 'bootstrapper', - 'X-SciTran-Name': 'Bootstrapper', - 'X-SciTran-Auth': SCITRAN_CORE_DRONE_SECRET, - }) - - as_drone.post('/users', json={ - '_id': abao_user, - 'firstname': 'Abao', - 'lastname': 'User', - 'root': True, - }) - api_db = pymongo.MongoClient(SCITRAN_PERSISTENT_DB_URI).get_default_database() - api_db.apikeys.insert_one({ - '_id': abao_api_key, - 'created': datetime.datetime.utcnow(), - 'last_seen': None, - 'type': 'user', - 'uid': abao_user - }) - - as_root = BaseUrlSession() - as_root.headers.update({'Authorization': 'scitran-user {}'.format(abao_api_key)}) - as_root.params.update({'root': 'true'}) - - # create scitran group - r = as_root.post('/groups', json={'_id': 'scitran'}) - assert r.ok - - # create test-group - r = as_root.post('/groups', json={'_id': 'test-group'}) - assert r.ok - - # upload file to test-project-1/test-session-1/test-acquisition-1 - # depends on 'create test-group' - r = as_root.post('/upload/label', files={ - 'file': ('test-1.dcm', open('tests/integration_tests/abao/test_files/test-1.dcm', 'rb')), - 'metadata': ('', json.dumps({ - 'group': { '_id': 'test-group' }, - 'project': { - 'label': 'test-project-1' - }, - 'session': { - 'label': 'test-session-1', - 'subject': { - 'age': 25, - 'sex': 'male', - 'firstname': 'xyz' - } - }, - 'acquisition': { - 'label': 'test-acquisition-1', - 'files': [{ 'name': 'test-1.dcm' }] - } - })) - }) - assert r.ok - - # list projects - # depends on 'upload file to test-project-1/test-session-1/test-acquisition-1' - r = as_root.get('/projects') - assert r.ok - assert r.json()[0]['label'] == 'test-project-1' - test_project = r.json()[0] - - # list sessions - # depends on 'upload file to test-project-1/test-session-1/test-acquisition-1' - r = as_root.get('/sessions') - assert r.ok - assert r.json()[0]['label'] == 'test-session-1' - test_session = r.json()[0] - - # list acquisitions for test-session-1 - # depends on 'upload file to test-project-1/test-session-1/test-acquisition-1' - r = as_root.get('/sessions/' + test_session['_id'] + '/acquisitions') - assert r.ok - assert r.json()[0]['label'] == 'test-acquisition-1' - test_acquisition = r.json()[0] - - # add test-case-gear - r = as_root.post('/gears/test-case-gear', json={ - 'category': 'converter', - 'gear': { - 'inputs': { - 'dicom': { - 'base': 'file', - 'type': { 'enum': [ 'wat' ] } - } - }, - 'maintainer': 'Example', - 'description': 'Example', - 'license': 'BSD-2-Clause', - 'author': 'Example', - 'url': 'https://example.example', - 'label': 'wat', - 'flywheel': '0', - 'source': 'https://example.example', - 'version': '0.0.1', - 'config': {}, - 'name': 'test-case-gear' - }, - 'exchange': { - 'git-commit': 'aex', - 'rootfs-hash': 'sha384:oy', - 'rootfs-url': 'https://example.example' - } - }) - assert r.ok - test_gear = r.json() - - # create test-collection-1 - r = as_root.post('/collections', json={ - 'label': 'test-collection-1' - }) - assert r.ok - test_collection = r.json() - - # add test-session-1 to test-collection-1 - # depends on 'upload file to test-project-1/test-session-1/test-acquisition-1' - # depends on 'create test-collection-1' - r = as_root.put('/collections/' + test_collection['_id'], json={ - 'contents':{ - 'operation': 'add', - 'nodes': [{ - 'level': 'session', - '_id': test_session['_id'] - }] - } - }) - assert r.ok - - # upload file to test-collection-1 - # depends on 'create test-collection-1' - r = as_root.post('/collections/' + test_collection['_id'] + '/files', files={ - 'file': ('notes.txt', open('tests/integration_tests/abao/test_files/notes.txt', 'rb')) - }) - assert r.ok - - # create test-collection-2 - r = as_root.post('/collections', json={ - 'label': 'test-collection-2' - }) - assert r.ok - - # upload file to test-project-1 - # depends on 'upload file to test-project-1/test-session-1/test-acquisition-1' - r = as_root.post('/projects/' + test_project['_id'] + '/files', files={ - 'file': ('notes.txt', open('tests/integration_tests/abao/test_files/notes.txt', 'rb')) - }) - assert r.ok - - # upload file to test-session-1 - # depends on 'upload file to test-project-1/test-session-1/test-acquisition-1' - r = as_root.post('/sessions/' + test_session['_id'] + '/files', files={ - 'file': ('notes.txt', open('tests/integration_tests/abao/test_files/notes.txt', 'rb')) - }) - assert r.ok - - # add a note to test-project-1 - # depends on 'upload file to test-project-1/test-session-1/test-acquisition-1' - r = as_root.post('/projects/' + test_project['_id'] + '/notes', json={ - 'text': 'test note' - }) - assert r.ok - - # add a note to test-session-1 - # depends on 'upload file to test-project-1/test-session-1/test-acquisition-1' - r = as_root.post('/sessions/' + test_session['_id'] + '/notes', json={ - 'text': 'test note' - }) - assert r.ok - - # add a note to test-acquisition-1 - # depends on 'upload file to test-project-1/test-session-1/test-acquisition-1' - r = as_root.post('/acquisitions/' + test_acquisition['_id'] + '/notes', json={ - 'text': 'test note' - }) - assert r.ok - - # add a note to test-collection-1 - # depends on 'create test-collection-1' - r = as_root.post('/collections/' + test_collection['_id'] + '/notes', json={ - 'text': 'test note' - }) - assert r.ok - - # create session 1 test-analysis-1 (job) - # depends on 'upload file to test-project-1/test-session-1/test-acquisition-1' - # depends on 'add test-case-gear' - r = as_root.post('/sessions/' + test_session['_id'] + '/analyses?job=true', json={ - 'analysis': { 'label': 'Test Analysis 1' }, - 'job': { - 'gear_id': test_gear['_id'], - 'inputs': { - 'dicom': { - 'type': 'acquisition', - 'id': test_acquisition['_id'], - 'name': 'test-1.dcm' - } - }, - 'tags': ['example'] - } - }) - assert r.ok - test_session_analysis = r.json() - - # create session 1 test-analysis (file upload) - # depends on 'upload file to test-project-1/test-session-1/test-acquisition-1' - r = as_root.post('/sessions/' + test_session['_id'] + '/analyses', files={ - 'file': ('test-1.dcm', open('tests/integration_tests/abao/test_files/test-1.dcm', 'rb')), - 'metadata': ('', json.dumps({ - 'label': 'test analysis', - 'inputs': [ { 'name': 'test-1.dcm' } ] - })) - }) - assert r.ok - test_session_analysis_upload = r.json() - - # delete session 1 test analysis (file upload) - # depends on 'create session 1 test-analysis (file upload)' - r = as_root.delete('/sessions/' + test_session['_id'] + '/analyses/' + test_session_analysis_upload['_id']) - assert r.ok - - # create acquisition 1 test-analysis (file upload) - # depends on 'upload file to test-project-1/test-session-1/test-acquisition-1' - r = as_root.post('/acquisitions/' + test_acquisition['_id'] + '/analyses', files={ - 'file': ('test-1.dcm', open('tests/integration_tests/abao/test_files/test-1.dcm', 'rb')), - 'metadata': ('', json.dumps({ - 'label': 'test analysis', - 'inputs': [ { 'name': 'test-1.dcm' } ] - })) - }) - assert r.ok - test_acquisition_analysis_upload = r.json() - - # create acquisition 1 test-analysis 2 (file upload) - # depends on 'upload file to test-project-1/test-session-1/test-acquisition-1' - r = as_root.post('/acquisitions/' + test_acquisition['_id'] + '/analyses', files={ - 'file': ('test-1.dcm', open('tests/integration_tests/abao/test_files/test-1.dcm', 'rb')), - 'metadata': ('', json.dumps({ - 'label': 'test analysis', - 'inputs': [ { 'name': 'test-1.dcm' } ] - })) - }) - assert r.ok - - # create collection 1 test-analysis (file upload) - # depends on 'create test-collection-1' - r = as_root.post('/collections/' + test_collection['_id'] + '/analyses', files={ - 'file': ('test-1.dcm', open('tests/integration_tests/abao/test_files/test-1.dcm', 'rb')), - 'metadata': ('', json.dumps({ - 'label': 'test analysis', - 'inputs': [ { 'name': 'test-1.dcm' } ] - })) - }) - assert r.ok - test_collection_analysis_upload = r.json() - - # create collection 1 test-analysis 2 (file upload) - # depends on 'create test-collection-1' - r = as_root.post('/collections/' + test_collection['_id'] + '/analyses', files={ - 'file': ('test-1.dcm', open('tests/integration_tests/abao/test_files/test-1.dcm', 'rb')), - 'metadata': ('', json.dumps({ - 'label': 'test analysis 2', - 'inputs': [ { 'name': 'test-1.dcm' } ] - })) - }) - assert r.ok - - # create project 1 test-analysis (file upload) - # depends on 'upload file to test-project-1/test-session-1/test-acquisition-1' - r = as_root.post('/projects/' + test_project['_id'] + '/analyses', files={ - 'file': ('test-1.dcm', open('tests/integration_tests/abao/test_files/test-1.dcm', 'rb')), - 'metadata': ('', json.dumps({ - 'label': 'test analysis', - 'inputs': [ { 'name': 'test-1.dcm' } ] - })) - }) - assert r.ok - test_project_analysis_upload = r.json() - - # create project 1 test-analysis 2 (file upload) - # depends on 'upload file to test-project-1/test-session-1/test-acquisition-1' - r = as_root.post('/projects/' + test_project['_id'] + '/analyses', files={ - 'file': ('test-1.dcm', open('tests/integration_tests/abao/test_files/test-1.dcm', 'rb')), - 'metadata': ('', json.dumps({ - 'label': 'test analysis', - 'inputs': [ { 'name': 'test-1.dcm' } ] - })) - }) - assert r.ok - - # add a note to test-acquisition-1 test-analysis-1 - # depends on 'create acquisition 1 test-analysis (file upload)' - r = as_root.post('/acquisitions/' + test_acquisition['_id'] + '/analyses/' + test_acquisition_analysis_upload['_id'] + '/notes', json={ - 'text': 'test note' - }) - assert r.ok - - # add a note to test-collection-1 test-analysis-1 - # depends on 'create test-collection-1' - r = as_root.post('/collections/' + test_collection['_id'] + '/analyses/' + test_collection_analysis_upload['_id'] + '/notes', json={ - 'text': 'test note' - }) - assert r.ok - - # add a note to test-session-1 test-analysis-1 - # depends on 'create session 1 test-analysis (file upload)' - r = as_root.post('/sessions/' + test_session['_id'] + '/analyses/' + test_session_analysis['_id'] + '/notes', json={ - 'text': 'test note' - }) - assert r.ok - - # add a note to test-project-1 test-analysis-1 - # depends on 'create project 1 test-analysis (file upload)' - r = as_root.post('/projects/' + test_project['_id'] + '/analyses/' + test_project_analysis_upload['_id'] + '/notes', json={ - 'text': 'test note' - }) - assert r.ok - - # create project - r = as_root.post('/projects', json={ - 'group': 'test-group', - 'label': 'Project with template', - 'public': False - }) - assert r.ok - st_project = r.json() - - # create compliant session - # depends on 'create project' - r = as_root.post('/sessions', json={ - 'subject': { 'code': 'ex8945' }, - 'label': 'Compliant Session', - 'project': st_project['_id'], - 'public': False - }) - assert r.ok - st_compliant_session = r.json() - - # create non-compliant session - # depends on 'create project' - r = as_root.post('/sessions', json={ - 'subject': { 'code': 'ex9849' }, - 'label': 'Non-compliant Session', - 'project': st_project['_id'], - 'public': False - }) - assert r.ok - st_noncompliant_session = r.json() - - # create acquisition-1 for compliant session - # depends on 'create compliant session' - r = as_root.post('/acquisitions', json={ - 'label': 'c-acquisition-1-t1', - 'session': st_compliant_session['_id'], - 'public': False - }) - assert r.ok - - # create acquisition-2 for compliant session - # depends on 'create compliant session' - r = as_root.post('/acquisitions', json={ - 'label': 'c-acquisition-2-t1', - 'session': st_compliant_session['_id'], - 'public': False - }) - assert r.ok - - # create acquisition-1 for noncompliant session - # depends on 'create non-compliant session' - r = as_root.post('/acquisitions', json={ - 'label': 'nc-acquisition-1-t1', - 'session': st_noncompliant_session['_id'], - 'public': False - }) - assert r.ok - - # add project template - r = as_root.post('/projects/' + st_project['_id'] + '/template', json={ - 'session': { 'subject': { 'code' : '^ex' } }, - 'acquisitions': [{ - 'label': 't1', - 'minimum': 2 - }] - }) - assert r.ok - assert r.json()['modified'] == 1 - - # create acquisition-2 for noncompliant session - # depends on 'create non-compliant session' - r = as_root.post('/acquisitions', json={ - 'label': 'nc-acquisition-2-t1', - 'session': st_noncompliant_session['_id'], - 'public': False - }) - assert r.ok - - # update session 2 to be non-compliant - # depends on 'create non-compliant session' - r = as_root.put('/sessions/' + st_noncompliant_session['_id'], json={ - 'subject': { 'code': 'bad-subject-code' } - }) - assert r.ok - - -if __name__ == '__main__': - main() diff --git a/tests/integration_tests/abao/package.json b/tests/integration_tests/abao/package.json deleted file mode 100644 index ea666c398..000000000 --- a/tests/integration_tests/abao/package.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "name": "scitran-core-integration-tests", - "version": "1.0.0", - "description": "SciTran Core integation test node dependencies", - "dependencies": { - "abao":"git+https://github.com/flywheel-io/abao.git#better-jsonschema-ref", - "chai": "~3.5.0" - }, - "bin":{ - "abao":"node_modules/.bin/abao" - } -} diff --git a/tests/integration_tests/abao/test_files/engine-analyses-1.txt b/tests/integration_tests/abao/test_files/engine-analyses-1.txt deleted file mode 100644 index 6686dd9ae..000000000 --- a/tests/integration_tests/abao/test_files/engine-analyses-1.txt +++ /dev/null @@ -1 +0,0 @@ -Replace this with something more realistic diff --git a/tests/integration_tests/abao/test_files/notes.txt b/tests/integration_tests/abao/test_files/notes.txt deleted file mode 100644 index 907b30816..000000000 --- a/tests/integration_tests/abao/test_files/notes.txt +++ /dev/null @@ -1 +0,0 @@ -blah diff --git a/tests/integration_tests/abao/test_files/test-1.dcm b/tests/integration_tests/abao/test_files/test-1.dcm deleted file mode 100644 index f088aa8f9..000000000 Binary files a/tests/integration_tests/abao/test_files/test-1.dcm and /dev/null differ