mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-23 15:56:45 -04:00
revert change in fixture scoping
This commit is contained in:
@@ -252,7 +252,7 @@ def _sample_service_full_permissions(notify_db_session):
|
|||||||
return service
|
return service
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="function")
|
||||||
def sample_template(sample_user):
|
def sample_template(sample_user):
|
||||||
service = create_service(
|
service = create_service(
|
||||||
service_permissions=[ServicePermissionType.EMAIL, ServicePermissionType.SMS],
|
service_permissions=[ServicePermissionType.EMAIL, ServicePermissionType.SMS],
|
||||||
|
|||||||
@@ -16,42 +16,49 @@ from tests import create_service_authorization_header
|
|||||||
from tests.app.db import create_api_key, create_notification
|
from tests.app.db import create_api_key, create_notification
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("client", "sample_template")
|
@pytest.mark.usefixtures(
|
||||||
@settings(max_examples=10)
|
"client",
|
||||||
@given(
|
"sample_template",
|
||||||
fuzzed_email_address=st.emails(),
|
|
||||||
fuzzed_personalisation=st.dictionaries(
|
|
||||||
keys=st.text(min_size=1, max_size=20),
|
|
||||||
values=st.text(min_size=0, max_size=100),
|
|
||||||
max_size=5,
|
|
||||||
),
|
|
||||||
fuzzed_reference=st.one_of(st.none(), st.text(min_size=0, max_size=50)),
|
|
||||||
)
|
)
|
||||||
def test_fuzz_send_email_notification(
|
def test_fuzz_send_email_notification(
|
||||||
client,
|
client,
|
||||||
sample_template,
|
sample_template,
|
||||||
sample_email_notification,
|
sample_email_notification,
|
||||||
fuzzed_email_address,
|
|
||||||
fuzzed_personalisation,
|
|
||||||
fuzzed_reference,
|
|
||||||
):
|
):
|
||||||
|
@settings(max_examples=5)
|
||||||
template_id = str(sample_template.id)
|
@given(
|
||||||
|
st.emails(),
|
||||||
payload = {
|
st.dictionaries(
|
||||||
"template_id": template_id,
|
keys=st.text(min_size=1, max_size=20),
|
||||||
"email_address": fuzzed_email_address,
|
values=st.text(min_size=0, max_size=100),
|
||||||
"personalisation": fuzzed_personalisation,
|
max_size=5,
|
||||||
"reference": fuzzed_reference,
|
),
|
||||||
}
|
st.one_of(st.none(), st.text(min_size=0, max_size=50)),
|
||||||
auth_header = create_service_authorization_header(
|
|
||||||
service_id=sample_email_notification.service_id
|
|
||||||
)
|
)
|
||||||
response = client.post("/notifications/email", json=payload, headers=[auth_header])
|
# This use of the 'inner' function is caused because hypothesis doesn't
|
||||||
assert response.status_code in (
|
# work well with function-scoped fixtures like client and sample_template.
|
||||||
201,
|
def inner(email_address, personalisation, reference):
|
||||||
400,
|
|
||||||
), f"Unexpected status: {response.status_code}, body: {response.json}"
|
template_id = str(sample_template.id)
|
||||||
|
|
||||||
|
payload = {
|
||||||
|
"template_id": template_id,
|
||||||
|
"email_address": email_address,
|
||||||
|
"personalisation": personalisation,
|
||||||
|
"reference": reference,
|
||||||
|
}
|
||||||
|
auth_header = create_service_authorization_header(
|
||||||
|
service_id=sample_email_notification.service_id
|
||||||
|
)
|
||||||
|
response = client.post(
|
||||||
|
"/notifications/email", json=payload, headers=[auth_header]
|
||||||
|
)
|
||||||
|
assert response.status_code in (
|
||||||
|
201,
|
||||||
|
400,
|
||||||
|
), f"Unexpected status: {response.status_code}, body: {response.json}"
|
||||||
|
|
||||||
|
inner()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("type", (NotificationType.EMAIL, NotificationType.SMS))
|
@pytest.mark.parametrize("type", (NotificationType.EMAIL, NotificationType.SMS))
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ def notify_api(notify_app):
|
|||||||
ctx.pop()
|
ctx.pop()
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="function")
|
||||||
def client(notify_api):
|
def client(notify_api):
|
||||||
with notify_api.test_request_context(), notify_api.test_client() as client:
|
with notify_api.test_request_context(), notify_api.test_client() as client:
|
||||||
yield client
|
yield client
|
||||||
@@ -83,7 +83,7 @@ def sms_providers(_notify_db):
|
|||||||
# get_provider_details_by_identifier("sns").priority = 100
|
# get_provider_details_by_identifier("sns").priority = 100
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="function")
|
||||||
def notify_db_session(_notify_db, sms_providers):
|
def notify_db_session(_notify_db, sms_providers):
|
||||||
"""
|
"""
|
||||||
This fixture clears down all non static data after your test run. It yields the sqlalchemy session variable
|
This fixture clears down all non static data after your test run. It yields the sqlalchemy session variable
|
||||||
|
|||||||
Reference in New Issue
Block a user