mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-24 00:06:16 -04:00
fuzz
This commit is contained in:
@@ -6,6 +6,8 @@ from zoneinfo import ZoneInfo
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from freezegun import freeze_time
|
from freezegun import freeze_time
|
||||||
|
from hypothesis import given
|
||||||
|
from hypothesis import strategies as st
|
||||||
|
|
||||||
import app.celery.tasks
|
import app.celery.tasks
|
||||||
from app.dao.templates_dao import dao_update_template
|
from app.dao.templates_dao import dao_update_template
|
||||||
@@ -70,6 +72,30 @@ def test_cancel_job(client, sample_scheduled_job):
|
|||||||
assert resp_json["data"]["job_status"] == JobStatus.CANCELLED
|
assert resp_json["data"]["job_status"] == JobStatus.CANCELLED
|
||||||
|
|
||||||
|
|
||||||
|
uuid_str_strategy = st.one_of(
|
||||||
|
st.just(str(uuid.uuid4())), st.text(min_size=1, max_size=36)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@given(service_id=uuid_str_strategy, job_id=uuid_str_strategy)
|
||||||
|
def test_fuzz_cancel_job(client, service_id, job_id):
|
||||||
|
path = f"/service/{service_id}/job/{job_id}/cancel"
|
||||||
|
auth_header = create_admin_authorization_header()
|
||||||
|
response = client.post(path, headers=[auth_header])
|
||||||
|
status = response.status_code
|
||||||
|
assert status in (
|
||||||
|
200,
|
||||||
|
400,
|
||||||
|
401,
|
||||||
|
403,
|
||||||
|
404,
|
||||||
|
), f"Unexpected status: {status} for path: {path}"
|
||||||
|
if status == 200:
|
||||||
|
resp_json = json.loads(response.get_data(as_text=True))
|
||||||
|
assert resp_json["data"]["id"] == job_id
|
||||||
|
assert resp_json["data"]["job_status"] == JobStatus.CANCELLED
|
||||||
|
|
||||||
|
|
||||||
def test_cant_cancel_normal_job(client, sample_job, mocker):
|
def test_cant_cancel_normal_job(client, sample_job, mocker):
|
||||||
job_id = str(sample_job.id)
|
job_id = str(sample_job.id)
|
||||||
service_id = sample_job.service.id
|
service_id = sample_job.service.id
|
||||||
|
|||||||
Reference in New Issue
Block a user