-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite get_or_create function NOT to bypass the ORM
- Loading branch information
Showing
3 changed files
with
54 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ | |
# Nadzeya Hutsko <[email protected]> | ||
|
||
|
||
from fastapi import APIRouter, Depends | ||
from fastapi import APIRouter, Depends, HTTPException | ||
from sqlalchemy.orm import Session | ||
|
||
from test_observer.data_access.models import ( | ||
|
@@ -51,45 +51,48 @@ def start_test_execution( | |
.one() | ||
) | ||
|
||
artefact = get_or_create( | ||
db, | ||
Artefact, | ||
filter_kwargs={ | ||
"name": request.name, | ||
"version": request.version, | ||
"source": request.source, | ||
}, | ||
creation_kwargs={"stage_id": stage.id}, | ||
) | ||
try: | ||
artefact = get_or_create( | ||
db, | ||
Artefact, | ||
filter_kwargs={ | ||
"name": request.name, | ||
"version": request.version, | ||
"source": request.source, | ||
}, | ||
creation_kwargs={"stage_id": stage.id}, | ||
) | ||
|
||
environment = get_or_create( | ||
db, | ||
Environment, | ||
filter_kwargs={"name": request.environment, "architecture": request.arch}, | ||
) | ||
environment = get_or_create( | ||
db, | ||
Environment, | ||
filter_kwargs={"name": request.environment, "architecture": request.arch}, | ||
) | ||
|
||
artefact_build = get_or_create( | ||
db, | ||
ArtefactBuild, | ||
filter_kwargs={ | ||
"architecture": request.arch, | ||
"revision": request.revision, | ||
"artefact_id": artefact.id, | ||
}, | ||
) | ||
artefact_build = get_or_create( | ||
db, | ||
ArtefactBuild, | ||
filter_kwargs={ | ||
"architecture": request.arch, | ||
"revision": request.revision, | ||
"artefact_id": artefact.id, | ||
}, | ||
) | ||
|
||
test_execution = get_or_create( | ||
db, | ||
TestExecution, | ||
filter_kwargs={ | ||
"environment_id": environment.id, | ||
"artefact_build_id": artefact_build.id, | ||
}, | ||
creation_kwargs={ | ||
"status": TestExecutionStatus.IN_PROGRESS, | ||
}, | ||
) | ||
return {"id": test_execution.id} | ||
test_execution = get_or_create( | ||
db, | ||
TestExecution, | ||
filter_kwargs={ | ||
"environment_id": environment.id, | ||
"artefact_build_id": artefact_build.id, | ||
}, | ||
creation_kwargs={ | ||
"status": TestExecutionStatus.IN_PROGRESS, | ||
}, | ||
) | ||
return {"id": test_execution.id} | ||
except ValueError as exc: | ||
raise HTTPException(status_code=400, detail=str(exc)) from exc | ||
|
||
|
||
@router.patch("/{id}") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters