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

feat: more robust backend code and cleanup in tests (#354) #356

Merged
merged 1 commit into from
Jan 2, 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
4 changes: 1 addition & 3 deletions backend/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@ pydantic = {extras = ["email"], version = "*"}
pydantic-settings = "*"
python-dateutil = "*"
python-dotenv = "*"
requests-mock = "*"
sqlalchemy = "*"
tenacity = "*"
uvicorn = "*"
alembic = "*"
requests = "*"
types-requests = "*"
greenlet = "*"
emails = "*"
jinja2 = "*"
Expand Down Expand Up @@ -61,6 +58,7 @@ watchdog = "*"
celery-types = "*"
jupyterlab = "*"
pytest-mock = "*"
gevent = "*"

[requires]
python_version = "3.10"
1,927 changes: 859 additions & 1,068 deletions backend/Pipfile.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions backend/app/api/api_v1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ def __init__(
base_scopes=base_scopes,
)

async def get_id_email(self, token: str) -> Tuple[str, Optional[str]]:
# Note: It is OK to not epect coverage here as this integrates with upstream API.
async def get_id_email(self, token: str) -> Tuple[str, Optional[str]]: # pragma: no cover
"""Custom implementation that returns the user ID and email."""
async with self.get_httpx_client() as client:
response_user = await client.get(
Expand All @@ -103,7 +104,7 @@ async def get_id_email(self, token: str) -> Tuple[str, Optional[str]]:
data_user: Dict[str, Any] = response_user.json()

response_record = await client.get(
f"https://api.sandbox.orcid.org/v3.0/{data_user['sub']}/record",
f"https://api.orcid.org/v3.0/{data_user['sub']}/record",
headers={**self.request_headers, "Authorization": f"Bearer {token}"},
)
if response_user.status_code >= 400:
Expand Down
28 changes: 14 additions & 14 deletions backend/app/api/api_v1/endpoints/acmgseqvar.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ async def get_acmgseqvar(id: str, db: AsyncSession = Depends(deps.get_db)):
:return: ACMG Sequence Variant
:rtype: dict
"""
response = await crud.acmgseqvar.get(db, id)
if not response:
result = await crud.acmgseqvar.get(db, id)
if not result: # pragma: no cover
raise HTTPException(status_code=404, detail="ACMG Sequence Variant not found")
else:
return response
return result


@router.get("/list", response_model=list[schemas.AcmgSeqVarRead])
Expand Down Expand Up @@ -99,11 +99,11 @@ async def get_acmgseqvar_by_user(
:return: ACMG Sequence Variant
:rtype: dict
"""
response = await crud.acmgseqvar.get_by_user(db, user_id=user.id, seqvar_name=seqvar)
if not response:
result = await crud.acmgseqvar.get_by_user(db, user_id=user.id, seqvar_name=seqvar)
if not result: # pragma: no cover
raise HTTPException(status_code=404, detail="ACMG Sequence Variant not found")
else:
return response
return result


@router.put("/update", response_model=schemas.AcmgSeqVarRead)
Expand All @@ -122,13 +122,13 @@ async def update_acmgseqvar(
:rtype: dict
"""
acmgseqvar.user = user.id
response = await crud.acmgseqvar.get_by_user(
result = await crud.acmgseqvar.get_by_user(
db, user_id=user.id, seqvar_name=acmgseqvar.seqvar_name
)
if not response:
if not result: # pragma: no cover
raise HTTPException(status_code=404, detail="ACMG Sequence Variant not found")
else:
return await crud.acmgseqvar.update(db, db_obj=response, obj_in=acmgseqvar)
return await crud.acmgseqvar.update(db, db_obj=result, obj_in=acmgseqvar)


@router.delete(
Expand All @@ -145,8 +145,8 @@ async def delete_acmgseqvar(id: str, db: AsyncSession = Depends(deps.get_db)):
:return: ACMG Sequence Variant
:rtype: dict
"""
response = await crud.acmgseqvar.get(db, id)
if not response:
result = await crud.acmgseqvar.get(db, id)
if not result: # pragma: no cover
raise HTTPException(status_code=404, detail="ACMG Sequence Variant not found")
else:
return await crud.acmgseqvar.remove(db, id=id)
Expand All @@ -166,8 +166,8 @@ async def delete_acmgseqvar_by_user(
:return: ACMG Sequence Variant
:rtype: dict
"""
response = await crud.acmgseqvar.get_by_user(db, user_id=user.id, seqvar_name=seqvar)
if not response:
result = await crud.acmgseqvar.get_by_user(db, user_id=user.id, seqvar_name=seqvar)
if not result: # pragma: no cover
raise HTTPException(status_code=404, detail="ACMG Sequence Variant not found")
else:
return await crud.acmgseqvar.remove(db, id=response.id)
return await crud.acmgseqvar.remove(db, id=result.id)
20 changes: 10 additions & 10 deletions backend/app/api/api_v1/endpoints/bookmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ async def get_bookmark(id: str, db: AsyncSession = Depends(deps.get_db)):
:return: bookmark
:rtype: dict
"""
response = await crud.bookmark.get(db, id=id)
if not response:
result = await crud.bookmark.get(db, id=id)
if not result: # pragma: no cover
raise HTTPException(status_code=404, detail="Bookmark not found")
else:
return response
return result


@router.delete(
Expand All @@ -81,11 +81,11 @@ async def delete_bookmark(id: str, db: AsyncSession = Depends(deps.get_db)):
:return: bookmark which was deleted
:rtype: dict
"""
response = await crud.bookmark.remove(db, id=id)
if not response:
result = await crud.bookmark.remove(db, id=id)
if not result: # pragma: no cover
raise HTTPException(status_code=404, detail="Bookmark not found")
else:
return response
return result


@router.get("/list", response_model=list[schemas.BookmarkRead])
Expand Down Expand Up @@ -125,13 +125,13 @@ async def get_bookmark_for_user(
:return: bookmark
:rtype: dict
"""
response = await crud.bookmark.get_by_user_and_obj(
result = await crud.bookmark.get_by_user_and_obj(
db, user_id=user.id, obj_type=obj_type, obj_id=obj_id
)
if not response:
if not result: # pragma: no cover
raise HTTPException(status_code=404, detail="Bookmark not found")
else:
return response
return result


@router.delete("/delete", response_model=schemas.BookmarkRead)
Expand All @@ -157,5 +157,5 @@ async def delete_bookmark_for_user(
)
if bookmark:
return await crud.bookmark.remove(db, id=bookmark.id)
else:
else: # pragma: no cover
raise HTTPException(status_code=404, detail="Bookmark not found")
14 changes: 7 additions & 7 deletions backend/app/api/api_v1/endpoints/caseinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ async def get_caseinfo(id: str, db: AsyncSession = Depends(deps.get_db)):
:return: Case Information
:rtype: dict
"""
response = await crud.caseinfo.get(db, id=id)
if not response:
caseinfo = await crud.caseinfo.get(db, id=id)
if not caseinfo: # pragma: no cover
raise HTTPException(status_code=404, detail="Case Information not found")
else:
return response
return caseinfo


@router.get("/list", response_model=list[schemas.CaseInfoRead])
Expand Down Expand Up @@ -92,7 +92,7 @@ async def get_caseinfo_for_user(
:rtype: dict
"""
caseinfo = await crud.caseinfo.get_by_user(db, user_id=user.id)
if not caseinfo:
if not caseinfo: # pragma: no cover
raise HTTPException(status_code=404, detail="Case Information not found")
return caseinfo

Expand All @@ -114,7 +114,7 @@ async def update_caseinfo_for_user(
"""
caseinfoupdate.user = user.id
caseinfo = await crud.caseinfo.get_by_user(db, user_id=user.id)
if not caseinfo:
if not caseinfo: # pragma: no cover # pragma: no cover
raise HTTPException(status_code=404, detail="Case Information not found")
return await crud.caseinfo.update(db, db_obj=caseinfo, obj_in=caseinfoupdate)

Expand All @@ -134,7 +134,7 @@ async def delete_caseinfo(id: str, db: AsyncSession = Depends(deps.get_db)):
:rtype: dict
"""
response = await crud.caseinfo.remove(db, id=id)
if not response:
if not response: # pragma: no cover
raise HTTPException(status_code=404, detail="Case Information not found")
else:
return response
Expand All @@ -151,6 +151,6 @@ async def delete_caseinfo_for_user(
:rtype: dict
"""
caseinfo = await crud.caseinfo.get_by_user(db, user_id=user.id)
if not caseinfo:
if not caseinfo: # pragma: no cover
raise HTTPException(status_code=404, detail="Case Information not found")
return await crud.caseinfo.remove(db, id=caseinfo.id)
34 changes: 17 additions & 17 deletions backend/app/api/api_v1/endpoints/clinvarsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ async def get_submittingorg_by_id(
:return: Submitting org data.
"""
response = await crud.submittingorg.get(db, id=submittingorg_id)
if not response:
if not response: # pragma: no cover
raise HTTPException(status_code=404, detail="submitting org not found")
elif response.owner != user.id:
raise HTTPException(status_code=403, detail="user not owner of submitting org")
Expand All @@ -111,7 +111,7 @@ async def update_submittingorg(
:return: Paginated list of results.
"""
submittingorg_db = await crud.submittingorg.get(db, id=submittingorg_id)
if not submittingorg_db:
if not submittingorg_db: # pragma: no cover
raise HTTPException(status_code=404, detail="submitting org not found")
elif submittingorg_db.owner != user.id:
raise HTTPException(status_code=403, detail="user not owner of submitting org")
Expand All @@ -134,7 +134,7 @@ async def delete_submittingorg(
:return: Paginated list of results.
"""
submittingorg_db = await crud.submittingorg.get(db, id=submittingorg_id)
if not submittingorg_db:
if not submittingorg_db: # pragma: no cover
raise HTTPException(status_code=404, detail="submitting org not found")
elif submittingorg_db.owner != user.id:
raise HTTPException(status_code=403, detail="user not owner of submitting org")
Expand Down Expand Up @@ -175,7 +175,7 @@ async def create_submissionthread(
:return: Created submission thread.
"""
submittingorg = await crud.submittingorg.get(db, id=submissionthread.submittingorg_id)
if not submittingorg:
if not submittingorg: # pragma: no cover
raise HTTPException(status_code=404, detail="submitting org not found")
elif submittingorg.owner != user.id:
raise HTTPException(status_code=403, detail="user not owner of submitting org")
Expand All @@ -200,10 +200,10 @@ async def update_submissionthread(
:return: Submission tread data.
"""
submissionthread_db = await crud.submissionthread.get(db, id=submissionthread_id)
if not submissionthread_db:
if not submissionthread_db: # pragma: no cover
raise HTTPException(status_code=404, detail="submission thread not found")
submittingorg = await crud.submittingorg.get(db, id=submissionthread_db.submittingorg_id)
if not submittingorg:
if not submittingorg: # pragma: no cover
raise HTTPException(status_code=404, detail="submitting org not found")
elif submittingorg.owner != user.id:
raise HTTPException(status_code=403, detail="user not owner of submitting org")
Expand All @@ -229,10 +229,10 @@ async def get_submissionthread_by_id(
:return: Submission tread data.
"""
submissionthread_db = await crud.submissionthread.get(db, id=submissionthread_id)
if not submissionthread_db:
if not submissionthread_db: # pragma: no cover
raise HTTPException(status_code=404, detail="submission thread not found")
submittingorg = await crud.submittingorg.get(db, id=submissionthread_db.submittingorg_id)
if not submittingorg:
if not submittingorg: # pragma: no cover
raise HTTPException(status_code=404, detail="submitting org not found")
elif submittingorg.owner != user.id:
raise HTTPException(status_code=403, detail="user not owner of submitting org")
Expand All @@ -255,10 +255,10 @@ async def delete_submissionthread(
:return: Paginated list of results.
"""
submissionthread_db = await crud.submissionthread.get(db, id=submissionthread_id)
if not submissionthread_db:
if not submissionthread_db: # pragma: no cover
raise HTTPException(status_code=404, detail="submission thread not found")
submittingorg = await crud.submittingorg.get(db, id=submissionthread_db.submittingorg_id)
if not submittingorg:
if not submittingorg: # pragma: no cover
raise HTTPException(status_code=404, detail="submitting org not found")
elif submittingorg.owner != user.id:
raise HTTPException(status_code=403, detail="user not owner of submitting org")
Expand Down Expand Up @@ -287,10 +287,10 @@ async def list_submissionactivities(
:return: Paginated list of results.
"""
submissionthread_db = await crud.submissionthread.get(db, id=submissionthread_id)
if not submissionthread_db:
if not submissionthread_db: # pragma: no cover
raise HTTPException(status_code=404, detail="submission thread not found")
submittingorg = await crud.submittingorg.get(db, id=submissionthread_db.submittingorg_id)
if not submittingorg:
if not submittingorg: # pragma: no cover
raise HTTPException(status_code=404, detail="submitting org not found")
elif submittingorg.owner != user.id:
raise HTTPException(status_code=403, detail="user not owner of submitting org")
Expand All @@ -317,10 +317,10 @@ async def create_submissionactivity(
:return: Created submission activity.
"""
submissionthread_db = await crud.submissionthread.get(db, id=submissionthread_id)
if not submissionthread_db:
if not submissionthread_db: # pragma: no cover
raise HTTPException(status_code=404, detail="submission thread not found")
submittingorg = await crud.submittingorg.get(db, id=submissionthread_db.submittingorg_id)
if not submittingorg:
if not submittingorg: # pragma: no cover
raise HTTPException(status_code=404, detail="submitting org not found")
elif submittingorg.owner != user.id:
raise HTTPException(status_code=403, detail="user not owner of submitting org")
Expand All @@ -345,15 +345,15 @@ async def update_submissionactivity(
:return: Created submission activity.
"""
submissionactivity_db = await crud.submissionactivity.get(db, id=submissionactivity_id)
if not submissionactivity_db:
if not submissionactivity_db: # pragma: no cover
raise HTTPException(status_code=404, detail="submission activity not found")
submissionthread_db = await crud.submissionthread.get(
db, id=submissionactivity_db.submissionthread_id
)
if not submissionthread_db:
if not submissionthread_db: # pragma: no cover
raise HTTPException(status_code=404, detail="submission thread not found")
submittingorg = await crud.submittingorg.get(db, id=submissionthread_db.submittingorg_id)
if not submittingorg:
if not submittingorg: # pragma: no cover
raise HTTPException(status_code=404, detail="submitting org not found")
elif submittingorg.owner != user.id:
raise HTTPException(status_code=403, detail="user not owner of submitting org")
Expand Down
Loading
Loading