|
| 1 | +import pytest |
1 | 2 | from sqlalchemy import orm |
2 | 3 |
|
3 | 4 | from cloud_pipelines_backend import backend_types_sql as bts |
|
6 | 7 | ExecutionStatusSummary, |
7 | 8 | PipelineRunsApiService_Sql, |
8 | 9 | ) |
| 10 | +from cloud_pipelines_backend.errors import ItemNotFoundError |
9 | 11 |
|
10 | 12 |
|
11 | 13 | def _initialize_db_and_get_session_factory(): |
@@ -162,3 +164,68 @@ def test_list_with_execution_stats(self): |
162 | 164 | assert summary.total_nodes == 2 |
163 | 165 | assert summary.ended_nodes == 1 |
164 | 166 | assert summary.has_ended is False |
| 167 | + |
| 168 | + |
| 169 | +class TestPipelineRunServiceGet: |
| 170 | + def test_get_not_found(self): |
| 171 | + session_factory = _initialize_db_and_get_session_factory() |
| 172 | + service = PipelineRunsApiService_Sql() |
| 173 | + with session_factory() as session: |
| 174 | + with pytest.raises(ItemNotFoundError): |
| 175 | + service.get(session=session, id="nonexistent-id") |
| 176 | + |
| 177 | + def test_get_returns_pipeline_run(self): |
| 178 | + session_factory = _initialize_db_and_get_session_factory() |
| 179 | + service = PipelineRunsApiService_Sql() |
| 180 | + with session_factory() as session: |
| 181 | + root = _create_execution_node(session) |
| 182 | + root_id = root.id |
| 183 | + run = _create_pipeline_run(session, root, created_by="user1") |
| 184 | + run_id = run.id |
| 185 | + session.commit() |
| 186 | + |
| 187 | + with session_factory() as session: |
| 188 | + result = service.get(session=session, id=run_id) |
| 189 | + assert result.id == run_id |
| 190 | + assert result.root_execution_id == root_id |
| 191 | + assert result.created_by == "user1" |
| 192 | + assert result.execution_status_stats is None |
| 193 | + assert result.execution_summary is None |
| 194 | + |
| 195 | + def test_get_with_execution_stats(self): |
| 196 | + session_factory = _initialize_db_and_get_session_factory() |
| 197 | + service = PipelineRunsApiService_Sql() |
| 198 | + with session_factory() as session: |
| 199 | + root = _create_execution_node(session) |
| 200 | + root_id = root.id |
| 201 | + child1 = _create_execution_node( |
| 202 | + session, |
| 203 | + parent=root, |
| 204 | + status=bts.ContainerExecutionStatus.SUCCEEDED, |
| 205 | + ) |
| 206 | + child2 = _create_execution_node( |
| 207 | + session, |
| 208 | + parent=root, |
| 209 | + status=bts.ContainerExecutionStatus.RUNNING, |
| 210 | + ) |
| 211 | + _link_ancestor(session, child1, root) |
| 212 | + _link_ancestor(session, child2, root) |
| 213 | + run = _create_pipeline_run(session, root) |
| 214 | + run_id = run.id |
| 215 | + session.commit() |
| 216 | + |
| 217 | + with session_factory() as session: |
| 218 | + result = service.get( |
| 219 | + session=session, id=run_id, include_execution_stats=True |
| 220 | + ) |
| 221 | + assert result.id == run_id |
| 222 | + assert result.root_execution_id == root_id |
| 223 | + stats = result.execution_status_stats |
| 224 | + assert stats is not None |
| 225 | + assert stats["SUCCEEDED"] == 1 |
| 226 | + assert stats["RUNNING"] == 1 |
| 227 | + summary = result.execution_summary |
| 228 | + assert summary is not None |
| 229 | + assert summary.total_nodes == 2 |
| 230 | + assert summary.ended_nodes == 1 |
| 231 | + assert summary.has_ended is False |
0 commit comments