2018-09-06 17:37:17 +03:00
|
|
|
from django.urls import reverse
|
2015-08-10 01:02:37 +03:00
|
|
|
|
2013-07-18 17:47:58 +04:00
|
|
|
|
2018-04-12 20:06:53 +03:00
|
|
|
def test_pending_job_available(test_repository, pending_jobs_stored, client):
|
2020-04-21 17:35:59 +03:00
|
|
|
resp = client.get(reverse("jobs-list", kwargs={"project": test_repository.name}))
|
2018-04-12 20:06:53 +03:00
|
|
|
assert resp.status_code == 200
|
|
|
|
jobs = resp.json()
|
2013-07-18 17:47:58 +04:00
|
|
|
|
2015-02-15 17:52:31 +03:00
|
|
|
assert len(jobs["results"]) == 1
|
2013-07-18 17:47:58 +04:00
|
|
|
|
2015-01-12 20:23:28 +03:00
|
|
|
assert jobs["results"][0]["state"] == "pending"
|
2013-07-18 17:47:58 +04:00
|
|
|
|
|
|
|
|
2018-04-12 20:06:53 +03:00
|
|
|
def test_running_job_available(test_repository, running_jobs_stored, client):
|
2020-04-21 17:35:59 +03:00
|
|
|
resp = client.get(reverse("jobs-list", kwargs={"project": test_repository.name}))
|
2018-04-12 20:06:53 +03:00
|
|
|
assert resp.status_code == 200
|
|
|
|
jobs = resp.json()
|
2013-07-18 17:47:58 +04:00
|
|
|
|
2015-01-12 20:23:28 +03:00
|
|
|
assert len(jobs["results"]) == 1
|
2013-07-18 17:47:58 +04:00
|
|
|
|
2015-01-12 20:23:28 +03:00
|
|
|
assert jobs["results"][0]["state"] == "running"
|
2013-07-18 17:47:58 +04:00
|
|
|
|
|
|
|
|
2018-04-12 20:06:53 +03:00
|
|
|
def test_completed_job_available(test_repository, completed_jobs_stored, client):
|
2020-04-21 17:35:59 +03:00
|
|
|
resp = client.get(reverse("jobs-list", kwargs={"project": test_repository.name}))
|
2018-04-12 20:06:53 +03:00
|
|
|
assert resp.status_code == 200
|
|
|
|
jobs = resp.json()
|
2013-07-18 17:47:58 +04:00
|
|
|
|
2015-01-12 20:23:28 +03:00
|
|
|
assert len(jobs["results"]) == 1
|
|
|
|
assert jobs["results"][0]["state"] == "completed"
|
2013-07-23 20:39:47 +04:00
|
|
|
|
|
|
|
|
2020-04-21 17:35:59 +03:00
|
|
|
def test_pending_stored_to_running_loaded(
|
|
|
|
test_repository, pending_jobs_stored, running_jobs_stored, client
|
|
|
|
):
|
2013-07-23 20:39:47 +04:00
|
|
|
"""
|
|
|
|
tests a job transition from pending to running
|
2015-07-22 13:23:20 +03:00
|
|
|
given a loaded pending job, if I store and load the same job with status running,
|
2013-07-23 20:39:47 +04:00
|
|
|
the latter is shown in the jobs endpoint
|
|
|
|
"""
|
2020-04-21 17:35:59 +03:00
|
|
|
resp = client.get(reverse("jobs-list", kwargs={"project": test_repository.name}))
|
2018-04-12 20:06:53 +03:00
|
|
|
assert resp.status_code == 200
|
|
|
|
jobs = resp.json()
|
2013-07-23 20:39:47 +04:00
|
|
|
|
2015-01-12 20:23:28 +03:00
|
|
|
assert len(jobs["results"]) == 1
|
|
|
|
assert jobs["results"][0]["state"] == "running"
|
2013-09-18 17:55:39 +04:00
|
|
|
|
|
|
|
|
2020-04-21 17:35:59 +03:00
|
|
|
def test_finished_job_to_running(
|
|
|
|
test_repository, completed_jobs_stored, running_jobs_stored, client
|
|
|
|
):
|
2013-09-18 17:55:39 +04:00
|
|
|
"""
|
|
|
|
tests that a job finished cannot change state
|
|
|
|
"""
|
2020-04-21 17:35:59 +03:00
|
|
|
resp = client.get(reverse("jobs-list", kwargs={"project": test_repository.name}))
|
2018-04-12 20:06:53 +03:00
|
|
|
assert resp.status_code == 200
|
|
|
|
jobs = resp.json()
|
2013-09-18 17:55:39 +04:00
|
|
|
|
2015-01-12 20:23:28 +03:00
|
|
|
assert len(jobs["results"]) == 1
|
|
|
|
assert jobs["results"][0]["state"] == "completed"
|
2013-09-18 17:55:39 +04:00
|
|
|
|
|
|
|
|
2020-04-21 17:35:59 +03:00
|
|
|
def test_running_job_to_pending(test_repository, running_jobs_stored, pending_jobs_stored, client):
|
2013-09-18 17:55:39 +04:00
|
|
|
"""
|
|
|
|
tests that a job transition from pending to running
|
|
|
|
cannot happen
|
|
|
|
"""
|
2020-04-21 17:35:59 +03:00
|
|
|
resp = client.get(reverse("jobs-list", kwargs={"project": test_repository.name}))
|
2018-04-12 20:06:53 +03:00
|
|
|
assert resp.status_code == 200
|
|
|
|
jobs = resp.json()
|
2013-09-18 17:55:39 +04:00
|
|
|
|
2015-01-12 20:23:28 +03:00
|
|
|
assert len(jobs["results"]) == 1
|
|
|
|
assert jobs["results"][0]["state"] == "running"
|