mirror of
https://github.com/GSA/notifications-api.git
synced 2026-07-24 01:49:42 -04:00
fuzz
This commit is contained in:
@@ -3,6 +3,8 @@ import uuid
|
||||
import pytest
|
||||
from flask import current_app, json
|
||||
from freezegun import freeze_time
|
||||
from hypothesis import given
|
||||
from hypothesis import strategies as st
|
||||
|
||||
from app.dao.api_key_dao import save_model_api_key
|
||||
from app.dao.notifications_dao import dao_update_notification
|
||||
@@ -14,6 +16,41 @@ from tests import create_service_authorization_header
|
||||
from tests.app.db import create_api_key, create_notification
|
||||
|
||||
|
||||
@given(
|
||||
st.emails(),
|
||||
st.dictionaries(
|
||||
keys=st.text(min_size=1, max_size=20),
|
||||
values=st.text(min_size=0, max_size=100),
|
||||
max_size=5,
|
||||
),
|
||||
st.one_of(st.none(), st.text(min_size=0, max_size=50)),
|
||||
)
|
||||
def test_fuzz_send_email_notification(
|
||||
client,
|
||||
sample_service,
|
||||
sample_template,
|
||||
notify_db_session,
|
||||
email_address,
|
||||
personalisation,
|
||||
reference,
|
||||
):
|
||||
template_id = str(sample_template.id)
|
||||
auth_header = {
|
||||
"Authorization": "ApiKey-v1 {}".format(sample_service.api_keys[0].secret)
|
||||
}
|
||||
payload = {
|
||||
"template_id": template_id,
|
||||
"email_address": email_address,
|
||||
"personalisation": personalisation,
|
||||
"reference": reference,
|
||||
}
|
||||
response = client.post("/v2/notifications/email", json=payload, headers=auth_header)
|
||||
assert response.status_code in (
|
||||
201,
|
||||
400,
|
||||
), f"Unexpected status: {response.status_code}, body: {response.json}"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("type", (NotificationType.EMAIL, NotificationType.SMS))
|
||||
def test_get_notification_by_id(
|
||||
client, sample_notification, sample_email_notification, type, mocker
|
||||
|
||||
Reference in New Issue
Block a user