mirror of
https://github.com/facefusion/facefusion.git
synced 2026-09-15 12:05:27 +02:00
first piece for /jobs endpoint part5
This commit is contained in:
+162
-6
@@ -129,7 +129,7 @@ def test_create_job(test_client : TestClient) -> None:
|
||||
|
||||
|
||||
def test_submit_jobs(test_client : TestClient) -> None:
|
||||
submit_jobs_response = test_client.put('/jobs/submit')
|
||||
submit_jobs_response = test_client.patch('/jobs?action=submit')
|
||||
|
||||
assert submit_jobs_response.status_code == 401
|
||||
|
||||
@@ -140,9 +140,18 @@ def test_submit_jobs(test_client : TestClient) -> None:
|
||||
create_session_body = create_session_response.json()
|
||||
access_token = create_session_body.get('access_token')
|
||||
|
||||
submit_jobs_response = test_client.patch('/jobs?action=invalid', headers =
|
||||
{
|
||||
'Authorization': 'Bearer ' + access_token
|
||||
})
|
||||
submit_jobs_body = submit_jobs_response.json()
|
||||
|
||||
assert submit_jobs_body.get('message') == 'invalid job action'
|
||||
assert submit_jobs_response.status_code == 400
|
||||
|
||||
create_job('job-test-submit-jobs')
|
||||
|
||||
submit_jobs_response = test_client.put('/jobs/submit', headers =
|
||||
submit_jobs_response = test_client.patch('/jobs?action=submit', headers =
|
||||
{
|
||||
'Authorization': 'Bearer ' + access_token
|
||||
})
|
||||
@@ -152,7 +161,7 @@ def test_submit_jobs(test_client : TestClient) -> None:
|
||||
assert submit_jobs_response.status_code == 400
|
||||
|
||||
with patch('facefusion.jobs.job_manager.submit_jobs', return_value = True):
|
||||
submit_jobs_response = test_client.put('/jobs/submit', headers =
|
||||
submit_jobs_response = test_client.patch('/jobs?action=submit', headers =
|
||||
{
|
||||
'Authorization': 'Bearer ' + access_token
|
||||
})
|
||||
@@ -163,7 +172,7 @@ def test_submit_jobs(test_client : TestClient) -> None:
|
||||
|
||||
|
||||
def test_submit_job(test_client : TestClient) -> None:
|
||||
submit_job_response = test_client.put('/jobs/job-test-submit-job/submit')
|
||||
submit_job_response = test_client.patch('/jobs/job-test-submit-job?action=submit')
|
||||
|
||||
assert submit_job_response.status_code == 401
|
||||
|
||||
@@ -174,9 +183,18 @@ def test_submit_job(test_client : TestClient) -> None:
|
||||
create_session_body = create_session_response.json()
|
||||
access_token = create_session_body.get('access_token')
|
||||
|
||||
submit_job_response = test_client.patch('/jobs/job-test-submit-job?action=invalid', headers =
|
||||
{
|
||||
'Authorization': 'Bearer ' + access_token
|
||||
})
|
||||
submit_job_body = submit_job_response.json()
|
||||
|
||||
assert submit_job_body.get('message') == 'invalid job action'
|
||||
assert submit_job_response.status_code == 400
|
||||
|
||||
create_job('job-test-submit-job')
|
||||
|
||||
submit_job_response = test_client.put('/jobs/job-test-submit-job/submit', headers =
|
||||
submit_job_response = test_client.patch('/jobs/job-test-submit-job?action=submit', headers =
|
||||
{
|
||||
'Authorization': 'Bearer ' + access_token
|
||||
})
|
||||
@@ -186,7 +204,7 @@ def test_submit_job(test_client : TestClient) -> None:
|
||||
assert submit_job_response.status_code == 400
|
||||
|
||||
with patch('facefusion.jobs.job_manager.submit_job', return_value = True):
|
||||
submit_job_response = test_client.put('/jobs/job-test-submit-job/submit', headers =
|
||||
submit_job_response = test_client.patch('/jobs/job-test-submit-job?action=submit', headers =
|
||||
{
|
||||
'Authorization': 'Bearer ' + access_token
|
||||
})
|
||||
@@ -196,6 +214,144 @@ def test_submit_job(test_client : TestClient) -> None:
|
||||
assert submit_job_response.status_code == 200
|
||||
|
||||
|
||||
def test_run_jobs(test_client : TestClient) -> None:
|
||||
run_jobs_response = test_client.patch('/jobs?action=run')
|
||||
|
||||
assert run_jobs_response.status_code == 401
|
||||
|
||||
create_session_response = test_client.post('/session', json =
|
||||
{
|
||||
'client_version': metadata.get('version')
|
||||
})
|
||||
create_session_body = create_session_response.json()
|
||||
access_token = create_session_body.get('access_token')
|
||||
|
||||
run_jobs_response = test_client.patch('/jobs?action=run', headers =
|
||||
{
|
||||
'Authorization': 'Bearer ' + access_token
|
||||
})
|
||||
run_jobs_body = run_jobs_response.json()
|
||||
|
||||
assert run_jobs_body.get('message') == 'jobs not run'
|
||||
assert run_jobs_response.status_code == 400
|
||||
|
||||
with patch('facefusion.jobs.job_manager.find_job_ids', return_value = [ 'job-test-run-jobs' ]):
|
||||
with patch('facefusion.jobs.job_runner.run_jobs', return_value = True) as run_jobs_mock:
|
||||
run_jobs_response = test_client.patch('/jobs?action=run', headers =
|
||||
{
|
||||
'Authorization': 'Bearer ' + access_token
|
||||
})
|
||||
run_jobs_body = run_jobs_response.json()
|
||||
|
||||
assert run_jobs_body.get('message') == 'ok'
|
||||
assert run_jobs_response.status_code == 202
|
||||
assert run_jobs_mock.called is True
|
||||
|
||||
|
||||
def test_run_job(test_client : TestClient) -> None:
|
||||
run_job_response = test_client.patch('/jobs/job-test-run-job?action=run')
|
||||
|
||||
assert run_job_response.status_code == 401
|
||||
|
||||
create_session_response = test_client.post('/session', json =
|
||||
{
|
||||
'client_version': metadata.get('version')
|
||||
})
|
||||
create_session_body = create_session_response.json()
|
||||
access_token = create_session_body.get('access_token')
|
||||
|
||||
create_job('job-test-run-job')
|
||||
|
||||
run_job_response = test_client.patch('/jobs/job-test-run-job?action=run', headers =
|
||||
{
|
||||
'Authorization': 'Bearer ' + access_token
|
||||
})
|
||||
run_job_body = run_job_response.json()
|
||||
|
||||
assert run_job_body.get('message') == 'job not run'
|
||||
assert run_job_response.status_code == 400
|
||||
|
||||
with patch('facefusion.jobs.job_manager.find_job_ids', return_value = [ 'job-test-run-job' ]):
|
||||
with patch('facefusion.jobs.job_runner.run_job', return_value = True) as run_job_mock:
|
||||
run_job_response = test_client.patch('/jobs/job-test-run-job?action=run', headers =
|
||||
{
|
||||
'Authorization': 'Bearer ' + access_token
|
||||
})
|
||||
run_job_body = run_job_response.json()
|
||||
|
||||
assert run_job_body.get('message') == 'ok'
|
||||
assert run_job_response.status_code == 202
|
||||
assert run_job_mock.called is True
|
||||
|
||||
|
||||
def test_retry_jobs(test_client : TestClient) -> None:
|
||||
retry_jobs_response = test_client.patch('/jobs?action=retry')
|
||||
|
||||
assert retry_jobs_response.status_code == 401
|
||||
|
||||
create_session_response = test_client.post('/session', json =
|
||||
{
|
||||
'client_version': metadata.get('version')
|
||||
})
|
||||
create_session_body = create_session_response.json()
|
||||
access_token = create_session_body.get('access_token')
|
||||
|
||||
retry_jobs_response = test_client.patch('/jobs?action=retry', headers =
|
||||
{
|
||||
'Authorization': 'Bearer ' + access_token
|
||||
})
|
||||
retry_jobs_body = retry_jobs_response.json()
|
||||
|
||||
assert retry_jobs_body.get('message') == 'jobs not retried'
|
||||
assert retry_jobs_response.status_code == 400
|
||||
|
||||
with patch('facefusion.jobs.job_manager.find_job_ids', return_value = [ 'job-test-retry-jobs' ]):
|
||||
with patch('facefusion.jobs.job_runner.retry_jobs', return_value = True) as retry_jobs_mock:
|
||||
retry_jobs_response = test_client.patch('/jobs?action=retry', headers =
|
||||
{
|
||||
'Authorization': 'Bearer ' + access_token
|
||||
})
|
||||
retry_jobs_body = retry_jobs_response.json()
|
||||
|
||||
assert retry_jobs_body.get('message') == 'ok'
|
||||
assert retry_jobs_response.status_code == 202
|
||||
assert retry_jobs_mock.called is True
|
||||
|
||||
|
||||
def test_retry_job(test_client : TestClient) -> None:
|
||||
retry_job_response = test_client.patch('/jobs/job-test-retry-job?action=retry')
|
||||
|
||||
assert retry_job_response.status_code == 401
|
||||
|
||||
create_session_response = test_client.post('/session', json =
|
||||
{
|
||||
'client_version': metadata.get('version')
|
||||
})
|
||||
create_session_body = create_session_response.json()
|
||||
access_token = create_session_body.get('access_token')
|
||||
|
||||
retry_job_response = test_client.patch('/jobs/job-test-retry-job?action=retry', headers =
|
||||
{
|
||||
'Authorization': 'Bearer ' + access_token
|
||||
})
|
||||
retry_job_body = retry_job_response.json()
|
||||
|
||||
assert retry_job_body.get('message') == 'job not retried'
|
||||
assert retry_job_response.status_code == 400
|
||||
|
||||
with patch('facefusion.jobs.job_manager.find_job_ids', return_value = [ 'job-test-retry-job' ]):
|
||||
with patch('facefusion.jobs.job_runner.retry_job', return_value = True) as retry_job_mock:
|
||||
retry_job_response = test_client.patch('/jobs/job-test-retry-job?action=retry', headers =
|
||||
{
|
||||
'Authorization': 'Bearer ' + access_token
|
||||
})
|
||||
retry_job_body = retry_job_response.json()
|
||||
|
||||
assert retry_job_body.get('message') == 'ok'
|
||||
assert retry_job_response.status_code == 202
|
||||
assert retry_job_mock.called is True
|
||||
|
||||
|
||||
def test_delete_jobs(test_client : TestClient) -> None:
|
||||
delete_jobs_response = test_client.delete('/jobs')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user