Prevent v2 notifications POST when in trial mode

This commit is contained in:
Ken Tsang
2017-08-25 16:07:30 +01:00
parent b346d5d173
commit 8f82642422
2 changed files with 23 additions and 3 deletions

View File

@@ -150,6 +150,9 @@ def process_letter_notification(*, letter_data, api_key, template):
if api_key.key_type == KEY_TYPE_TEAM: if api_key.key_type == KEY_TYPE_TEAM:
raise BadRequestError(message='Cannot send letters with a team api key', status_code=403) raise BadRequestError(message='Cannot send letters with a team api key', status_code=403)
if api_key.service.restricted:
raise BadRequestError(message='Cannot send letters when service is in trial mode', status_code=403)
job = create_letter_api_job(template) job = create_letter_api_job(template)
notification = create_letter_notification(letter_data, job, api_key) notification = create_letter_notification(letter_data, job, api_key)

View File

@@ -17,13 +17,12 @@ from app.variables import LETTER_TEST_API_FILENAME
from app.variables import LETTER_API_FILENAME from app.variables import LETTER_API_FILENAME
from tests import create_authorization_header from tests import create_authorization_header
from tests.app.db import create_service from tests.app.db import create_service, create_template
from tests.app.db import create_template
def letter_request(client, data, service_id, key_type=KEY_TYPE_NORMAL, _expected_status=201): def letter_request(client, data, service_id, key_type=KEY_TYPE_NORMAL, _expected_status=201):
resp = client.post( resp = client.post(
url_for('v2_notifications.post_notification', notification_type='letter'), url_for('v2_notifications.post_notification', notification_type=LETTER_TYPE),
data=json.dumps(data), data=json.dumps(data),
headers=[ headers=[
('Content-Type', 'application/json'), ('Content-Type', 'application/json'),
@@ -232,3 +231,21 @@ def test_post_letter_notification_doesnt_accept_team_key(client, sample_letter_t
assert error_json['status_code'] == 403 assert error_json['status_code'] == 403
assert error_json['errors'] == [{'error': 'BadRequestError', 'message': 'Cannot send letters with a team api key'}] assert error_json['errors'] == [{'error': 'BadRequestError', 'message': 'Cannot send letters with a team api key'}]
def test_post_letter_notification_doesnt_send_in_trial(client, sample_trial_letter_template):
data = {
'template_id': str(sample_trial_letter_template.id),
'personalisation': {'address_line_1': 'Foo', 'address_line_2': 'Bar', 'postcode': 'Baz'}
}
error_json = letter_request(
client,
data,
sample_trial_letter_template.service_id,
_expected_status=403
)
assert error_json['status_code'] == 403
assert error_json['errors'] == [
{'error': 'BadRequestError', 'message': 'Cannot send letters when service is in trial mode'}]