Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
163 commits
Select commit Hold shift + click to select a range
d0238f3
Updated SDK SHA - revert
rquidute Oct 22, 2024
25f7581
Changed SDK_DOCKER_TAG to f2e5de7_latest
rquidute Oct 25, 2024
2caab2e
Make all TH dependencies not static (#164)
rquidute Oct 31, 2024
55afab5
[FIX] Reverting the OTBR Start Script (#150)
antonio-amjr Sep 27, 2024
fddd789
Do not error while parsing SDK python tests (#141)
hiltonlima Oct 23, 2024
851ad45
Add TC-IDM-10.5 test case to mandatory suite (#153)
rquidute Oct 23, 2024
018d273
Check user prompt answer FAILED for DUT commissioning (#155)
rquidute Oct 23, 2024
6ebfcf8
Handle Skip test fir old script python test cases (#154)
rquidute Oct 23, 2024
151057f
[FIX] Intermittent Tests Start Error With No Information (#157)
antonio-amjr Oct 23, 2024
13c7911
Update python_testing references after SDK refactoring (#162)
rquidute Oct 31, 2024
c6f8a12
Revert "[FIX] Intermittent Tests Start Error With No Information (#15…
hiltonlima Nov 7, 2024
85887ab
01 - Isolate SDK docker pull script (#142)
hiltonlima Nov 7, 2024
b8df5fe
02 - Script to parser SDK python tests (#144)
hiltonlima Nov 11, 2024
9d79b81
Implemented changes for custom python test (#167)
rquidute Nov 14, 2024
77def30
Update update-sample-app script to copy apps from new origin (#148)
rquidute Nov 14, 2024
5b50541
Fix suite names for custom python tests (#168)
rquidute Nov 19, 2024
90531ab
Fix move update-pull-sdk-docker-image script content to update-sample…
rquidute Nov 19, 2024
73a13e9
Fixed some python tests not listed (#172)
rquidute Dec 2, 2024
66d218c
[Feature] Implement support to export project config (#171)
rquidute Dec 2, 2024
a2a87e5
[FIX] Added support to negated PICS (#170)
rquidute Dec 4, 2024
0bb4f89
Merge branch 'v2.11+fall2024' into spring2025
rquidute Dec 12, 2024
6ca0fb5
Fixes after merge
rquidute Dec 17, 2024
3574d8e
Remove unused file (#175)
rquidute Dec 17, 2024
dcc8436
Fix ci issues v 2 12 (#176)
rquidute Dec 23, 2024
f242fc4
Add support for configuring terms and conditions in device commission…
swan-amazon Dec 23, 2024
20db0c0
chore: upgrade Node.js from v18.x to v20.x (#177)
swan-amazon Dec 30, 2024
188a646
[Feature] DO NOT require commissioning every test (#178)
rquidute Jan 6, 2025
f00f21c
Add logs for project config (#179)
rquidute Jan 9, 2025
a7c0075
Implement rename test run execution name (#180)
rquidute Jan 13, 2025
5fe46f6
Fix the checking for storage-path (#183)
rquidute Jan 15, 2025
8bb766d
Revert code changes related to SDK path refactoring (#186)
rquidute Jan 23, 2025
dd260d4
Refatoring prompts for recommissioning (#187)
rquidute Jan 27, 2025
07cba4b
Revert "Utilities stress stability (#146)" (#188)
antonio-amjr Jan 30, 2025
4d562c4
Remove commissioning information when running YAML scripts (#189)
rquidute Jan 31, 2025
e9e9806
Fix CONTAINER_TH_CLIENT_EXEC path (#191)
rquidute Feb 11, 2025
68749f7
Updated SDK SHA and Python Tests JSON (#192)
rquidute Feb 11, 2025
50121ce
Removed unused count field at test_case_metadata (#193)
rquidute Feb 12, 2025
7b06ddb
Add apps folder when copying apps from container to host
rquidute Feb 12, 2025
41b4745
Version v2.12-beta2+spring2025
rquidute Feb 12, 2025
39e5259
Version v2.12-beta3+spring2025
rquidute Feb 13, 2025
443e366
Add apps folder when copying apps from container to host (#194)
rquidute Feb 12, 2025
38bd005
Version v2.12-beta2+spring2025
rquidute Feb 12, 2025
1bb595b
[FIX] Updating Performance Files (#182)
antonio-amjr Jan 14, 2025
aecd7fb
Fix starting backend without internet access. (#184)
antonio-amjr Jan 16, 2025
cc40487
Remove unused file (#175)
rquidute Dec 17, 2024
21c8031
[FIX] Updating Performance Files (#182)
antonio-amjr Jan 14, 2025
077eebb
Remove unused file (#175)
rquidute Dec 17, 2024
d8fc2c4
Fix ci issues v 2 12 (#176)
rquidute Dec 23, 2024
52bc40a
Add nfc-thread pairing mode (#185)
OlivierGre Jan 27, 2025
7cc2122
[Fix] Recommissioning Refactoring to V1.5 (#190)
antonio-amjr Jan 31, 2025
ebabe3a
Updating SDK SHA to 7d67dc904758bb68989596f401a843a31e81911d in config
antonio-amjr Feb 20, 2025
b791f5c
Updated SDK SHA
Feb 20, 2025
a8d2bb4
Redo code changes related to SDK path refactoring (#198)
rquidute Feb 20, 2025
55d65cc
Updated SDK SHA and update-sample-apps.sh
rquidute Feb 21, 2025
fb79ae3
Updated sdk sha
rquidute Feb 21, 2025
d47ebfc
Undo changes in update-sample-apps.sh
rquidute Feb 21, 2025
6becb5d
Utilities stress stability (#146)
gladystonfranca Nov 18, 2024
2bedfd3
Updated SDK SHA
rquidute Feb 21, 2025
f2c1a14
Update SDK SHA
rquidute Feb 21, 2025
84ddda3
New Json for beta1 summer2025 release
rquidute Feb 21, 2025
63b3115
Updating Beta 2 For Summer 2025 (#200)
antonio-amjr Feb 25, 2025
1e4c194
Updated SDK_SHA. ble-wifi and ble-thread fixes
rquidute Feb 27, 2025
3640848
Change to be able to use NFC Commissioning in YAML test. (#201)
OlivierGre Feb 28, 2025
6e74348
[FIX] Removing Performance Collection From PICS Validation (#202)
antonio-amjr Mar 10, 2025
3eac122
[FIX] Fix Custom YAML test execution (#205)
rquidute Mar 20, 2025
df2a67b
Copy mock_server from cert-bins to host (#206)
rquidute Mar 25, 2025
a53c6f8
Implement Project config changes due to platform certification suppor…
rquidute Mar 28, 2025
8255743
[Feature] Platform cert implementation - Updated applicable test case…
rquidute Apr 15, 2025
dd00e84
Use discriminator for nfc thread (#212)
rquidute Apr 23, 2025
9b92ac8
Updated SDK_SHA to c60643c9a44ff6dfcc4319588e6fdec544c4a3e2
rquidute Apr 29, 2025
1445df7
Updated .version_information file
rquidute Apr 29, 2025
7945a91
[FIX] Adding Timeout To Server Exit (#216)
antonio-amjr Apr 29, 2025
b0160e9
Updated SDK_SHA - added air-purifier app
rquidute Apr 30, 2025
c0529a2
updated version to v2.13-beta3.1+summer2025
rquidute Apr 30, 2025
d6d1fc2
Fix 1.5_in_progress missing folder (#217)
rquidute May 5, 2025
616dcc9
Added logs for applicable test cases (#218)
rquidute May 5, 2025
1a35598
Adding the missing parameter to avoid the python's posicional argumen…
antonio-amjr May 6, 2025
88704a7
Updating .version_information of backend
antonio-amjr May 6, 2025
0417d39
Copying credentials folder from SDK image
antonio-amjr May 6, 2025
de5f70f
Updating version information
antonio-amjr May 6, 2025
e5490de
Fixed some platform tests not being added to applicable test cases (#…
rquidute May 13, 2025
f6ea712
Fix platform-test.json read path
rquidute May 14, 2025
76a71ab
[Fix] Linter Error (#221)
antonio-amjr May 20, 2025
752947d
Move platform-test.json to collections folder (#223)
rquidute May 28, 2025
0d1139b
Merge V2.13 sve+summer2025 into v2.13-develop (#231)
rquidute Jul 1, 2025
17bc14d
[Camera] Update backend to allow python testing framework to invoke p…
chulspro Jul 4, 2025
de7d73d
Fixed stress test interaction TC_COMMISSIONING_1_0 test case (#239)
rquidute Jul 8, 2025
5f94874
[Camera] Handle video stream socket operations in SocketConnectionMan…
chulspro Jul 10, 2025
a1ea6b6
Added support to PICS for /test_run_executions/cli endpoint (#236)
rquidute Jul 11, 2025
e0ab920
Optimize sideload process (#237)
rquidute Jul 14, 2025
9a703ab
[Fix] - Fix import test harness client (#243)
rquidute Jul 15, 2025
e06f2a8
Changes for V2.14 beta1+fall2025 version (#244)
rquidute Jul 15, 2025
7232ff8
Updating with v2.14-beta1.1+winter2025 release (#247)
antonio-amjr Jul 23, 2025
03e5eb2
Updated unit test to not modify .version_information file (#253)
rquidute Aug 22, 2025
bede638
Added support to project_id in test_run_executions POST /cli (#252)
rquidute Aug 22, 2025
48e7b43
Fix POST testrun_executions/cli not using config when project id is i…
rquidute Aug 28, 2025
22c4aa5
Fixes raised by Gemini in PR#250 (#255)
rquidute Sep 1, 2025
fb994be
[FIX] Updated TH after SDK refactoring (#258)
rquidute Sep 8, 2025
323a280
Version v2.14-beta2+fall2025 (#259)
rquidute Sep 8, 2025
d91d879
[Camera] Push AV validation prompt support (#251)
chulspro Sep 9, 2025
224c811
[Camera] Add signaling endpoints for WebRTC (#256)
chulspro Sep 9, 2025
3ac4392
[Camera] Adds pop up for two way talk verification request (#257)
chulspro Sep 9, 2025
8798d5a
black
rquidute Sep 9, 2025
cd70e9d
Updated fetch_sdk_tests_and_runner script to install chipyaml wheel (…
rquidute Sep 10, 2025
7f55410
[Fix] Fix missing python script in TH UI (#261)
rquidute Sep 11, 2025
e820107
v2.14-beta2.1+fall2025 version (#262)
rquidute Sep 12, 2025
ddb4b4f
Restore msg argument in SDKPythonTestResultShowTwoWayTalkPrompt (#263)
chulspro Sep 15, 2025
8ffe5c2
[Enhancement] Dynamic generate python_test_info.json file (#264)
rquidute Sep 29, 2025
eb068b3
Removed python_tests_info.json file (#265)
rquidute Sep 30, 2025
4f2f12c
[Fix] Update filename pattern validation for python test files (#266)
rquidute Sep 30, 2025
31336ef
Updated argument handling in test_harness_client (#270)
rquidute Oct 10, 2025
a795cd7
Fixing sdk container arguments by always passing thread and wifi info…
antonio-amjr Oct 10, 2025
7d78df3
v2.14-beta3+fall2025 version
rquidute Oct 13, 2025
c74c666
Updated SDK version to 966e378dab819d3abd4a59b468dc61d80b8b4b41
rquidute Oct 13, 2025
6640998
Updated SDK SHA to f902839abf1de0d17956de34889b6ad997e2c5e4
rquidute Oct 13, 2025
2d3fbb6
Fix error handling in Python test list generation to prevent KeyError…
rquidute Oct 13, 2025
24f227f
Fix python script listing (#272)
rquidute Oct 14, 2025
ee07018
Updated SDK_SHA after some scripts fixes
rquidute Oct 17, 2025
f7922cb
Implement real-time log synchronization for Python test steps (#267)
rquidute Oct 20, 2025
8f808e1
Add sdk docker image sha info (#273)
rquidute Oct 21, 2025
99fb615
Disable Polkit in chip-cert-bins (#269)
OlivierGre Oct 21, 2025
6e9bba0
Feature/763 use argparse test harness client (#274)
rquidute Oct 21, 2025
f976155
Added commissioning logs (#275)
rquidute Oct 22, 2025
b902ab5
[FEATURE] Add equivalent shell command logs when using docker api (#276)
rquidute Oct 24, 2025
96fbd3d
[Fix] Moved Shared Constants To New File (#277)
antonio-amjr Oct 30, 2025
35c5a7b
[Feature] Improve Python Testing Initialization (#278)
antonio-amjr Nov 7, 2025
970623f
Get changes from v2.14-develop into v2.15-develop (#280)
rquidute Nov 14, 2025
6f60e85
Feature/785 make log synchronization configurable (#279)
rquidute Nov 14, 2025
8fa3fc5
Updating SDK SHA for the v2.15-beta1+winter2025 release (Matter 1.6 TE1)
antonio-amjr Nov 17, 2025
b4b12d5
[FIX] Custom Suite And Custom TC Naming (#282)
antonio-amjr Nov 19, 2025
541b9d5
Fixing Backend's API for the CLI Test Run Execution (#283)
antonio-amjr Dec 10, 2025
ca35cdc
Fix permission denied errors in update-paa-certs.sh by force recreati…
rquidute Dec 15, 2025
c568c48
[Feature] Adding chip-server information API (#284)
antonio-amjr Dec 16, 2025
d1e6d50
Add support to sort the test run execution list and retrieve all reco…
rquidute Dec 29, 2025
ccbbf58
[Feature] Updating CHIP Server Info Endpoint to Include Manual Pairin…
antonio-amjr Dec 30, 2025
f4c99ba
Skip load custom tests step if no custom tests were found (#288)
rquidute Jan 16, 2026
dc71fa3
[Feature] Adding Support to CLI's Double-Dash Extra Arguments Feature…
antonio-amjr Jan 19, 2026
bd9bed7
Implemented configuration for enabling/disabling container informatio…
rquidute Jan 19, 2026
1ccf08d
Fixes for Python tests being loaded twice during Test Harness startup…
rquidute Jan 23, 2026
1c9eb67
Updated backend version v2.15-beta2+spring2026 (#292)
rquidute Jan 26, 2026
8c0b447
Updated SDK SHA to 9b1078da4307f98d362a0b44625a94d649bc1e77 for v2.14…
rquidute Jan 29, 2026
f83efc9
Version v2.14.1-beta2+winter2026
rquidute Feb 1, 2026
0211885
[Feature] TH to support thread commissioning (#295)
rquidute Feb 5, 2026
0c866eb
Adding nfc-wifi to the backend rebased to V2.15-develop (#294)
ArnoldBraine Feb 19, 2026
c26daa5
Version v2.15-beta2.1+spring2026
rquidute Feb 19, 2026
c870463
Fixed imports in test_harness_client.py file (#297)
rquidute Feb 19, 2026
682931f
Updated all references from Thread to Thread_meshcop (#299)
rquidute Feb 20, 2026
0ae226e
[Fix] Argument Generation When Using NFC Commissioning (#298)
antonio-amjr Feb 20, 2026
06379b4
Fix the Python test script parser to correctly identify base test cla…
rquidute Feb 24, 2026
28fa53b
Version v2.15-beta2.2+spring2026
rquidute Feb 25, 2026
60f0142
Fix/888 include missing tests (#302)
rquidute Mar 3, 2026
3ab803b
Fix json-arg not working (#304)
rquidute Mar 30, 2026
1919605
Release Matter 1.6 SVE (v2.15-beta3+spring2026)
antonio-amjr Mar 30, 2026
deda8ea
Release Matter 1.6 SVE version 2 (v2.15-beta3.1+spring2026)
antonio-amjr Apr 3, 2026
174b668
[FIX] Updating Test Run Executions To Handle temporary PICS (#305)
antonio-amjr Apr 10, 2026
30adcd1
Fix custom sideloaded test scripts not appearing in the test list whe…
rquidute Apr 23, 2026
cafea0d
Remove commissioning prompt from no commissioning tests (#307)
rquidute Apr 24, 2026
64038f8
Make pcscd --disable-polkit started unconditionally (#309)
rquidute Apr 27, 2026
0bef2f9
Fix TC_DD_3_24 hang on user prompt timeout in _show_prompt_request (#…
rquidute Apr 28, 2026
cfc4cc7
Fix ImportError for CommissionDeviceTest in test_harness_client (#312)
oxesoft May 6, 2026
1794f7f
Annotate grouped log download for api generation (#313)
greens May 15, 2026
ba754d2
v2.15+spring2026 version (#315)
rquidute May 20, 2026
2ac562d
Fix ModuleNotFoundError - matter.testing.CommissioningPreTest (#316)
rquidute May 21, 2026
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
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ htmlcov
__pycache__
app.egg-info
logs
admin_storage.json
/docker-stack.yml
.DS_Store
app/chip-tool/chip-tool
Expand All @@ -13,4 +14,7 @@ SerialTests.lock
test_db_creation.lock
.sha_information
test_collections/matter/sdk_tests/sdk_checkout
performance-logs
performance-logs
output_logs/
test_collections/matter/sdk_tests/custom_python_tests_info.json
test_collections/matter/sdk_tests/python_tests_info.json
2 changes: 1 addition & 1 deletion .version_information
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v2.11+fall2024
v2.15+spring2026
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ RUN curl -sSL https://install.python-poetry.org | python3 - && \
RUN curl -sSL https://get.docker.com/ | sh

# Install nodejs, npm and spell checker
RUN curl -sL https://deb.nodesource.com/setup_18.x | bash -
RUN curl -sL https://deb.nodesource.com/setup_20.x | bash -
RUN apt-get install -y nodejs
RUN npm install -g npm@latest
RUN npm install -g cspell@latest
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""add execution_pics to test_run_execution

Revision ID: a16c8c20cd36
Revises: e6153267b741
Create Date: 2026-04-08 17:41:21.198510

"""
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

from alembic import op

# revision identifiers, used by Alembic.
revision = "a16c8c20cd36"
down_revision = "e6153267b741"
branch_labels = None
depends_on = None


def upgrade():
# Add execution_pics column to testrunexecution table (optional JSON)
op.add_column(
"testrunexecution",
sa.Column(
"execution_pics", postgresql.JSON(astext_type=sa.Text()), nullable=True
),
)


def downgrade():
# Remove execution_pics column
op.drop_column("testrunexecution", "execution_pics")
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""add execution_config to test_run_execution

Revision ID: e6153267b741
Revises: 0a251edfd975
Create Date: 2026-01-15 17:36:00.000000

"""
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

from alembic import op

# revision identifiers, used by Alembic.
revision = "e6153267b741"
down_revision = "0a251edfd975"
branch_labels = None
depends_on = None


def upgrade():
# Add execution_config column to testrunexecution table (optional JSON)
op.add_column(
"testrunexecution",
sa.Column(
"execution_config", postgresql.JSON(astext_type=sa.Text()), nullable=True
),
)


def downgrade():
# Remove execution_config column
op.drop_column("testrunexecution", "execution_config")
170 changes: 151 additions & 19 deletions app/api/api_v1/endpoints/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
import json
import traceback
from http import HTTPStatus
from typing import List, Sequence, Union

from fastapi import APIRouter, Depends, File, HTTPException, Request, UploadFile
from fastapi.encoders import jsonable_encoder
from fastapi.responses import JSONResponse
from loguru import logger
from pydantic import ValidationError, parse_obj_as
from sqlalchemy.orm import Session
from sqlalchemy.orm.attributes import flag_modified

Expand All @@ -25,11 +31,16 @@
from app.default_environment_config import default_environment_config
from app.models.project import Project
from app.pics.pics_parser import PICSParser
from app.pics_applicable_test_cases import applicable_test_cases_list
from app.pics_applicable_test_cases import applicable_test_cases_set
from app.schemas.pics import PICSError
from app.schemas.project import Project as Proj
from app.schemas.test_environment_config import TestEnvironmentConfigError
from app.utils import TEST_ENVIRONMENT_CONFIG_NAME
from app.utils import (
DMP_TEST_SKIP_CONFIG_NODE,
DMP_TEST_SKIP_FILENAME,
TEST_ENVIRONMENT_CONFIG_NAME,
parse_dmp_file,
)

router = APIRouter()

Expand Down Expand Up @@ -222,32 +233,66 @@ def unarchive_project(
return crud.project.unarchive(db=db, db_obj=__project(db=db, id=id))


def __upload_pics(file: UploadFile, db: Session, project: Project) -> Project:
cluster = PICSParser.parse(file=file.file)

project.pics.clusters[cluster.name] = cluster

return __persist_update_not_mutable(db=db, project=project, field="pics")


def __persist_dmp_test_skip(file: UploadFile, db: Session, project: Project) -> Project:
try:
skip_test_list = parse_dmp_file(xml_file=file.file)
project.config[DMP_TEST_SKIP_CONFIG_NODE] = skip_test_list

return __persist_update_not_mutable(db=db, project=project, field="config")
except Exception:
logger.error(traceback.format_exc())
raise HTTPException(
status_code=HTTPStatus.UNPROCESSABLE_ENTITY,
detail=f"Not able to parse {file.filename} file",
)


@router.put("/{id}/upload_pics", response_model=schemas.Project)
def upload_pics(
async def upload_pics(
*,
db: Session = Depends(get_db),
file: UploadFile = File(...),
id: int,
) -> models.Project:
"""Upload PICS file of a project based on project identifier.
"""Upload PICS or dmp-test-skip.xml file of a project based on project identifier.

Args:
id (int): project id
file : the PICS file to upload
file : the PICS or dmp-test-skip.xml file to upload

Raises:
HTTPException: if no project exists for provided project id (or)
if the PICS file is invalid

Returns:
Project: project record that was updated with the PICS information
Project: project record that was updated with the PICS and dmp_test_skip
information.
"""
cluster = PICSParser.parse(file=file.file)

project = __project(db=db, id=id)
project.pics.clusters[cluster.name] = cluster

return __persist_pics_update(db=db, project=project)
try:
if file and file.filename and file.filename.startswith(DMP_TEST_SKIP_FILENAME):
return __persist_dmp_test_skip(file=file, db=db, project=project)
else:
return __upload_pics(file=file, db=db, project=project)
except PICSError as e:
raise HTTPException(
status_code=HTTPStatus.UNPROCESSABLE_ENTITY,
detail=str(e),
)
except Exception as e:
raise HTTPException(
status_code=HTTPStatus.UNPROCESSABLE_ENTITY,
detail=f"Not able to parse {file.filename} file: {str(e)}",
)


@router.delete("/{id}/pics_cluster_type", response_model=schemas.Project)
Expand Down Expand Up @@ -277,7 +322,7 @@ def remove_pics_cluster_type(
# delete the PICS cluster.
del project.pics.clusters[cluster_name]

return __persist_pics_update(db=db, project=project)
return __persist_update_not_mutable(db=db, project=project, field="pics")


@router.get(
Expand All @@ -303,7 +348,19 @@ def applicable_test_cases(

project_data = Proj.from_orm(project)

return applicable_test_cases_list(pics=project_data.pics)
try:
return applicable_test_cases_set(
pics=project_data.pics,
dmp_test_skip=project_data.config.get( # type: ignore
DMP_TEST_SKIP_CONFIG_NODE, []
),
)
except Exception as e:
logger.error(f"Error getting applicable test cases: {str(e)}")
raise HTTPException(
status_code=HTTPStatus.UNPROCESSABLE_ENTITY,
detail=f"Error getting applicable test cases: {str(e)}",
)


def __project(db: Session, id: int) -> Project:
Expand All @@ -315,16 +372,91 @@ def __project(db: Session, id: int) -> Project:
return project


def __persist_pics_update(db: Session, project: Project) -> Project:
"""Update Project PICS in DB.
def __persist_update_not_mutable(db: Session, project: Project, field: str) -> Project:
"""Update Project JSON fields in DB.

project.pics is stored in a JSON column mapped to PICS schema, this column is
not Mutable, so SQLAlchemy doesn't know when PICS changed.
Project contains JSON columns (like 'pics' and 'config') mapped to their respective
schemas.
These columns are not Mutable by default, so SQLAlchemy doesn't track changes
to their content.

Using `flag_modified` marks the property, so SQLAlchemy will update the field on
commit.
Using `flag_modified` explicitly marks the JSON property as changed, ensuring
SQLAlchemy will update the field on commit. This is necessary for any nested
modifications to JSON column data.
"""
flag_modified(project, "pics")

flag_modified(project, field)
db.commit()
db.refresh(project)
return project


@router.get("/{id}/export", response_model=schemas.ProjectCreate)
def export_project_config(
*,
db: Session = Depends(get_db),
id: int,
) -> JSONResponse:
"""
Exports the project config by id.

Args:
id (int): project id

Raises:
HTTPException: if no project exists for provided project id

Returns:
JSONResponse: json representation of the project with the informed project id
"""
# Retrieve project by project_id using schemas.ProjectCreate schema
project = schemas.ProjectCreate(**__project(db=db, id=id).__dict__)

options: dict = {"media_type": "application/json"}
filename = f"{project.name}-project-config.json"
options["headers"] = {"Content-Disposition": f'attachment; filename="{filename}"'}

return JSONResponse(
jsonable_encoder(project),
**options,
)


@router.post("/import", response_model=schemas.Project)
def importproject_config(
*,
db: Session = Depends(get_db),
import_file: UploadFile = File(...),
) -> models.Project:
"""
Imports the project config

Args:
import_file : The project config file to be imported

Raises:
ValidationError: if the imported project config contains invalid information

Returns:
Project: newly created project record
"""

file_content = import_file.file.read().decode("utf-8")
file_dict = json.loads(file_content)

try:
imported_project: schemas.ProjectCreate = parse_obj_as(
schemas.ProjectCreate, file_dict
)
except ValidationError as error:
raise HTTPException(
status_code=HTTPStatus.UNPROCESSABLE_ENTITY, detail=str(error)
)

try:
return crud.project.create(db=db, obj_in=imported_project)
except TestEnvironmentConfigError as e:
raise HTTPException(
status_code=HTTPStatus.UNPROCESSABLE_ENTITY,
detail=str(e),
)
Loading
Loading