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

Test/deployment form #14

Closed
wants to merge 8 commits into from
Closed
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: 4 additions & 0 deletions api/src/models/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ class DeploymentWithTemplateSequence(ReadDeployment):
template_sequences: Optional[List[TemplateSequence]]


class NewDeploymentWithTemplateSequence(DeploymentBase):
template_sequences: Optional[List[TemplateSequence]]


class DeploymentForProjectSheet(DeploymentEssentials):
id: int
site_name: Optional[str]
Expand Down
6 changes: 4 additions & 2 deletions api/src/routers/deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

from src.connectors.database import get_db
from src.models.deployment import (
DeploymentBase,
Deployments,
DeploymentWithFile,
DeploymentWithTemplateSequence,
NewDeploymentWithTemplateSequence,
ReadDeployment,
)
from src.services import deployment
Expand Down Expand Up @@ -36,7 +36,9 @@ def read_deployment(deployment_id: int, db: Session = Depends(get_db)):


@router.post("/", response_model=Deployments)
def create_deployment(new_deployment: DeploymentBase, db: Session = Depends(get_db)):
def create_deployment(
new_deployment: NewDeploymentWithTemplateSequence, db: Session = Depends(get_db)
):
db_deployment = deployment.get_deployment_by_name(db, name_deployment=new_deployment.name)
if db_deployment:
raise HTTPException(status_code=400, detail="Name already registered")
Expand Down
23 changes: 20 additions & 3 deletions api/src/services/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
from sqlalchemy.orm import joinedload
from sqlmodel import Session

from src.models.deployment import DeploymentBase, Deployments, DeploymentWithTemplateSequence
from src.models.deployment import (
Deployments,
DeploymentWithTemplateSequence,
NewDeploymentWithTemplateSequence,
)
from src.models.models import TemplateSequence


Expand All @@ -22,8 +26,21 @@ def get_deployment_by_name(db: Session, name_deployment: str):
return db.query(Deployments).filter(Deployments.name == name_deployment).first()


def create_deployment(db: Session, deployment: DeploymentBase):
db_deployment = Deployments(**deployment.dict())
def create_deployment(db: Session, deployment: NewDeploymentWithTemplateSequence):
field = "template_sequences"
create_data = deployment.dict()
tmp_deployment = {**create_data, field: []}

for template in create_data[field]:
if "id" in template and template["id"] is not None:
existing_template = (
db.query(TemplateSequence).filter(TemplateSequence.id == template["id"]).one()
)
tmp_deployment[field].append(existing_template)
if "id" in template and template["id"] is None:
tmp_deployment[field].append(TemplateSequence(**template))

db_deployment = Deployments(**tmp_deployment)
db.add(db_deployment)
db.commit()
db.refresh(db_deployment)
Expand Down
6 changes: 3 additions & 3 deletions api/tests/fixtures/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import pytest

from src.models.deployment import DeploymentBase, Deployments
from src.models.deployment import Deployments, NewDeploymentWithTemplateSequence
from src.services.deployment import create_deployment


@pytest.fixture()
def deployment(db, device, project, site) -> Deployments:
date = datetime.now()
data = DeploymentBase(
data = NewDeploymentWithTemplateSequence(
name="1er deployment",
start_date=date.isoformat(),
end_date=date.isoformat(),
Expand All @@ -19,7 +19,7 @@ def deployment(db, device, project, site) -> Deployments:
feature="feature",
description="desc",
project_id=project.id,
# template_sequence_id= Optional[int]
template_sequences=[]
)

return create_deployment(db=db, deployment=data)
1 change: 1 addition & 0 deletions api/tests/test_routers/test_deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def test_create_deployment(client, site, device, project):
"feature": "feature",
"description": "desc",
"project_id": project.id,
"template_sequences": [],
}

response = client.post(url, json=deployment)
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export type { Body_upload_file_files_upload__deployment_id__post } from './model
export type { Body_upload_files_files_upload_files__deployment_id__post } from './models/Body_upload_files_files_upload_files__deployment_id__post';
export type { Body_upload_zip_files_upload_zip__deployment_id__post } from './models/Body_upload_zip_files_upload_zip__deployment_id__post';
export type { DataProject } from './models/DataProject';
export type { DeploymentBase } from './models/DeploymentBase';
export type { DeploymentForProjectSheet } from './models/DeploymentForProjectSheet';
export type { Deployments } from './models/Deployments';
export type { DeploymentWithFile } from './models/DeploymentWithFile';
Expand All @@ -23,6 +22,7 @@ export type { Devices } from './models/Devices';
export type { Files } from './models/Files';
export type { FirstUntreated } from './models/FirstUntreated';
export type { HTTPValidationError } from './models/HTTPValidationError';
export type { NewDeploymentWithTemplateSequence } from './models/NewDeploymentWithTemplateSequence';
export type { ProjectBase } from './models/ProjectBase';
export type { ProjectSheet } from './models/ProjectSheet';
export type { ProjectWithDeployment } from './models/ProjectWithDeployment';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
/* tslint:disable */
/* eslint-disable */

export type DeploymentBase = {
import type { TemplateSequence } from './TemplateSequence';

export type NewDeploymentWithTemplateSequence = {
name: string;
start_date: string;
end_date?: string;
Expand All @@ -15,5 +17,6 @@ export type DeploymentBase = {
description?: string;
image?: string;
project_id: number;
template_sequences?: Array<TemplateSequence>;
};

4 changes: 2 additions & 2 deletions frontend/src/client/services/DeploymentsService.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
import type { DeploymentBase } from '../models/DeploymentBase';
import type { Deployments } from '../models/Deployments';
import type { DeploymentWithFile } from '../models/DeploymentWithFile';
import type { DeploymentWithTemplateSequence } from '../models/DeploymentWithTemplateSequence';
import type { NewDeploymentWithTemplateSequence } from '../models/NewDeploymentWithTemplateSequence';
import type { ReadDeployment } from '../models/ReadDeployment';

import type { CancelablePromise } from '../core/CancelablePromise';
Expand Down Expand Up @@ -45,7 +45,7 @@ export class DeploymentsService {
* @throws ApiError
*/
public static createDeploymentDeploymentsPost(
requestBody: DeploymentBase,
requestBody: NewDeploymentWithTemplateSequence,
): CancelablePromise<Deployments> {
return __request(OpenAPI, {
method: 'POST',
Expand Down
Loading