14
14
15
15
from jobbergate_agent .jobbergate .schemas import JobScriptFile , PendingJobSubmission , SlurmJobData
16
16
from jobbergate_agent .jobbergate .submit import (
17
+ SubprocessAsUserHandler ,
17
18
fetch_pending_submissions ,
18
19
get_job_script_file ,
19
20
mark_as_rejected ,
22
23
retrieve_submission_file ,
23
24
submit_job_script ,
24
25
submit_pending_jobs ,
26
+ validate_submit_dir ,
25
27
write_submission_file ,
26
28
)
27
29
from jobbergate_agent .settings import SETTINGS
@@ -403,6 +405,52 @@ async def test_mark_as_rejected__raises_JobbergateApiError_if_the_response_is_no
403
405
assert update_route .called
404
406
405
407
408
+ class TestValidateSubmitDir :
409
+ """
410
+ Test the ``validate_submit_dir()`` function.
411
+ """
412
+
413
+ subprocess_handler = SubprocessAsUserHandler (username = getpass .getuser ())
414
+
415
+ def test_validate_submit_dir__success (self , tmp_path ):
416
+ """
417
+ Test that the function can successfully validate a submission directory.
418
+ """
419
+ submit_dir = tmp_path / "submit"
420
+ submit_dir .mkdir ()
421
+
422
+ validate_submit_dir (submit_dir , self .subprocess_handler )
423
+
424
+ def test_validate_submit_dir__raises_exception_if_not_absolute_path (self ):
425
+ """
426
+ Test that the function raises an exception if the submission directory is not an absolute path.
427
+ """
428
+ submit_dir = Path ("./submit" )
429
+
430
+ with pytest .raises (ValueError , match = "must be an absolute path" ):
431
+ validate_submit_dir (submit_dir , self .subprocess_handler )
432
+
433
+ def test_validate_submit_dir__raises_exception_if_dir_is_not_writable (self , tmp_path ):
434
+ """
435
+ Test that the function raises an exception if the submission directory is not writable.
436
+ """
437
+ submit_dir = tmp_path / "submit"
438
+ submit_dir .mkdir ()
439
+ submit_dir .chmod (0o444 )
440
+
441
+ with pytest .raises (ValueError , match = "not writable by the user" ):
442
+ validate_submit_dir (submit_dir , self .subprocess_handler )
443
+
444
+ def test_validate_submit_dir__raises_exception_if_dir_does_not_exist (self , tmp_path ):
445
+ """
446
+ Test that the function raises an exception if the submission directory does not exist.
447
+ """
448
+ submit_dir = tmp_path / "submit"
449
+
450
+ with pytest .raises (ValueError , match = "Execution directory does not exist" ):
451
+ validate_submit_dir (submit_dir , self .subprocess_handler )
452
+
453
+
406
454
@pytest .mark .asyncio
407
455
@pytest .mark .usefixtures ("mock_access_token" )
408
456
@pytest .mark .parametrize ("job_submissions_name" , ["dummy-job-submission" , "really-long-job-submission-name" * 10 ])
@@ -553,12 +601,12 @@ async def test_submit_job_script__raises_exception_if_execution_dir_does_not_exi
553
601
mocked_sbatch = mock .MagicMock ()
554
602
mocker .patch ("jobbergate_agent.jobbergate.submit.SubmissionHandler" , return_value = mocked_sbatch )
555
603
556
- with pytest .raises (JobSubmissionError , match = "The execution directory must exist and be an absolute path " ):
604
+ with pytest .raises (JobSubmissionError , match = "Execution directory does not exist or is not writable by the user " ):
557
605
await submit_job_script (pending_job_submission , user_mapper )
558
606
559
607
mock_mark_as_rejected .assert_called_once_with (
560
608
dummy_pending_job_submission_data ["id" ],
561
- RegexArgMatcher (".*The execution directory must exist and be an absolute path .*" ),
609
+ RegexArgMatcher (".*Execution directory does not exist or is not writable by the user .*" ),
562
610
)
563
611
564
612
@@ -577,12 +625,12 @@ async def test_submit_job_script__raises_exception_if_execution_dir_is_relative(
577
625
mocked_sbatch = mock .MagicMock ()
578
626
mocker .patch ("jobbergate_agent.jobbergate.submit.SubmissionHandler" , return_value = mocked_sbatch )
579
627
580
- with pytest .raises (JobSubmissionError , match = "The execution directory must exist and be an absolute path" ):
628
+ with pytest .raises (JobSubmissionError , match = "Execution directory must be an absolute path" ):
581
629
await submit_job_script (pending_job_submission , user_mapper )
582
630
583
631
mock_mark_as_rejected .assert_called_once_with (
584
632
dummy_pending_job_submission_data ["id" ],
585
- RegexArgMatcher (".*The execution directory must exist and be an absolute path.*" ),
633
+ RegexArgMatcher (".*Execution directory must be an absolute path.*" ),
586
634
)
587
635
588
636
0 commit comments