Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rquidute committed Jan 11, 2024
1 parent 0023bd3 commit 3cdc620
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
26 changes: 13 additions & 13 deletions app/api/api_v1/endpoints/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def create_project(
Returns:
Project: newly created project record
"""
# Validade dut config informed arguments
# Validate dut config properties
__validate_dut_config(request=request)

return crud.project.create(db=db, obj_in=project_in)
Expand All @@ -88,23 +88,23 @@ def default_config() -> schemas.TestEnvironmentConfig:


def __validate_dut_config(request: Request) -> None:
valid_properties = [
"discriminator",
"setup_code",
"pairing_mode",
"chip_timeout",
"chip_use_paa_certs",
]

if "config" in request._json and "dut_config" in request._json["config"]:
dut_config = request._json["config"]["dut_config"]

valid_fields = [
"discriminator",
"setup_code",
"pairing_mode",
"chip_timeout",
"chip_use_paa_certs",
]

for field, _ in dut_config.items():
if field not in valid_fields:
if field not in valid_properties:
raise HTTPException(
status_code=HTTPStatus.UNPROCESSABLE_ENTITY,
detail="Dut config has invalid configuration informed."
f" The valid configuration are: {valid_fields}",
detail="Dut config section has invalid property informed."
f" The valid properties are: {valid_properties}",
)


Expand All @@ -128,7 +128,7 @@ def update_project(
Returns:
Project: updated project record
"""
# Validade dut config informed arguments
# Validate dut config properties
__validate_dut_config(request=request)

return crud.project.update(db=db, db_obj=__project(db=db, id=id), obj_in=project_in)
Expand Down
4 changes: 2 additions & 2 deletions app/tests/api/api_v1/test_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def test_create_project_invalid_dut_config(client: TestClient) -> None:
response=response,
expected_status_code=HTTPStatus.UNPROCESSABLE_ENTITY,
expected_content={
"detail": "Dut config has invalid configuration informed. The valid configuration are: ['discriminator', 'setup_code', 'pairing_mode', 'chip_timeout', 'chip_use_paa_certs']"
"detail": "Dut config section has invalid property informed. The valid properties are: ['discriminator', 'setup_code', 'pairing_mode', 'chip_timeout', 'chip_use_paa_certs']"
},
expected_keys=["detail"],
)
Expand Down Expand Up @@ -210,7 +210,7 @@ def test_update_project_invalid_dut_config(client: TestClient, db: Session) -> N
response=response,
expected_status_code=HTTPStatus.UNPROCESSABLE_ENTITY,
expected_content={
"detail": "Dut config has invalid configuration informed. The valid configuration are: ['discriminator', 'setup_code', 'pairing_mode', 'chip_timeout', 'chip_use_paa_certs']"
"detail": "Dut config section has invalid property informed. The valid properties are: ['discriminator', 'setup_code', 'pairing_mode', 'chip_timeout', 'chip_use_paa_certs']"
},
expected_keys=["detail"],
)
Expand Down

0 comments on commit 3cdc620

Please sign in to comment.