Skip to content

Commit

Permalink
Delete sample (#19)
Browse files Browse the repository at this point in the history
* Update OpenAPI generator

* Delete sample endpoint

* Fixed requirement to avoid currently open issue: python-openapi/openapi-spec-validator#126

* Change return status

* Update specs
  • Loading branch information
giang-nghg authored Aug 21, 2021
1 parent 603c0aa commit 7cf6e19
Show file tree
Hide file tree
Showing 13 changed files with 175 additions and 17 deletions.
21 changes: 21 additions & 0 deletions .openapi-generator/FILES
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
openapi_server/__init__.py
openapi_server/controllers/__init__.py
openapi_server/controllers/event_controller.py
openapi_server/controllers/file_controller.py
openapi_server/controllers/qc_result_controller.py
openapi_server/controllers/sample_controller.py
openapi_server/controllers/sample_status_controller.py
openapi_server/controllers/security_controller_.py
openapi_server/encoder.py
openapi_server/models/__init__.py
openapi_server/models/base_model_.py
openapi_server/models/error.py
openapi_server/models/event.py
openapi_server/models/file.py
openapi_server/models/qc_result.py
openapi_server/models/sample.py
openapi_server/models/status.py
openapi_server/openapi/openapi.yaml
openapi_server/typing_utils.py
openapi_server/util.py
setup.py
2 changes: 1 addition & 1 deletion .openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.3.1
5.2.1
23 changes: 22 additions & 1 deletion openapi_server/controllers/sample_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,25 @@ def samples_id_patch(id, new_sample=None): # noqa: E501
except IntegrityError:
return Error(409, 'Already existed'), 409
else:
return old_sample.to_model(), 200
return old_sample.to_model(), 200


def samples_id_delete(id): # noqa: E501
"""samples_id_delete
Delete a sample. # noqa: E501
:param id:
:type id:
:rtype: Sample
"""

inst = orm.Sample.query.get(id)
if not inst:
return Error(404, 'Not found'), 404

db.session.delete(inst)
db.session.commit()

return '', 204
2 changes: 1 addition & 1 deletion openapi_server/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# import models into model package
from openapi_server.models.error import Error
from openapi_server.models.event import Event
from openapi_server.models.file import File
from openapi_server.models.qc_result import QcResult
from openapi_server.models.sample import Sample
from openapi_server.models.status import Status
from openapi_server.models.file import File
13 changes: 9 additions & 4 deletions openapi_server/models/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@


class File(Model):
"""NOTE: This class is COPIED FROM A GENERATED MODEL because OpenAPI Generator (https://openapi-generator.tech) couldn't generate the model (unknown reason).
"""NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Do not edit the class manually ANY FURTHER.
Do not edit the class manually.
"""

def __init__(self, md5sum=None, filename=None, file_type=None): # noqa: E501
Expand All @@ -22,7 +22,7 @@ def __init__(self, md5sum=None, filename=None, file_type=None): # noqa: E501
:type md5sum: str
:param filename: The filename of this File. # noqa: E501
:type filename: str
:param file_type: The file_type of this Event. # noqa: E501
:param file_type: The file_type of this File. # noqa: E501
:type file_type: str
"""
self.openapi_types = {
Expand All @@ -47,7 +47,7 @@ def from_dict(cls, dikt) -> 'File':
:param dikt: A dict.
:type: dict
:return: The File of this Event. # noqa: E501
:return: The File of this File. # noqa: E501
:rtype: File
"""
return util.deserialize_model(dikt, cls)
Expand All @@ -70,6 +70,8 @@ def md5sum(self, md5sum):
:param md5sum: The md5sum of this File.
:type md5sum: str
"""
if md5sum is None:
raise ValueError("Invalid value for `md5sum`, must not be `None`") # noqa: E501

self._md5sum = md5sum

Expand All @@ -91,6 +93,9 @@ def filename(self, filename):
:param filename: The filename of this File.
:type filename: str
"""
if filename is None:
raise ValueError("Invalid value for `filename`, must not be `None`") # noqa: E501

self._filename = filename

@property
Expand Down
61 changes: 61 additions & 0 deletions openapi_server/openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,35 @@ paths:
- sample
x-openapi-router-controller: openapi_server.controllers.sample_controller
/samples/{id}:
delete:
description: Delete a sample.
operationId: samples_id_delete
parameters:
- explode: false
in: path
name: id
required: true
schema:
$ref: '#/components/schemas/SampleID'
style: simple
responses:
"204":
description: Deleted
"404":
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
description: Not found
default:
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
description: Unexpected error
tags:
- sample
x-openapi-router-controller: openapi_server.controllers.sample_controller
get:
description: Return a sample by its ID.
operationId: samples_id_get
Expand Down Expand Up @@ -818,6 +847,7 @@ components:
SampleID:
format: uuid
pattern: ^[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}$
title: id
type: string
Sample:
example:
Expand All @@ -826,13 +856,17 @@ components:
experiment-id: experiment-id
properties:
experiment-id:
title: experiment-id
type: string
isolate-id:
title: isolate-id
type: string
id:
format: uuid
pattern: ^[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}$
title: id
type: string
title: Sample
type: object
File:
example:
Expand All @@ -841,18 +875,22 @@ components:
md5sum: md5sum
properties:
md5sum:
title: md5sum
type: string
filename:
title: filename
type: string
file-type:
enum:
- fastq
- vcf
title: file-type
type: string
required:
- file-type
- filename
- md5sum
title: File
type: object
Event:
example:
Expand All @@ -865,6 +903,7 @@ components:
command: command
properties:
id:
title: id
type: integer
name:
enum:
Expand All @@ -874,17 +913,23 @@ components:
- prediction
- bigsi-building
- distance-calculation
title: name
type: string
software:
title: software
type: string
software-version:
title: software-version
type: string
start-time:
title: start-time
type: number
duration:
format: int32
title: duration
type: integer
command:
title: command
type: string
required:
- command
Expand All @@ -893,6 +938,7 @@ components:
- software
- software-version
- start-time
title: Event
type: object
QcResult:
example:
Expand All @@ -902,19 +948,23 @@ components:
properties:
coverage:
format: float
title: coverage
type: number
number_of_het_snps:
format: int32
title: number_of_het_snps
type: integer
decision:
enum:
- passed
- failed
title: decision
type: string
required:
- coverage
- decision
- number_of_het_snps
title: QcResult
type: object
Status:
example:
Expand All @@ -932,48 +982,55 @@ components:
- started
- complete
- failed
title: de-contamination
type: string
qc:
enum:
- pending
- started
- complete
- failed
title: qc
type: string
variant-calling:
enum:
- pending
- started
- complete
- failed
title: variant-calling
type: string
prediction:
enum:
- pending
- started
- complete
- failed
title: prediction
type: string
bigsi-building:
enum:
- pending
- started
- complete
- failed
title: bigsi-building
type: string
distance-calculation:
enum:
- pending
- started
- complete
- failed
title: distance-calculation
type: string
stage:
enum:
- accepted
- qc-failed
- live
- deprecated
title: stage
type: string
required:
- bigsi-building
Expand All @@ -982,15 +1039,19 @@ components:
- prediction
- qc
- variant-calling
title: Status
type: object
Error:
properties:
code:
format: int32
title: code
type: integer
message:
title: message
type: string
required:
- code
- message
title: Error
type: object
12 changes: 5 additions & 7 deletions openapi_server/test/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging

from hypothesis import settings
from hypothesis import settings, HealthCheck
from pytest import fixture

from openapi_server.migrate import migrate
Expand Down Expand Up @@ -202,11 +202,9 @@ def _(sample_id):


@fixture
def delete_sample():
def _(sample_id):
inst = Sample.query.get(sample_id)
db.session.delete(inst)
db.session.commit()
def delete_sample(make_request):
def _(sample_id, *args, **kwargs):
return make_request(f'/api/v1/samples/{sample_id}', 'DELETE', *args, **kwargs)
return _


Expand All @@ -219,5 +217,5 @@ def _(model):
return _


settings.register_profile('e2e', deadline=None)
settings.register_profile('e2e', deadline=None, suppress_health_check=(HealthCheck.function_scoped_fixture,))
settings.load_profile('e2e')
2 changes: 1 addition & 1 deletion openapi_server/test/test_invalid_sample_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def _(sample_id, *args, **kwargs):
return _


@settings(suppress_health_check=(HealthCheck.filter_too_much,))
@settings(suppress_health_check=(HealthCheck.filter_too_much, HealthCheck.function_scoped_fixture))
@given(sample_id=safe_strings(min_size=1))
def test_invalid_sample_id(sample_id, call_endpoint):
def is_uuid(s):
Expand Down
Loading

0 comments on commit 7cf6e19

Please sign in to comment.