def if_applicable_release_or_deprecate( existing_transformation_revision: Optional[TransformationRevision], updated_transformation_revision: TransformationRevision, ) -> TransformationRevision: if existing_transformation_revision is not None: if ( existing_transformation_revision.state == State.DRAFT and updated_transformation_revision.state == State.RELEASED ): logger.info( "release transformation revision %s", existing_transformation_revision.id, ) updated_transformation_revision.release() # prevent overwriting content during releasing updated_transformation_revision.content = ( existing_transformation_revision.content ) if ( existing_transformation_revision.state == State.RELEASED and updated_transformation_revision.state == State.DISABLED ): logger.info( "deprecate transformation revision %s", existing_transformation_revision.id, ) updated_transformation_revision = TransformationRevision( **existing_transformation_revision.dict() ) updated_transformation_revision.deprecate() # prevent overwriting content during deprecating updated_transformation_revision.content = ( existing_transformation_revision.content ) return updated_transformation_revision
async def test_execute_latest_for_transformation_revision_works( async_test_client, clean_test_db_engine): patched_session = sessionmaker(clean_test_db_engine) with mock.patch( "hetdesrun.persistence.dbservice.nesting.Session", patched_session, ): with mock.patch( "hetdesrun.persistence.dbservice.revision.Session", patched_session, ): tr_component_1 = TransformationRevision(**tr_json_component_1) tr_component_1.content = update_code(tr_component_1) store_single_transformation_revision(tr_component_1) tr_component_1_new_revision = TransformationRevision( **tr_json_component_1_new_revision) tr_component_1_new_revision.content = update_code( tr_component_1_new_revision) tr_component_1_new_revision.release() store_single_transformation_revision(tr_component_1_new_revision) exec_latest_by_group_id_input = ExecLatestByGroupIdInput( revision_group_id=tr_component_1.revision_group_id, wiring=tr_component_1.test_wiring, job_id=UUID("1270547c-b224-461d-9387-e9d9d465bbe1"), ) async with async_test_client as ac: response = await ac.post( "/api/transformations/execute-latest", json=json.loads(exec_latest_by_group_id_input.json()), ) assert response.status_code == 200 resp_data = response.json() assert "output_types_by_output_name" in resp_data assert (resp_data["output_types_by_output_name"]["operator_output"] == "STRING") assert "job_id" in resp_data assert UUID(resp_data["job_id"]) == UUID( "1270547c-b224-461d-9387-e9d9d465bbe1")