Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a test for the /delete endpoint #138

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

## [unreleased]
### Added
- Delete submission endpoint, with json example (under demo files)
- Delete submission endpoint, with json example (under demo files) and test
### Changed
- Updated API submission schema to the latest available on `ncbi/clinvar` GitHub pages
- Modified the json submission example to use one from the ClinVar GitHib repo (`sample_clinical_significance_hgvs_submission.json`)
Expand Down
8 changes: 2 additions & 6 deletions preClinVar/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@

from preClinVar.__version__ import VERSION
from preClinVar.build import build_header, build_submission
from preClinVar.constants import (
DRY_RUN_SUBMISSION_URL,
SUBMISSION_URL,
VALIDATE_SUBMISSION_URL,
)
from preClinVar.constants import DRY_RUN_SUBMISSION_URL, SUBMISSION_URL, VALIDATE_SUBMISSION_URL
from preClinVar.file_parser import csv_lines, file_fields_to_submission, tsv_lines
from preClinVar.validate import validate_submission

Expand Down Expand Up @@ -241,7 +237,7 @@ async def status(api_key: str = Form(), submission_id: str = Form()) -> JSONResp

@app.post("/delete")
async def delete(api_key: str = Form(), clinvar_accession: str = Form()):
"""A proxy to the dry run submission ClinVar API endpoint"""
"""A proxy to the submission ClinVar API, to delete a submission with a given ClinVar accession."""
# Create a submission header
header = build_header(api_key)

Expand Down
23 changes: 23 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"assertionCriteriaDB": "PubMed",
"assertionCriteriaID": "25741868",
}
DEMO_ACCESSION_ID = "SCV005395965"


def test_heartbeat():
Expand Down Expand Up @@ -411,3 +412,25 @@ def test_status_submitted():
# THEN the response should contain the provided status
assert response.status_code == 200
assert response.json()["actions"][0]["status"] == "submitted"


@responses.activate
def test_delete():
"""Test the endpoint that deletes ClinVar submissions sing the API."""

# GIVEN a mocked submitted response from ClinVar:
responses.add(
responses.POST,
SUBMISSION_URL,
json={"id": DEMO_SUBMISSION_ID},
status=201,
)

# GIVEN a call to the delete endpoint
response = client.post(
"/delete", data={"api_key": DEMO_API_KEY, "clinvar_accession": DEMO_ACCESSION_ID}
)

# THEN the response should contain the provided status
assert response.status_code == 201
assert response.json()["id"] == DEMO_SUBMISSION_ID
Loading