add another test

This commit is contained in:
Kenneth Kehl
2025-09-11 11:04:02 -07:00
parent 531e9ad7ba
commit e7fd571871
3 changed files with 31 additions and 2 deletions

View File

@@ -6,6 +6,8 @@ from datetime import datetime, timedelta
import pytest
from freezegun import freeze_time
from hypothesis import given
from hypothesis import strategies as st
from sqlalchemy import select
from app import db
@@ -297,6 +299,33 @@ def test_should_be_error_if_service_does_not_exist_on_update(client, fake_uuid):
assert json_resp["message"] == "No result found"
@given(
fuzzed_service_id=st.uuids(),
fuzzed_template_id=st.uuids(),
fuzzed_template_name=st.text(min_size=1, max_size=100),
)
def test_fuzz_should_be_error_if_service_does_not_exist_on_update(
client, fuzzed_service_id, fuzzed_template_id, fuzzed_template_name
):
"""
Hypothesis-based fuzz test to ensure that when updating a template
for a non-existent service, the API returns a 404 with the correct error message
"""
data = {"name": fuzzed_template_name}
data = json.dumps(data)
auth_header = create_admin_authorization_header()
response = client.post(
f"/service/{fuzzed_service_id}/tempalte/{fuzzed_template_id}",
headers=[("Content-Type", "application/json"), auth_header],
data=data,
)
json_resp = json.loads(response.get_data(as_text=True))
assert response.status_code == 404
assert json_resp["result"] == "error"
assert json_resp["message"] == "No result found"
@pytest.mark.parametrize("template_type", [TemplateType.EMAIL])
def test_must_have_a_subject_on_an_email_template(
client, sample_user, sample_service, template_type