Fixes #11: adding a delete endpoint for studies. It won't delete studies that have workflows, you have to delete those first)
Removing the "default" error response from the api.yml, it was all noise.
This commit is contained in:
parent
1cd5c0fb02
commit
e91d7aff2f
87
crc/api.yml
87
crc/api.yml
|
@ -90,12 +90,6 @@ paths:
|
|||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Study"
|
||||
default:
|
||||
description: unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
post:
|
||||
operationId: crc.api.study.add_study
|
||||
summary: Creates a new study with the given parameters.
|
||||
|
@ -113,12 +107,6 @@ paths:
|
|||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Study"
|
||||
default:
|
||||
description: unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
/study/{study_id}:
|
||||
parameters:
|
||||
- name: study_id
|
||||
|
@ -140,12 +128,14 @@ paths:
|
|||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Study"
|
||||
default:
|
||||
description: unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
delete:
|
||||
operationId: crc.api.study.delete_study
|
||||
summary: Removes the given study completely.
|
||||
tags:
|
||||
- Studies
|
||||
responses:
|
||||
'204':
|
||||
description: The study has been removed.
|
||||
put:
|
||||
operationId: crc.api.study.update_study
|
||||
summary: Updates an existing study with the given parameters.
|
||||
|
@ -163,12 +153,6 @@ paths:
|
|||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Study"
|
||||
default:
|
||||
description: unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
/study-update/{study_id}:
|
||||
post:
|
||||
operationId: crc.api.study.post_update_study_from_protocol_builder
|
||||
|
@ -188,12 +172,6 @@ paths:
|
|||
description: Study is currently up to date and does not need to be reloaded from Protocol Builder
|
||||
'202':
|
||||
description: Request accepted, will preform an update. Study state set to "updating"
|
||||
default:
|
||||
description: unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
/study/{study_id}/workflows:
|
||||
get:
|
||||
operationId: crc.api.study.get_study_workflows
|
||||
|
@ -217,12 +195,6 @@ paths:
|
|||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/Workflow"
|
||||
default:
|
||||
description: unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
post:
|
||||
operationId: crc.api.study.add_workflow_to_study
|
||||
summary: Starts a new workflow for the given study using the provided spec. This is atypical, and should be left to the protocol builder.
|
||||
|
@ -250,12 +222,6 @@ paths:
|
|||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/Workflow"
|
||||
default:
|
||||
description: unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
/workflow-specification:
|
||||
get:
|
||||
operationId: crc.api.workflow.all_specifications
|
||||
|
@ -271,12 +237,6 @@ paths:
|
|||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/WorkflowSpec"
|
||||
default:
|
||||
description: unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
post:
|
||||
operationId: crc.api.workflow.add_workflow_specification
|
||||
summary: Creates a new workflow specification with the given parameters.
|
||||
|
@ -294,12 +254,6 @@ paths:
|
|||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/WorkflowSpec"
|
||||
default:
|
||||
description: unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
/workflow-specification/{spec_id}:
|
||||
parameters:
|
||||
- name: spec_id
|
||||
|
@ -337,12 +291,6 @@ paths:
|
|||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/WorkflowSpec"
|
||||
default:
|
||||
description: unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
delete:
|
||||
operationId: crc.api.workflow.delete_workflow_specification
|
||||
summary: Removes an existing workflow specification
|
||||
|
@ -397,12 +345,7 @@ paths:
|
|||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/File"
|
||||
default:
|
||||
description: unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
|
||||
post:
|
||||
operationId: crc.api.file.add_file
|
||||
summary: Add a new file
|
||||
|
@ -461,12 +404,6 @@ paths:
|
|||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/File"
|
||||
default:
|
||||
description: unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
delete:
|
||||
operationId: crc.api.file.delete_file
|
||||
summary: Removes an existing file
|
||||
|
@ -555,12 +492,6 @@ paths:
|
|||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Workflow"
|
||||
default:
|
||||
description: unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
delete:
|
||||
operationId: crc.api.workflow.delete
|
||||
summary: Removes an existing workflow
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
import logging
|
||||
from typing import List, Optional, Union, Tuple, Dict
|
||||
|
||||
from connexion import NoContent
|
||||
from flask import g
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
|
||||
from crc import session, auth
|
||||
from crc import session, auth, app
|
||||
from crc.api.common import ApiError, ApiErrorSchema
|
||||
from crc.api.workflow import __get_workflow_api_model
|
||||
from crc.models.api_models import WorkflowApiSchema
|
||||
|
@ -31,6 +33,7 @@ def add_study(body):
|
|||
return StudyModelSchema().dump(study)
|
||||
|
||||
|
||||
|
||||
@auth.login_required
|
||||
def update_study(study_id, body):
|
||||
if study_id is None:
|
||||
|
@ -59,6 +62,16 @@ def get_study(study_id):
|
|||
return schema.dump(study)
|
||||
|
||||
|
||||
def delete_study(study_id):
|
||||
try:
|
||||
session.query(StudyModel).filter_by(id=study_id).delete()
|
||||
except IntegrityError as ie:
|
||||
session.rollback()
|
||||
app.logger.error("Failed to delete Study #%i due to an Integrity Error: %s" % (study_id, str(ie)))
|
||||
raise ApiError(code="study_integrity_error", message="This study contains running workflows that is "
|
||||
"preventing deletion. Please delete the workflows " +
|
||||
"before proceeding.")
|
||||
|
||||
@auth.login_required
|
||||
def update_from_protocol_builder():
|
||||
"""Updates the list of known studies for a given user based on data received from
|
||||
|
|
|
@ -113,11 +113,14 @@ class BaseTest(unittest.TestCase):
|
|||
self.assertTrue(200 <= rv.status_code < 300,
|
||||
"BAD Response: %i." % rv.status_code + ". " + msg)
|
||||
|
||||
def assert_failure(self, rv, code=0):
|
||||
def assert_failure(self, rv, status_code=0, error_code=""):
|
||||
self.assertFalse(200 <= rv.status_code < 300,
|
||||
"Incorrect Valid Response:" + rv.status + ".")
|
||||
if code != 0:
|
||||
self.assertEqual(code, rv.status_code)
|
||||
if status_code != 0:
|
||||
self.assertEqual(status_code, rv.status_code)
|
||||
if error_code != "":
|
||||
data = json.loads(rv.get_data(as_text=True))
|
||||
self.assertEqual(error_code, data["code"])
|
||||
|
||||
@staticmethod
|
||||
def user_info_to_query_string(user_info, redirect_url):
|
||||
|
|
|
@ -141,6 +141,28 @@ class TestStudyApi(BaseTest):
|
|||
workflow2 = WorkflowApiSchema().load(json_data)
|
||||
self.assertEqual(workflow_model.id, workflow2.id)
|
||||
|
||||
def test_delete_study(self):
|
||||
self.load_example_data()
|
||||
study = session.query(StudyModel).first()
|
||||
rv = self.app.delete('/v1.0/study/%i' % study.id)
|
||||
self.assert_success(rv)
|
||||
|
||||
def test_delete_study_with_workflow(self):
|
||||
self.load_example_data()
|
||||
study = session.query(StudyModel).first()
|
||||
|
||||
spec = session.query(WorkflowSpecModel).first()
|
||||
rv = self.app.post('/v1.0/study/%i/workflows' % study.id,
|
||||
content_type="application/json",
|
||||
headers=self.logged_in_headers(),
|
||||
data=json.dumps(WorkflowSpecModelSchema().dump(spec)))
|
||||
|
||||
rv = self.app.delete('/v1.0/study/%i' % study.id)
|
||||
self.assert_failure(rv, error_code="study_integrity_error")
|
||||
|
||||
|
||||
|
||||
|
||||
def test_delete_workflow(self):
|
||||
self.load_example_data()
|
||||
study = session.query(StudyModel).first()
|
||||
|
|
Loading…
Reference in New Issue