Implement an option to choose a job type on relaunch (issue #14177) (#15249)

Allows changing the job type (run, check) when relaunching
a job by adding a "job_type" to the relaunch POST payload
This commit is contained in:
Sasa Jovicic
2025-03-12 18:27:05 +01:00
committed by GitHub
parent 0f0f5aa289
commit 6f7d5ca8a3
3 changed files with 43 additions and 1 deletions

View File

@@ -210,6 +210,39 @@ def test_disallowed_http_update_methods(put, patch, post, inventory, project, ad
patch(url=reverse('api:job_detail', kwargs={'pk': job.pk}), data={}, user=admin_user, expect=405)
@pytest.mark.django_db
@pytest.mark.parametrize(
"job_type",
[
'run',
'check',
],
)
def test_job_relaunch_with_job_type(post, inventory, project, machine_credential, admin_user, job_type):
# Create a job template
jt = JobTemplate.objects.create(name='testjt', inventory=inventory, project=project)
# Set initial job type
init_job_type = 'check' if job_type == 'run' else 'run'
# Create a job instance
job = jt.create_unified_job(_eager_fields={'job_type': init_job_type})
# Perform the POST request
url = reverse('api:job_relaunch', kwargs={'pk': job.pk})
r = post(url=url, data={'job_type': job_type}, user=admin_user, expect=201)
# Assert that the response status code is 201 (Created)
assert r.status_code == 201
# Retrieve the newly created job from the response
new_job_id = r.data.get('id')
new_job = Job.objects.get(id=new_job_id)
# Assert that the new job has the correct job type
assert new_job.job_type == job_type
class TestControllerNode:
@pytest.fixture
def project_update(self, project):