Update a testset with given id, update the testset in Postgres. Args: testset_id (str): id of the test set to be updated. csvdata (NewTestset): New data to replace the old testset. Returns: str: The id of the test set updated.
(
testset_id: str,
csvdata: NewTestset,
request: Request,
)
| 291 | |
| 292 | @router.put("/{testset_id}/", operation_id="update_testset") |
| 293 | async def update_testset( |
| 294 | testset_id: str, |
| 295 | csvdata: NewTestset, |
| 296 | request: Request, |
| 297 | ): |
| 298 | """ |
| 299 | Update a testset with given id, update the testset in Postgres. |
| 300 | |
| 301 | Args: |
| 302 | testset_id (str): id of the test set to be updated. |
| 303 | csvdata (NewTestset): New data to replace the old testset. |
| 304 | |
| 305 | Returns: |
| 306 | str: The id of the test set updated. |
| 307 | """ |
| 308 | |
| 309 | testset = await db_manager.fetch_testset_by_id(testset_id=testset_id) |
| 310 | if testset is None: |
| 311 | raise HTTPException(status_code=404, detail="testset not found") |
| 312 | |
| 313 | if is_ee(): |
| 314 | has_permission = await check_action_access( |
| 315 | user_uid=request.state.user_id, |
| 316 | project_id=str(testset.project_id), |
| 317 | permission=Permission.EDIT_TESTSET, |
| 318 | ) |
| 319 | if not has_permission: |
| 320 | error_msg = f"You do not have permission to perform this action. Please contact your organization admin." |
| 321 | log.error(error_msg) |
| 322 | return JSONResponse( |
| 323 | {"detail": error_msg}, |
| 324 | status_code=403, |
| 325 | ) |
| 326 | |
| 327 | _validate_testset_limits(csvdata.csvdata) |
| 328 | |
| 329 | testset_update = { |
| 330 | "name": csvdata.name, |
| 331 | "csvdata": csvdata.csvdata, |
| 332 | "updated_at": datetime.now(timezone.utc), |
| 333 | } |
| 334 | await db_manager.update_testset( |
| 335 | testset_id=str(testset.id), values_to_update=testset_update |
| 336 | ) |
| 337 | return { |
| 338 | "status": "success", |
| 339 | "message": "testset updated successfully", |
| 340 | "_id": testset_id, |
| 341 | } |
| 342 | |
| 343 | |
| 344 | @router.get("/", operation_id="get_testsets") |
nothing calls this directly
no test coverage detected