From 424e8c0b7a1ad4aa9820fd13b1e3fcbec033e56e Mon Sep 17 00:00:00 2001 From: Tom Ward Date: Wed, 25 Sep 2024 17:28:09 +0100 Subject: [PATCH] WIP test the get_jobs function --- tests/cli/test_kill_job.py | 46 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/tests/cli/test_kill_job.py b/tests/cli/test_kill_job.py index c5091cdf..7fba2366 100644 --- a/tests/cli/test_kill_job.py +++ b/tests/cli/test_kill_job.py @@ -9,6 +9,52 @@ from tests.factories import job_factory +def test_get_jobs_partial_id(db, monkeypatch): + # make a fake job + job = job_factory(state=State.RUNNING, status_code=StatusCode.EXECUTING) + + # take the first four characters to make a partial id + partial_job_id = job.id[:4] + partial_job_ids = [partial_job_id] + + monkeypatch.setattr("builtins.input", lambda _: "") + + # search for jobs with our partial id + output_job_ids = kill_job.get_jobs(partial_job_ids) + + assert output_job_ids[0].id == job.id + + +def test_get_jobs_partial_id_quit(db, monkeypatch): + # make a fake job + job = job_factory(state=State.RUNNING, status_code=StatusCode.EXECUTING) + + # take the first four characters to make a partial id + partial_job_id = job.id[:4] + partial_job_ids = [partial_job_id] + + monkeypatch.setattr("builtins.input", lambda _: "") + + # search for jobs with our partial id + output_job_ids = kill_job.get_jobs(partial_job_ids) + + assert False + + +def test_get_jobs_full_id(db): + # make a fake job + job = job_factory(state=State.RUNNING, status_code=StatusCode.EXECUTING) + + # this "partial id" is secretly a full id!! + full_job_id = job.id + full_job_ids = [full_job_id] + + # search for jobs with our partial id + output_job_ids = kill_job.get_jobs(full_job_ids) + + assert output_job_ids[0].id == job.id + + @pytest.mark.parametrize("cleanup", [False, True]) def test_kill_job(cleanup, tmp_work_dir, db, monkeypatch): job = job_factory(state=State.RUNNING, status_code=StatusCode.EXECUTING)