|
2 | 2 | Unit tests for get_graph_structure controller |
3 | 3 | """ |
4 | 4 | import pytest |
5 | | -from unittest.mock import AsyncMock, patch |
| 5 | +from unittest.mock import AsyncMock, patch, MagicMock |
6 | 6 | from beanie import PydanticObjectId |
7 | 7 | from datetime import datetime |
8 | 8 |
|
|
11 | 11 | from app.models.state_status_enum import StateStatusEnum |
12 | 12 |
|
13 | 13 |
|
| 14 | +def mock_state(id, status, run_id, node_name, namespace_name, identifier, graph_name, inputs, outputs, parents): |
| 15 | + state = MagicMock() |
| 16 | + state.id = id |
| 17 | + state.status = status |
| 18 | + state.run_id= run_id |
| 19 | + state.node_name = node_name |
| 20 | + state.namespace_name = namespace_name |
| 21 | + state.identifier = identifier |
| 22 | + state.graph_name = graph_name |
| 23 | + state.inputs = inputs |
| 24 | + state.outputs = outputs |
| 25 | + state.parents = parents |
| 26 | + return state |
| 27 | + |
| 28 | + |
14 | 29 | @pytest.fixture |
15 | 30 | def mock_states(): |
16 | 31 | """Create mock states for testing""" |
17 | 32 | state1_id = PydanticObjectId() |
18 | 33 | state2_id = PydanticObjectId() |
19 | 34 | state3_id = PydanticObjectId() |
20 | | - |
21 | | - return [ |
22 | | - State( |
23 | | - id=state1_id, |
24 | | - node_name="start_node", |
25 | | - namespace_name="test_namespace", |
26 | | - identifier="start_1", |
27 | | - graph_name="test_graph", |
28 | | - run_id="test_run_123", |
29 | | - status=StateStatusEnum.SUCCESS, |
30 | | - inputs={"input1": "value1"}, |
31 | | - outputs={"output1": "result1"}, |
32 | | - error=None, |
33 | | - parents={}, |
34 | | - created_at=datetime.now(), |
35 | | - updated_at=datetime.now() |
36 | | - ), |
37 | | - State( |
38 | | - id=state2_id, |
| 35 | + |
| 36 | + state1= mock_state( |
| 37 | + id=state1_id, |
| 38 | + status= StateStatusEnum.SUCCESS, |
| 39 | + node_name="start_node", |
| 40 | + run_id= "test-run-id", |
| 41 | + namespace_name="test_namespace", |
| 42 | + identifier="start_1", |
| 43 | + graph_name="test_graph", |
| 44 | + inputs={"input1": "value1"}, |
| 45 | + outputs={"output1"}, |
| 46 | + parents={}, |
| 47 | + ) |
| 48 | + |
| 49 | + state2= mock_state( |
| 50 | + id=state2_id, |
| 51 | + status= StateStatusEnum.SUCCESS, |
| 52 | + node_name="process_node", |
| 53 | + run_id= "test-run-id", |
| 54 | + namespace_name="test_namespace", |
| 55 | + identifier="process_1", |
| 56 | + graph_name="test_graph", |
| 57 | + inputs={"input2": "value2"}, |
| 58 | + outputs={"output2": "result2"}, |
| 59 | + parents={"start_1": state1_id} |
| 60 | + ) |
| 61 | + |
| 62 | + state3= mock_state( |
| 63 | + id=state3_id, |
| 64 | + status= StateStatusEnum.SUCCESS, |
39 | 65 | node_name="process_node", |
| 66 | + run_id= "test-run-id", |
40 | 67 | namespace_name="test_namespace", |
41 | 68 | identifier="process_1", |
42 | 69 | graph_name="test_graph", |
43 | | - run_id="test_run_123", |
44 | | - status=StateStatusEnum.SUCCESS, |
45 | 70 | inputs={"input2": "value2"}, |
46 | 71 | outputs={"output2": "result2"}, |
47 | | - error=None, |
48 | | - parents={"start_1": state1_id}, |
49 | | - created_at=datetime.now(), |
50 | | - updated_at=datetime.now() |
51 | | - ), |
52 | | - State( |
53 | | - id=state3_id, |
54 | | - node_name="end_node", |
55 | | - namespace_name="test_namespace", |
56 | | - identifier="end_1", |
57 | | - graph_name="test_graph", |
58 | | - run_id="test_run_123", |
59 | | - status=StateStatusEnum.SUCCESS, |
60 | | - inputs={"input3": "value3"}, |
61 | | - outputs={"output3": "result3"}, |
62 | | - error=None, |
63 | | - parents={"process_1": state2_id}, |
64 | | - created_at=datetime.now(), |
65 | | - updated_at=datetime.now() |
66 | | - ) |
67 | | - ] |
| 72 | + parents={"start_1": state1_id} |
| 73 | + ) |
| 74 | + |
| 75 | + return [state1,state2,state3] |
68 | 76 |
|
69 | 77 |
|
70 | 78 | @pytest.mark.asyncio |
|
0 commit comments