Use service model to look up service attributes

This is better than just keying into the JSON because it means you get
an exception straight away when looking up a key that doesn’t exist
(which via mocking you could ordinarily miss).
This commit is contained in:
Chris Hill-Scott
2018-07-20 08:42:01 +01:00
parent 036923c382
commit 1304561a70
14 changed files with 147 additions and 77 deletions

View File

@@ -116,7 +116,7 @@ def send_messages(service_id, template_id):
session['sender_id'] = None
db_template = service_api_client.get_service_template(service_id, template_id)['data']
if email_or_sms_not_enabled(db_template['template_type'], current_service['permissions']):
if email_or_sms_not_enabled(db_template['template_type'], current_service.permissions):
return redirect(url_for(
'.action_blocked',
service_id=service_id,
@@ -294,7 +294,7 @@ def send_test(service_id, template_id):
if db_template['template_type'] == 'letter':
session['sender_id'] = None
if email_or_sms_not_enabled(db_template['template_type'], current_service['permissions']):
if email_or_sms_not_enabled(db_template['template_type'], current_service.permissions):
return redirect(url_for(
'.action_blocked',
service_id=service_id,
@@ -511,7 +511,7 @@ def _check_messages(service_id, template_id, upload_id, preview_row, letters_as_
users = user_api_client.get_users_for_service(service_id=service_id)
statistics = service_api_client.get_service_statistics(service_id, today_only=True)
remaining_messages = (current_service['message_limit'] - sum(stat['requested'] for stat in statistics.values()))
remaining_messages = (current_service.message_limit - sum(stat['requested'] for stat in statistics.values()))
contents = s3download(service_id, upload_id)
@@ -549,7 +549,7 @@ def _check_messages(service_id, template_id, upload_id, preview_row, letters_as_
max_errors_shown=50,
whitelist=itertools.chain.from_iterable(
[user.name, user.mobile_number, user.email_address] for user in users
) if current_service['restricted'] else None,
) if current_service.trial_mode else None,
remaining_messages=remaining_messages,
international_sms=current_service.has_permission('international_sms'),
)
@@ -585,7 +585,7 @@ def _check_messages(service_id, template_id, upload_id, preview_row, letters_as_
back_link=back_link,
help=get_help_argument(),
trying_to_send_letters_in_trial_mode=all((
current_service['restricted'],
current_service.trial_mode,
template.template_type == 'letter',
not request.args.get('from_test'),
)),
@@ -873,7 +873,7 @@ def send_notification(service_id, template_id):
)
except HTTPError as exception:
current_app.logger.info('Service {} could not send notification: "{}"'.format(
current_service['id'],
current_service.id,
exception.message
))
return _check_notification(service_id, template_id, exception)