@@ -946,6 +946,7 @@ def test_role_hierachy_create_permissions(mongo_app_with_permissions):
946946 # Cleanup
947947 mongo .client_permissions .delete_one ({"client_id" : "test_manager" })
948948
949+
949950def test_refresh_access_token (mongo_app_with_permissions ):
950951 """Test refreshing an access token with a valid refresh token."""
951952 app , _ , client_id , client_key , max_priority = mongo_app_with_permissions
@@ -1232,26 +1233,27 @@ def test_refresh_token_last_accessed_update(mongo_app_with_permissions):
12321233
12331234 assert last_accessed_after > last_accessed_before
12341235
1236+
12351237def test_retrieve_parent_permissions_valid (mongo_app ):
12361238 """Test retrieving auth permissions from valid parent job."""
12371239 from testflinger import database
1238-
1240+
12391241 app , mongo = mongo_app
12401242 parent_permissions = {
12411243 "client_id" : "test_client" ,
12421244 "max_priority" : {"queue1" : 100 },
12431245 "allowed_queues" : ["restricted_queue" ],
1244- "max_reservation_time" : {"queue1" : 7200 }
1246+ "max_reservation_time" : {"queue1" : 7200 },
12451247 }
1246-
1248+
12471249 # Insert parent job with permissions
12481250 parent_job = {
12491251 "job_id" : "parent-123" ,
12501252 "auth_permissions" : parent_permissions ,
1251- "job_data" : {"job_queue" : "queue1" }
1253+ "job_data" : {"job_queue" : "queue1" },
12521254 }
12531255 mongo .jobs .insert_one (parent_job )
1254-
1256+
12551257 # Test retrieval
12561258 retrieved_permissions = database .retrieve_parent_permissions ("parent-123" )
12571259 assert retrieved_permissions == parent_permissions
@@ -1260,16 +1262,13 @@ def test_retrieve_parent_permissions_valid(mongo_app):
12601262def test_retrieve_parent_permissions_no_permissions (mongo_app ):
12611263 """Test retrieving permissions from parent job with no auth_permissions."""
12621264 from testflinger import database
1263-
1265+
12641266 app , mongo = mongo_app
1265-
1267+
12661268 # Insert parent job without permissions
1267- parent_job = {
1268- "job_id" : "parent-456" ,
1269- "job_data" : {"job_queue" : "queue1" }
1270- }
1269+ parent_job = {"job_id" : "parent-456" , "job_data" : {"job_queue" : "queue1" }}
12711270 mongo .jobs .insert_one (parent_job )
1272-
1271+
12731272 # Should return empty dict, not error
12741273 retrieved_permissions = database .retrieve_parent_permissions ("parent-456" )
12751274 assert retrieved_permissions == {}
@@ -1278,42 +1277,40 @@ def test_retrieve_parent_permissions_no_permissions(mongo_app):
12781277def test_retrieve_parent_permissions_nonexistent (mongo_app ):
12791278 """Test retrieving permissions from non-existent parent job."""
12801279 from testflinger import database
1281-
1280+
12821281 app , mongo = mongo_app
1283-
1282+
12841283 # Should return empty dict, not error
1285- retrieved_permissions = database .retrieve_parent_permissions ("nonexistent-job" )
1284+ retrieved_permissions = database .retrieve_parent_permissions (
1285+ "nonexistent-job"
1286+ )
12861287 assert retrieved_permissions == {}
12871288
12881289
12891290def test_agent_jobs_endpoint_with_credentials (mongo_app_with_permissions ):
12901291 """Test agent endpoint submits child job with inherited credentials."""
12911292 app , mongo , client_id , client_key , _ = mongo_app_with_permissions
1292-
1293+
12931294 # Create parent job with permissions
1294- authenticate_output = app .post (
1295- "/v1/oauth2/token" ,
1296- headers = create_auth_header (client_id , client_key ),
1297- )
1298- token = authenticate_output .data .decode ("utf-8" )
1295+ token = get_access_token (app , client_id , client_key )
12991296 parent_job = {"job_queue" : "myqueue2" , "job_priority" : 200 }
13001297 parent_response = app .post (
13011298 "/v1/job" , json = parent_job , headers = {"Authorization" : token }
13021299 )
13031300 parent_job_id = parent_response .json .get ("job_id" )
1304-
1301+
13051302 # Submit child job via agent endpoint
13061303 child_job = {
1307- "job_queue" : "myqueue2" ,
1304+ "job_queue" : "myqueue2" ,
13081305 "job_priority" : 200 ,
1309- "parent_job_id" : parent_job_id
1306+ "parent_job_id" : parent_job_id ,
13101307 }
13111308 child_response = app .post ("/v1/agent/jobs" , json = child_job )
13121309 assert child_response .status_code == 200
1313-
1310+
13141311 child_job_id = child_response .json .get ("job_id" )
13151312 assert child_job_id is not None
1316-
1313+
13171314 # Verify child job inherited parent permissions
13181315 child_job_data = mongo .jobs .find_one ({"job_id" : child_job_id })
13191316 assert child_job_data ["parent_job_id" ] == parent_job_id
@@ -1323,7 +1320,7 @@ def test_agent_jobs_endpoint_with_credentials(mongo_app_with_permissions):
13231320def test_agent_jobs_endpoint_missing_parent_job_id (mongo_app ):
13241321 """Test agent endpoint rejects jobs without parent_job_id."""
13251322 app , _ = mongo_app
1326-
1323+
13271324 child_job = {"job_queue" : "myqueue" }
13281325 response = app .post ("/v1/agent/jobs" , json = child_job )
13291326 assert response .status_code == 422
@@ -1333,11 +1330,8 @@ def test_agent_jobs_endpoint_missing_parent_job_id(mongo_app):
13331330def test_agent_jobs_endpoint_invalid_parent_job_id (mongo_app ):
13341331 """Test agent endpoint rejects jobs with invalid parent_job_id."""
13351332 app , _ = mongo_app
1336-
1337- child_job = {
1338- "job_queue" : "myqueue" ,
1339- "parent_job_id" : "invalid-uuid"
1340- }
1333+
1334+ child_job = {"job_queue" : "myqueue" , "parent_job_id" : "invalid-uuid" }
13411335 response = app .post ("/v1/agent/jobs" , json = child_job )
13421336 assert response .status_code == 400
13431337 assert "Invalid parent_job_id" in response .get_json ()["message" ]
@@ -1346,20 +1340,17 @@ def test_agent_jobs_endpoint_invalid_parent_job_id(mongo_app):
13461340def test_agent_jobs_endpoint_no_parent_permissions (mongo_app ):
13471341 """Test agent endpoint works when parent has no permissions."""
13481342 app , mongo = mongo_app
1349-
1343+
13501344 # Create parent job without authentication (no permissions)
13511345 parent_job = {"job_queue" : "myqueue" }
13521346 parent_response = app .post ("/v1/job" , json = parent_job )
13531347 parent_job_id = parent_response .json .get ("job_id" )
1354-
1348+
13551349 # Submit child job via agent endpoint
1356- child_job = {
1357- "job_queue" : "myqueue" ,
1358- "parent_job_id" : parent_job_id
1359- }
1350+ child_job = {"job_queue" : "myqueue" , "parent_job_id" : parent_job_id }
13601351 child_response = app .post ("/v1/agent/jobs" , json = child_job )
13611352 assert child_response .status_code == 200
1362-
1353+
13631354 # Verify child job was created successfully
13641355 child_job_id = child_response .json .get ("job_id" )
13651356 child_job_data = mongo .jobs .find_one ({"job_id" : child_job_id })
0 commit comments