request stats for today from send page from GET /service/:id endpoint

also amended test cases to ensure they mock out correct call
This commit is contained in:
Leo Hemsted
2016-07-25 14:16:34 +01:00
parent 40ed6dfe8e
commit 0accd88869
6 changed files with 52 additions and 79 deletions

View File

@@ -212,11 +212,9 @@ def check_messages(service_id, template_type, upload_id):
return redirect(url_for('main.choose_template', service_id=service_id, template_type=template_type))
users = user_api_client.get_users_for_service(service_id=service_id)
today = datetime.utcnow().date().strftime('%Y-%m-%d')
statistics = statistics_api_client.get_statistics_for_service_for_day(service_id, today)
if not statistics:
statistics = {}
statistics = service_api_client.get_detailed_service_for_today(service_id)['data']['statistics']
remaining_messages = (current_service['message_limit'] - sum(stat['requested'] for stat in statistics.values()))
contents = s3download(service_id, upload_id)
if not contents:
@@ -240,7 +238,8 @@ def check_messages(service_id, template_type, upload_id):
max_errors_shown=50,
whitelist=itertools.chain.from_iterable(
[user.mobile_number, user.email_address] for user in users
) if current_service['restricted'] else None
) if current_service['restricted'] else None,
remaining_messages=remaining_messages
)
if request.args.get('from_test'):
@@ -278,7 +277,7 @@ def check_messages(service_id, template_type, upload_id):
original_file_name=session['upload_data'].get('original_file_name'),
upload_id=upload_id,
form=CsvUploadForm(),
statistics=statistics,
remaining_messages=remaining_messages,
back_link=back_link,
help=get_help_argument()
)

View File

@@ -42,14 +42,20 @@ class ServiceAPIClient(NotificationsAPIClient):
return self.delete(endpoint, data)
def get_service(self, service_id):
return self._get_service(service_id, False)
return self._get_service(service_id, False, today_only=False)
def get_detailed_service(self, service_id):
return self._get_service(service_id, True)
return self._get_service(service_id, True, today_only=False)
def _get_service(self, service_id, detailed):
def get_detailed_service_for_today(self, service_id):
return self._get_service(service_id, False, today_only=True)
def _get_service(self, service_id, detailed, today_only):
"""
Retrieve a service.
:param detailed - return additional details, including notification statistics
:param today_only - return statistics only for today. No effect if detailed not passed in
"""
params = {'detailed': True} if detailed else {}
return self.get(

View File

@@ -11,10 +11,8 @@
.
</p>
<p>
{% if statistics.emails_requested or statistics.sms_requested %}
You can still send
{{ current_service.message_limit - statistics.get('emails_requested', 0) - statistics.get('sms_requested', 0) }}
messages today, but
{% if current_service.message_limit != remaining_messages %}
You can still send {{ remaining_messages }} messages today, but
{% endif %}
{{ original_file_name }} contains
{{ count_of_recipients }} {{ recipients.recipient_column_header }}

View File

@@ -103,7 +103,7 @@
{% endcall %}
</div>
{% elif count_of_recipients > (current_service.message_limit - statistics.get('emails_requested', 0) - statistics.get('sms_requested', 0)) %}
{% elif recipients.more_rows_than_can_send %}
{% include "partials/check/too-many-messages.html" %}
{% else %}
@@ -134,10 +134,7 @@
</div>
{% endif %}
{% if (
errors or
count_of_recipients > (current_service.message_limit - statistics.get('emails_requested', 0) - statistics.get('sms_requested', 0))
) %}
{% if errors %}
{% if request.args.from_test %}
<a href="{{ back_link }}" class="page-footer-back-link">Back</a>
{% else %}