@@ -60,12 +60,11 @@ async def test_get_job_dependencies_isolated_job(
6060
6161async def test_get_job_dependencies_unauthorized (
6262 test_client : AsyncClient ,
63- job_dependency_chain : tuple [ tuple [ Job , Job , Job ], ...] ,
63+ job : Job ,
6464):
65- (_ , job_middle , _ ) = job_dependency_chain [1 ]
6665 response = await test_client .get (
6766 "v1/jobs/dependencies" ,
68- params = {"start_node_id" : job_middle .id },
67+ params = {"start_node_id" : job .id },
6968 )
7069 assert response .status_code == HTTPStatus .UNAUTHORIZED , response .json ()
7170 assert response .json () == {
@@ -77,57 +76,54 @@ async def test_get_job_dependencies_unauthorized(
7776 }
7877
7978
80- async def test_get_job_dependencies_default_request (
79+ async def test_get_job_dependencies_with_direction_both (
8180 test_client : AsyncClient ,
8281 job_dependency_chain : tuple [tuple [Job , Job , Job ], ...],
8382 async_session : AsyncSession ,
8483 mocked_user : MockedUser ,
8584):
8685 (
87- (source_root , job_root , target_root ),
88- (source_middle , job_middle , target_middle ),
89- (source_leaf , job_leaf , target_leaf ),
86+ (_ , dag2 , _ ),
87+ (task1 , task2 , task3 ),
88+ (_ , spark2 , _ ),
9089 ) = job_dependency_chain
91- all_jobs = await enrich_jobs (
90+ expected_nodes = await enrich_jobs (
9291 [
93- job_root ,
94- job_middle ,
95- job_leaf ,
96- source_root ,
97- target_root ,
98- source_middle ,
99- target_middle ,
100- source_leaf ,
101- target_leaf ,
92+ dag2 ,
93+ task1 ,
94+ task2 ,
95+ task3 ,
96+ spark2 ,
10297 ],
10398 async_session ,
10499 )
105100
106- response = await test_client .get (
107- "v1/jobs/dependencies" ,
108- headers = {"Authorization" : f"Bearer { mocked_user .access_token } " },
109- params = {"start_node_id" : job_middle .id },
110- )
111- assert response .status_code == HTTPStatus .OK , response .json ()
112- assert response .json () == {
113- "relations" : {
114- "parents" : jobs_ancestors_to_json ([job_root , job_middle , job_leaf ]),
115- "dependencies" : [
116- {"from" : {"kind" : "JOB" , "id" : str (from_id )}, "to" : {"kind" : "JOB" , "id" : str (to_id )}, "type" : type_ }
117- for from_id , to_id , type_ in sorted (
118- [
119- (source_root .id , job_root .id , "DIRECT_DEPENDENCY" ),
120- (job_root .id , target_root .id , "DIRECT_DEPENDENCY" ),
121- (source_middle .id , job_middle .id , "DIRECT_DEPENDENCY" ),
122- (job_middle .id , target_middle .id , "DIRECT_DEPENDENCY" ),
123- (source_leaf .id , job_leaf .id , "DIRECT_DEPENDENCY" ),
124- (job_leaf .id , target_leaf .id , "DIRECT_DEPENDENCY" ),
125- ]
126- )
127- ],
128- },
129- "nodes" : {"jobs" : jobs_to_json (all_jobs )},
130- }
101+ for start_node in [dag2 , task2 , spark2 ]:
102+ response = await test_client .get (
103+ "v1/jobs/dependencies" ,
104+ headers = {"Authorization" : f"Bearer { mocked_user .access_token } " },
105+ params = {"start_node_id" : start_node .id },
106+ )
107+ assert response .status_code == HTTPStatus .OK , response .json ()
108+ assert response .json () == {
109+ "relations" : {
110+ "parents" : jobs_ancestors_to_json ([task2 , spark2 ]),
111+ "dependencies" : [
112+ {
113+ "from" : {"kind" : "JOB" , "id" : str (from_id )},
114+ "to" : {"kind" : "JOB" , "id" : str (to_id )},
115+ "type" : type_ ,
116+ }
117+ for from_id , to_id , type_ in sorted (
118+ [
119+ (task1 .id , task2 .id , "DIRECT_DEPENDENCY" ),
120+ (task2 .id , task3 .id , "DIRECT_DEPENDENCY" ),
121+ ]
122+ )
123+ ],
124+ },
125+ "nodes" : {"jobs" : jobs_to_json (expected_nodes )},
126+ }
131127
132128
133129async def test_get_job_dependencies_with_direction_upstream (
@@ -136,34 +132,32 @@ async def test_get_job_dependencies_with_direction_upstream(
136132 async_session : AsyncSession ,
137133 mocked_user : MockedUser ,
138134):
139- (source_root , job_root , _ ), (source_middle , job_middle , _ ), (source_leaf , job_leaf , _ ) = job_dependency_chain
135+ (_ , dag2 , _ ), (task1 , task2 , _ ), (_ , spark2 , _ ) = job_dependency_chain
140136 expected_nodes = await enrich_jobs (
141- [job_root , job_middle , job_leaf , source_root , source_middle , source_leaf ],
137+ [task1 , dag2 , task2 , spark2 ],
142138 async_session ,
143139 )
144140
145- response = await test_client .get (
146- "v1/jobs/dependencies" ,
147- headers = {"Authorization" : f"Bearer { mocked_user .access_token } " },
148- params = {"start_node_id" : job_middle .id , "direction" : "UPSTREAM" },
149- )
150- assert response .status_code == HTTPStatus .OK , response .json ()
151- assert response .json () == {
152- "relations" : {
153- "parents" : jobs_ancestors_to_json ([job_root , job_middle , job_leaf ]),
154- "dependencies" : [
155- {"from" : {"kind" : "JOB" , "id" : str (from_id )}, "to" : {"kind" : "JOB" , "id" : str (to_id )}, "type" : type_ }
156- for from_id , to_id , type_ in sorted (
157- [
158- (source_root .id , job_root .id , "DIRECT_DEPENDENCY" ),
159- (source_middle .id , job_middle .id , "DIRECT_DEPENDENCY" ),
160- (source_leaf .id , job_leaf .id , "DIRECT_DEPENDENCY" ),
161- ]
162- )
163- ],
164- },
165- "nodes" : {"jobs" : jobs_to_json (expected_nodes )},
166- }
141+ for start_node in [dag2 , task2 , spark2 ]:
142+ response = await test_client .get (
143+ "v1/jobs/dependencies" ,
144+ headers = {"Authorization" : f"Bearer { mocked_user .access_token } " },
145+ params = {"start_node_id" : start_node .id , "direction" : "UPSTREAM" },
146+ )
147+ assert response .status_code == HTTPStatus .OK , response .json ()
148+ assert response .json () == {
149+ "relations" : {
150+ "parents" : jobs_ancestors_to_json ([task2 , spark2 ]),
151+ "dependencies" : [
152+ {
153+ "from" : {"kind" : "JOB" , "id" : str (task1 .id )},
154+ "to" : {"kind" : "JOB" , "id" : str (task2 .id )},
155+ "type" : "DIRECT_DEPENDENCY" ,
156+ },
157+ ],
158+ },
159+ "nodes" : {"jobs" : jobs_to_json (expected_nodes )},
160+ }
167161
168162
169163async def test_get_job_dependencies_with_direction_downstream (
@@ -172,31 +166,29 @@ async def test_get_job_dependencies_with_direction_downstream(
172166 async_session : AsyncSession ,
173167 mocked_user : MockedUser ,
174168):
175- (_ , job_root , target_root ), (_ , job_middle , target_middle ), (_ , job_leaf , target_leaf ) = job_dependency_chain
169+ (_ , dag2 , _ ), (_ , task2 , task3 ), (_ , spark2 , _ ) = job_dependency_chain
176170 expected_nodes = await enrich_jobs (
177- [job_root , job_middle , job_leaf , target_root , target_middle , target_leaf ],
171+ [dag2 , task2 , spark2 , task3 ],
178172 async_session ,
179173 )
180174
181- response = await test_client .get (
182- "v1/jobs/dependencies" ,
183- headers = {"Authorization" : f"Bearer { mocked_user .access_token } " },
184- params = {"start_node_id" : job_middle .id , "direction" : "DOWNSTREAM" },
185- )
186- assert response .status_code == HTTPStatus .OK , response .json ()
187- assert response .json () == {
188- "relations" : {
189- "parents" : jobs_ancestors_to_json ([job_root , job_middle , job_leaf ]),
190- "dependencies" : [
191- {"from" : {"kind" : "JOB" , "id" : str (from_id )}, "to" : {"kind" : "JOB" , "id" : str (to_id )}, "type" : type_ }
192- for from_id , to_id , type_ in sorted (
193- [
194- (job_root .id , target_root .id , "DIRECT_DEPENDENCY" ),
195- (job_middle .id , target_middle .id , "DIRECT_DEPENDENCY" ),
196- (job_leaf .id , target_leaf .id , "DIRECT_DEPENDENCY" ),
197- ]
198- )
199- ],
200- },
201- "nodes" : {"jobs" : jobs_to_json (expected_nodes )},
202- }
175+ for start_node in [dag2 , task2 , spark2 ]:
176+ response = await test_client .get (
177+ "v1/jobs/dependencies" ,
178+ headers = {"Authorization" : f"Bearer { mocked_user .access_token } " },
179+ params = {"start_node_id" : start_node .id , "direction" : "DOWNSTREAM" },
180+ )
181+ assert response .status_code == HTTPStatus .OK , response .json ()
182+ assert response .json () == {
183+ "relations" : {
184+ "parents" : jobs_ancestors_to_json ([task2 , spark2 ]),
185+ "dependencies" : [
186+ {
187+ "from" : {"kind" : "JOB" , "id" : str (task2 .id )},
188+ "to" : {"kind" : "JOB" , "id" : str (task3 .id )},
189+ "type" : "DIRECT_DEPENDENCY" ,
190+ },
191+ ],
192+ },
193+ "nodes" : {"jobs" : jobs_to_json (expected_nodes )},
194+ }
0 commit comments