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:
Ben Thorner
2021-08-04 15:12:09 +01:00
parent 5a1636e41f
commit 0312e2a528
33 changed files with 526 additions and 512 deletions

View File

@@ -3,7 +3,7 @@ from flask import json
from app.models import EMAIL_TYPE, LETTER_TYPE, SMS_TYPE, TEMPLATE_TYPES
from app.utils import DATETIME_FORMAT
from tests import create_authorization_header
from tests import create_service_authorization_header
from tests.app.db import create_letter_contact, create_template
valid_version_params = [None, 1]
@@ -24,7 +24,7 @@ def test_get_template_by_id_returns_200(
letter_contact_block_id = letter_contact_block.id
template = create_template(sample_service, template_type=tmp_type, contact_block_id=(letter_contact_block_id))
auth_header = create_authorization_header(service_id=sample_service.id)
auth_header = create_service_authorization_header(service_id=sample_service.id)
version_path = '/version/{}'.format(version) if version else ''
@@ -94,7 +94,7 @@ def test_get_template_by_id_returns_placeholders(
expected_personalisation,
):
template = create_template(sample_service, **create_template_args)
auth_header = create_authorization_header(service_id=sample_service.id)
auth_header = create_service_authorization_header(service_id=sample_service.id)
version_path = '/version/{}'.format(version) if version else ''
@@ -122,7 +122,7 @@ def test_get_letter_template_by_id_returns_placeholders(
content="((letter_content))",
reply_to=contact_block.id,
)
auth_header = create_authorization_header(service_id=sample_service.id)
auth_header = create_service_authorization_header(service_id=sample_service.id)
version_path = '/version/{}'.format(version) if version else ''
@@ -144,7 +144,7 @@ def test_get_letter_template_by_id_returns_placeholders(
def test_get_template_with_non_existent_template_id_returns_404(client, fake_uuid, sample_service):
auth_header = create_authorization_header(service_id=sample_service.id)
auth_header = create_service_authorization_header(service_id=sample_service.id)
response = client.get(path='/v2/template/{}'.format(fake_uuid),
headers=[('Content-Type', 'application/json'), auth_header])
@@ -169,7 +169,7 @@ def test_get_template_with_non_existent_template_id_returns_404(client, fake_uui
def test_get_template_with_non_existent_version_returns_404(client, sample_service, tmp_type):
template = create_template(sample_service, template_type=tmp_type)
auth_header = create_authorization_header(service_id=sample_service.id)
auth_header = create_service_authorization_header(service_id=sample_service.id)
invalid_version = template.version + 1

View File

@@ -2,7 +2,7 @@ import pytest
from flask import json
from app.models import EMAIL_TYPE, LETTER_TYPE, TEMPLATE_TYPES
from tests import create_authorization_header
from tests import create_service_authorization_header
from tests.app.db import create_template
valid_personalisation = {
@@ -83,7 +83,7 @@ def test_valid_post_template_returns_200(
subject=subject,
content=content)
auth_header = create_authorization_header(service_id=sample_service.id)
auth_header = create_service_authorization_header(service_id=sample_service.id)
response = client.post(
path='/v2/template/{}/preview'.format(template.id),
@@ -128,7 +128,7 @@ def test_email_and_letter_templates_not_rendered_into_content(
),
)
auth_header = create_authorization_header(service_id=sample_service.id)
auth_header = create_service_authorization_header(service_id=sample_service.id)
response = client.post(
path='/v2/template/{}/preview'.format(template.id),
@@ -149,7 +149,7 @@ def test_invalid_post_template_returns_400(client, sample_service, tmp_type):
template_type=tmp_type,
content='Dear ((Name)), Hello ((Missing)). Yours Truly, The Government.')
auth_header = create_authorization_header(service_id=sample_service.id)
auth_header = create_service_authorization_header(service_id=sample_service.id)
response = client.post(
path='/v2/template/{}/preview'.format(template.id),
@@ -165,7 +165,7 @@ def test_invalid_post_template_returns_400(client, sample_service, tmp_type):
def test_post_template_with_non_existent_template_id_returns_404(client, fake_uuid, sample_service):
auth_header = create_authorization_header(service_id=sample_service.id)
auth_header = create_service_authorization_header(service_id=sample_service.id)
response = client.post(
path='/v2/template/{}/preview'.format(fake_uuid),
@@ -193,7 +193,7 @@ def test_post_template_returns_200_without_personalisation(client, sample_templa
path='/v2/template/{}/preview'.format(sample_template.id),
data=None,
headers=[('Content-Type', 'application/json'),
create_authorization_header(service_id=sample_template.service_id)]
create_service_authorization_header(service_id=sample_template.service_id)]
)
assert response.status_code == 200
@@ -202,7 +202,7 @@ def test_post_template_returns_200_without_personalisation_and_missing_content_h
response = client.post(
path='/v2/template/{}/preview'.format(sample_template.id),
data=None,
headers=[create_authorization_header(service_id=sample_template.service_id)]
headers=[create_service_authorization_header(service_id=sample_template.service_id)]
)
assert response.status_code == 200
@@ -213,7 +213,7 @@ def test_post_template_returns_200_without_personalisation_as_valid_json_and_mis
response = client.post(
path='/v2/template/{}/preview'.format(sample_template.id),
data=json.dumps(None),
headers=[create_authorization_header(service_id=sample_template.service_id)]
headers=[create_service_authorization_header(service_id=sample_template.service_id)]
)
assert response.status_code == 200
@@ -222,6 +222,6 @@ def test_post_template_returns_200_with_valid_json_and_missing_content_header(cl
response = client.post(
path='/v2/template/{}/preview'.format(sample_template.id),
data=json.dumps(valid_personalisation),
headers=[create_authorization_header(service_id=sample_template.service_id)]
headers=[create_service_authorization_header(service_id=sample_template.service_id)]
)
assert response.status_code == 200