mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-31 23:26:23 -05:00
Split generating authorization headers by type
In response to [1]. [1]: https://github.com/alphagov/notifications-api/pull/3300#discussion_r681653248
This commit is contained in:
@@ -26,7 +26,7 @@ from app.models import (
|
||||
Template,
|
||||
TemplateHistory,
|
||||
)
|
||||
from tests import create_authorization_header
|
||||
from tests import create_admin_authorization_header
|
||||
from tests.app.db import (
|
||||
create_letter_contact,
|
||||
create_notification,
|
||||
@@ -59,7 +59,7 @@ def test_should_create_a_new_template_for_a_service(
|
||||
if template_type == LETTER_TYPE:
|
||||
data.update({'postage': 'first'})
|
||||
data = json.dumps(data)
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
|
||||
response = client.post(
|
||||
'/service/{}/template'.format(service.id),
|
||||
@@ -105,7 +105,7 @@ def test_create_a_new_template_for_a_service_adds_folder_relationship(
|
||||
'parent_folder_id': str(parent_folder.id)
|
||||
}
|
||||
data = json.dumps(data)
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
|
||||
response = client.post(
|
||||
'/service/{}/template'.format(sample_service.id),
|
||||
@@ -134,7 +134,7 @@ def test_create_a_new_template_for_a_service_adds_postage_for_letters_only(
|
||||
data["subject"] = "Hi, I have good news"
|
||||
|
||||
data = json.dumps(data)
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
|
||||
response = client.post(
|
||||
'/service/{}/template'.format(sample_service.id),
|
||||
@@ -161,7 +161,7 @@ def test_create_template_should_return_400_if_folder_is_for_a_different_service(
|
||||
'parent_folder_id': str(parent_folder.id)
|
||||
}
|
||||
data = json.dumps(data)
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
|
||||
response = client.post(
|
||||
'/service/{}/template'.format(sample_service.id),
|
||||
@@ -184,7 +184,7 @@ def test_create_template_should_return_400_if_folder_does_not_exist(
|
||||
'parent_folder_id': str(uuid.uuid4())
|
||||
}
|
||||
data = json.dumps(data)
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
|
||||
response = client.post(
|
||||
'/service/{}/template'.format(sample_service.id),
|
||||
@@ -204,7 +204,7 @@ def test_should_raise_error_if_service_does_not_exist_on_create(client, sample_u
|
||||
'created_by': str(sample_user.id)
|
||||
}
|
||||
data = json.dumps(data)
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
|
||||
response = client.post(
|
||||
'/service/{}/template'.format(fake_uuid),
|
||||
@@ -237,7 +237,7 @@ def test_should_raise_error_on_create_if_no_permission(
|
||||
data.update({'subject': subject})
|
||||
|
||||
data = json.dumps(data)
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
|
||||
response = client.post(
|
||||
'/service/{}/template'.format(service.id),
|
||||
@@ -271,7 +271,7 @@ def test_should_be_error_on_update_if_no_permission(
|
||||
}
|
||||
|
||||
data = json.dumps(data)
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
|
||||
update_response = client.post(
|
||||
'/service/{}/template/{}'.format(
|
||||
@@ -295,7 +295,7 @@ def test_should_error_if_created_by_missing(client, sample_user, sample_service)
|
||||
'service': service_id
|
||||
}
|
||||
data = json.dumps(data)
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
|
||||
response = client.post(
|
||||
'/service/{}/template'.format(service_id),
|
||||
@@ -313,7 +313,7 @@ def test_should_be_error_if_service_does_not_exist_on_update(client, fake_uuid):
|
||||
'name': 'my template'
|
||||
}
|
||||
data = json.dumps(data)
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
|
||||
response = client.post(
|
||||
'/service/{}/template/{}'.format(fake_uuid, fake_uuid),
|
||||
@@ -336,7 +336,7 @@ def test_must_have_a_subject_on_an_email_or_letter_template(client, sample_user,
|
||||
'created_by': str(sample_user.id)
|
||||
}
|
||||
data = json.dumps(data)
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
|
||||
response = client.post(
|
||||
'/service/{}/template'.format(sample_service.id),
|
||||
@@ -362,7 +362,7 @@ def test_update_should_update_a_template(client, sample_user):
|
||||
'postage': 'first'
|
||||
}
|
||||
data = json.dumps(data)
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
|
||||
update_response = client.post(
|
||||
'/service/{}/template/{}'.format(service.id, template.id),
|
||||
@@ -399,7 +399,7 @@ def test_should_be_able_to_archive_template(client, sample_template):
|
||||
|
||||
json_data = json.dumps(data)
|
||||
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
|
||||
resp = client.post(
|
||||
'/service/{}/template/{}'.format(sample_template.service.id, sample_template.id),
|
||||
@@ -423,7 +423,7 @@ def test_should_be_able_to_archive_template_should_remove_template_folders(
|
||||
|
||||
client.post(
|
||||
f'/service/{sample_service.id}/template/{template.id}',
|
||||
headers=[('Content-Type', 'application/json'), create_authorization_header()],
|
||||
headers=[('Content-Type', 'application/json'), create_admin_authorization_header()],
|
||||
data=json.dumps(data)
|
||||
)
|
||||
|
||||
@@ -441,7 +441,7 @@ def test_get_precompiled_template_for_service(
|
||||
|
||||
response = client.get(
|
||||
'/service/{}/template/precompiled'.format(sample_service.id),
|
||||
headers=[create_authorization_header()],
|
||||
headers=[create_admin_authorization_header()],
|
||||
)
|
||||
assert response.status_code == 200
|
||||
assert len(sample_service.templates) == 1
|
||||
@@ -465,7 +465,7 @@ def test_get_precompiled_template_for_service_when_service_has_existing_precompi
|
||||
|
||||
response = client.get(
|
||||
'/service/{}/template/precompiled'.format(sample_service.id),
|
||||
headers=[create_authorization_header()],
|
||||
headers=[create_admin_authorization_header()],
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
@@ -495,13 +495,13 @@ def test_should_be_able_to_get_all_templates_for_a_service(client, sample_user,
|
||||
'created_by': str(sample_user.id)
|
||||
}
|
||||
data_2 = json.dumps(data)
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
client.post(
|
||||
'/service/{}/template'.format(sample_service.id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header],
|
||||
data=data_1
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
|
||||
client.post(
|
||||
'/service/{}/template'.format(sample_service.id),
|
||||
@@ -509,7 +509,7 @@ def test_should_be_able_to_get_all_templates_for_a_service(client, sample_user,
|
||||
data=data_2
|
||||
)
|
||||
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
|
||||
response = client.get(
|
||||
'/service/{}/template'.format(sample_service.id),
|
||||
@@ -648,7 +648,7 @@ def test_should_get_a_single_template(
|
||||
|
||||
response = client.get(
|
||||
'/service/{}/template/{}'.format(sample_service.id, template.id),
|
||||
headers=[create_authorization_header()]
|
||||
headers=[create_admin_authorization_header()]
|
||||
)
|
||||
|
||||
data = json.loads(response.get_data(as_text=True))['data']
|
||||
@@ -709,7 +709,7 @@ def test_should_preview_a_single_template(
|
||||
|
||||
response = client.get(
|
||||
path.format(sample_service.id, template.id),
|
||||
headers=[create_authorization_header()]
|
||||
headers=[create_admin_authorization_header()]
|
||||
)
|
||||
|
||||
content = json.loads(response.get_data(as_text=True))
|
||||
@@ -725,7 +725,7 @@ def test_should_preview_a_single_template(
|
||||
|
||||
def test_should_return_empty_array_if_no_templates_for_service(client, sample_service):
|
||||
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
|
||||
response = client.get(
|
||||
'/service/{}/template'.format(sample_service.id),
|
||||
@@ -739,7 +739,7 @@ def test_should_return_empty_array_if_no_templates_for_service(client, sample_se
|
||||
|
||||
def test_should_return_404_if_no_templates_for_service_with_id(client, sample_service, fake_uuid):
|
||||
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
|
||||
response = client.get(
|
||||
'/service/{}/template/{}'.format(sample_service.id, fake_uuid),
|
||||
@@ -772,7 +772,7 @@ def test_create_400_for_over_limit_content(
|
||||
'created_by': str(sample_service.created_by.id)
|
||||
}
|
||||
data = json.dumps(data)
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
|
||||
response = client.post(
|
||||
'/service/{}/template'.format(sample_service.id),
|
||||
@@ -792,7 +792,7 @@ def test_update_400_for_over_limit_content(client, notify_api, sample_user, samp
|
||||
SMS_CHAR_COUNT_LIMIT + 1)),
|
||||
'created_by': str(sample_user.id)
|
||||
})
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
resp = client.post(
|
||||
'/service/{}/template/{}'.format(sample_template.service.id, sample_template.id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header],
|
||||
@@ -813,7 +813,7 @@ def test_should_return_all_template_versions_for_service_and_template_id(client,
|
||||
sample_template.content = original_content + '2'
|
||||
dao_update_template(sample_template)
|
||||
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
resp = client.get('/service/{}/template/{}/versions'.format(sample_template.service_id, sample_template.id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
assert resp.status_code == 200
|
||||
@@ -830,7 +830,7 @@ def test_should_return_all_template_versions_for_service_and_template_id(client,
|
||||
|
||||
def test_update_does_not_create_new_version_when_there_is_no_change(client, sample_template):
|
||||
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
data = {
|
||||
'template_type': sample_template.template_type,
|
||||
'content': sample_template.content,
|
||||
@@ -845,7 +845,7 @@ def test_update_does_not_create_new_version_when_there_is_no_change(client, samp
|
||||
|
||||
|
||||
def test_update_set_process_type_on_template(client, sample_template):
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
data = {
|
||||
'process_type': 'priority'
|
||||
}
|
||||
@@ -949,7 +949,7 @@ def test_create_template_validates_against_json_schema(
|
||||
(None, None)
|
||||
])
|
||||
def test_get_template_reply_to(client, sample_service, template_default, service_default):
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
if service_default:
|
||||
create_letter_contact(
|
||||
service=sample_service, contact_block=service_default, is_default=True
|
||||
@@ -973,7 +973,7 @@ def test_get_template_reply_to(client, sample_service, template_default, service
|
||||
|
||||
|
||||
def test_update_template_reply_to(client, sample_letter_template):
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
letter_contact = create_letter_contact(sample_letter_template.service, "Edinburgh, ED1 1AA")
|
||||
data = {
|
||||
'reply_to': str(letter_contact.id),
|
||||
@@ -992,7 +992,7 @@ def test_update_template_reply_to(client, sample_letter_template):
|
||||
|
||||
|
||||
def test_update_template_reply_to_set_to_blank(client, notify_db_session):
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
service = create_service(service_permissions=['letter'])
|
||||
letter_contact = create_letter_contact(service, "Edinburgh, ED1 1AA")
|
||||
template = create_template(service=service, template_type='letter', reply_to=letter_contact.id)
|
||||
@@ -1027,7 +1027,7 @@ def test_update_template_validates_postage(admin_request, sample_service_full_pe
|
||||
|
||||
|
||||
def test_update_template_with_foreign_service_reply_to(client, sample_letter_template):
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
|
||||
service2 = create_service(service_name='test service', email_from='test@example.com',
|
||||
service_permissions=['letter'])
|
||||
|
||||
Reference in New Issue
Block a user