increase page size for API calls to 250

This commit is contained in:
Rebecca Law
2017-01-20 12:26:55 +00:00
parent 645a6fb3cf
commit 8ed0979251
4 changed files with 461 additions and 497 deletions

View File

@@ -68,6 +68,7 @@ class Config(object):
SQLALCHEMY_RECORD_QUERIES = True SQLALCHEMY_RECORD_QUERIES = True
SQLALCHEMY_TRACK_MODIFICATIONS = True SQLALCHEMY_TRACK_MODIFICATIONS = True
PAGE_SIZE = 50 PAGE_SIZE = 50
API_PAGE_SIZE = 250
SMS_CHAR_COUNT_LIMIT = 495 SMS_CHAR_COUNT_LIMIT = 495
BRANDING_PATH = '/images/email-template/crests/' BRANDING_PATH = '/images/email-template/crests/'
TEST_MESSAGE_FILENAME = 'Test message' TEST_MESSAGE_FILENAME = 'Test message'

View File

@@ -175,7 +175,7 @@ def get_all_notifications():
data = notifications_filter_schema.load(request.args).data data = notifications_filter_schema.load(request.args).data
include_jobs = data.get('include_jobs', False) include_jobs = data.get('include_jobs', False)
page = data.get('page', 1) page = data.get('page', 1)
page_size = data.get('page_size', current_app.config.get('PAGE_SIZE')) page_size = data.get('page_size', current_app.config.get('API_PAGE_SIZE'))
limit_days = data.get('limit_days') limit_days = data.get('limit_days')
pagination = notifications_dao.get_notifications_for_service( pagination = notifications_dao.get_notifications_for_service(

View File

@@ -1,6 +1,6 @@
import uuid import uuid
from flask import jsonify, request, url_for from flask import jsonify, request, url_for, current_app
from werkzeug.exceptions import abort from werkzeug.exceptions import abort
from app import api_user from app import api_user
@@ -43,7 +43,8 @@ def get_notifications():
key_type=api_user.key_type, key_type=api_user.key_type,
personalisation=True, personalisation=True,
older_than=data.get('older_than'), older_than=data.get('older_than'),
client_reference=data.get('reference') client_reference=data.get('reference'),
page_size=current_app.config.get('API_PAGE_SIZE')
) )
def _build_links(notifications): def _build_links(notifications):

View File

@@ -1,7 +1,7 @@
import uuid import uuid
import pytest import pytest
from flask import json from flask import json, current_app
from notifications_python_client.authentication import create_jwt_token from notifications_python_client.authentication import create_jwt_token
from freezegun import freeze_time from freezegun import freeze_time
@@ -46,7 +46,7 @@ def test_get_sms_notification_by_invalid_id(client, sample_notification, id):
assert response.status_code == 405 assert response.status_code == 405
def test_get_email_notification_by_id(notify_api, notify_db, notify_db_session, sample_email_template): def test_get_email_notification_by_id(client, notify_db, notify_db_session, sample_email_template):
email_notification = create_sample_notification(notify_db, email_notification = create_sample_notification(notify_db,
notify_db_session, notify_db_session,
@@ -55,8 +55,6 @@ def test_get_email_notification_by_id(notify_api, notify_db, notify_db_session,
template=sample_email_template, template=sample_email_template,
status='sending') status='sending')
with notify_api.test_request_context():
with notify_api.test_client() as client:
auth_header = create_authorization_header(service_id=email_notification.service_id) auth_header = create_authorization_header(service_id=email_notification.service_id)
response = client.get( response = client.get(
@@ -79,14 +77,11 @@ def test_get_email_notification_by_id(notify_api, notify_db, notify_db_session,
assert notification['subject'] == sample_email_template.subject assert notification['subject'] == sample_email_template.subject
def test_get_notifications_empty_result(notify_api, sample_api_key): def test_get_notifications_empty_result(client, sample_api_key):
with notify_api.test_request_context():
with notify_api.test_client() as client:
missing_notification_id = uuid.uuid4()
auth_header = create_authorization_header(service_id=sample_api_key.service_id) auth_header = create_authorization_header(service_id=sample_api_key.service_id)
response = client.get( response = client.get(
path='/notifications/{}'.format(missing_notification_id), path='/notifications/{}'.format(uuid.uuid4()),
headers=[auth_header]) headers=[auth_header])
notification = json.loads(response.get_data(as_text=True)) notification = json.loads(response.get_data(as_text=True))
@@ -104,12 +99,11 @@ def test_get_notifications_empty_result(notify_api, sample_api_key):
(KEY_TYPE_TEAM, KEY_TYPE_TEST), (KEY_TYPE_TEAM, KEY_TYPE_TEST),
]) ])
def test_get_notification_from_different_api_key_works( def test_get_notification_from_different_api_key_works(
notify_api, client,
sample_notification, sample_notification,
api_key_type, api_key_type,
notification_key_type notification_key_type
): ):
with notify_api.test_request_context(), notify_api.test_client() as client:
sample_notification.key_type = notification_key_type sample_notification.key_type = notification_key_type
api_key = ApiKey(service=sample_notification.service, api_key = ApiKey(service=sample_notification.service,
name='api_key', name='api_key',
@@ -124,8 +118,7 @@ def test_get_notification_from_different_api_key_works(
@pytest.mark.parametrize('key_type', [KEY_TYPE_NORMAL, KEY_TYPE_TEAM, KEY_TYPE_TEST]) @pytest.mark.parametrize('key_type', [KEY_TYPE_NORMAL, KEY_TYPE_TEAM, KEY_TYPE_TEST])
def test_get_notification_from_different_api_key_of_same_type_succeeds(notify_api, sample_notification, key_type): def test_get_notification_from_different_api_key_of_same_type_succeeds(client, sample_notification, key_type):
with notify_api.test_request_context(), notify_api.test_client() as client:
creation_api_key = ApiKey(service=sample_notification.service, creation_api_key = ApiKey(service=sample_notification.service,
name='creation_api_key', name='creation_api_key',
created_by=sample_notification.service.created_by, created_by=sample_notification.service.created_by,
@@ -152,9 +145,7 @@ def test_get_notification_from_different_api_key_of_same_type_succeeds(notify_ap
assert notification['id'] == str(sample_notification.id) assert notification['id'] == str(sample_notification.id)
def test_get_all_notifications(notify_api, sample_notification): def test_get_all_notifications(client, sample_notification):
with notify_api.test_request_context():
with notify_api.test_client() as client:
auth_header = create_authorization_header(service_id=sample_notification.service_id) auth_header = create_authorization_header(service_id=sample_notification.service_id)
response = client.get( response = client.get(
@@ -177,13 +168,12 @@ def test_get_all_notifications(notify_api, sample_notification):
def test_normal_api_key_returns_notifications_created_from_jobs_and_from_api( def test_normal_api_key_returns_notifications_created_from_jobs_and_from_api(
notify_api, client,
notify_db, notify_db,
notify_db_session, notify_db_session,
sample_api_key, sample_api_key,
sample_notification sample_notification
): ):
with notify_api.test_request_context(), notify_api.test_client() as client:
api_notification = create_sample_notification( api_notification = create_sample_notification(
notify_db, notify_db,
notify_db_session, notify_db_session,
@@ -204,13 +194,12 @@ def test_normal_api_key_returns_notifications_created_from_jobs_and_from_api(
@pytest.mark.parametrize('key_type', [KEY_TYPE_NORMAL, KEY_TYPE_TEAM, KEY_TYPE_TEST]) @pytest.mark.parametrize('key_type', [KEY_TYPE_NORMAL, KEY_TYPE_TEAM, KEY_TYPE_TEST])
def test_get_all_notifications_only_returns_notifications_of_matching_type( def test_get_all_notifications_only_returns_notifications_of_matching_type(
notify_api, client,
notify_db, notify_db,
notify_db_session, notify_db_session,
sample_service, sample_service,
key_type key_type
): ):
with notify_api.test_request_context(), notify_api.test_client() as client:
team_api_key = ApiKey(service=sample_service, team_api_key = ApiKey(service=sample_service,
name='team_api_key', name='team_api_key',
created_by=sample_service.created_by, created_by=sample_service.created_by,
@@ -267,14 +256,13 @@ def test_get_all_notifications_only_returns_notifications_of_matching_type(
@pytest.mark.parametrize('key_type', [KEY_TYPE_NORMAL, KEY_TYPE_TEAM, KEY_TYPE_TEST]) @pytest.mark.parametrize('key_type', [KEY_TYPE_NORMAL, KEY_TYPE_TEAM, KEY_TYPE_TEST])
def test_no_api_keys_return_job_notifications_by_default( def test_no_api_keys_return_job_notifications_by_default(
notify_api, client,
notify_db, notify_db,
notify_db_session, notify_db_session,
sample_service, sample_service,
sample_job, sample_job,
key_type key_type
): ):
with notify_api.test_request_context(), notify_api.test_client() as client:
team_api_key = ApiKey(service=sample_service, team_api_key = ApiKey(service=sample_service,
name='team_api_key', name='team_api_key',
created_by=sample_service.created_by, created_by=sample_service.created_by,
@@ -341,14 +329,13 @@ def test_no_api_keys_return_job_notifications_by_default(
(KEY_TYPE_TEST, 1) (KEY_TYPE_TEST, 1)
]) ])
def test_only_normal_api_keys_can_return_job_notifications( def test_only_normal_api_keys_can_return_job_notifications(
notify_api, client,
notify_db, notify_db,
notify_db_session, notify_db_session,
sample_service, sample_service,
sample_job, sample_job,
key_type key_type
): ):
with notify_api.test_request_context(), notify_api.test_client() as client:
team_api_key = ApiKey(service=sample_service, team_api_key = ApiKey(service=sample_service,
name='team_api_key', name='team_api_key',
created_by=sample_service.created_by, created_by=sample_service.created_by,
@@ -408,9 +395,7 @@ def test_only_normal_api_keys_can_return_job_notifications(
assert notifications[0]['id'] == str(notification_objs[key_type[0]].id) assert notifications[0]['id'] == str(notification_objs[key_type[0]].id)
def test_get_all_notifications_newest_first(notify_api, notify_db, notify_db_session, sample_email_template): def test_get_all_notifications_newest_first(client, notify_db, notify_db_session, sample_email_template):
with notify_api.test_request_context():
with notify_api.test_client() as client:
notification_1 = create_sample_notification(notify_db, notify_db_session, sample_email_template.service) notification_1 = create_sample_notification(notify_db, notify_db_session, sample_email_template.service)
notification_2 = create_sample_notification(notify_db, notify_db_session, sample_email_template.service) notification_2 = create_sample_notification(notify_db, notify_db_session, sample_email_template.service)
notification_3 = create_sample_notification(notify_db, notify_db_session, sample_email_template.service) notification_3 = create_sample_notification(notify_db, notify_db_session, sample_email_template.service)
@@ -429,9 +414,7 @@ def test_get_all_notifications_newest_first(notify_api, notify_db, notify_db_ses
assert response.status_code == 200 assert response.status_code == 200
def test_should_reject_invalid_page_param(notify_api, sample_email_template): def test_should_reject_invalid_page_param(client, sample_email_template):
with notify_api.test_request_context():
with notify_api.test_client() as client:
auth_header = create_authorization_header(service_id=sample_email_template.service_id) auth_header = create_authorization_header(service_id=sample_email_template.service_id)
response = client.get( response = client.get(
@@ -462,11 +445,10 @@ def test_valid_page_size_param(notify_api, notify_db, notify_db_session, sample_
assert notifications['page_size'] == 1 assert notifications['page_size'] == 1
def test_invalid_page_size_param(notify_api, notify_db, notify_db_session, sample_email_template): def test_invalid_page_size_param(client, notify_db, notify_db_session, sample_email_template):
with notify_api.test_request_context():
n1 = create_sample_notification(notify_db, notify_db_session) n1 = create_sample_notification(notify_db, notify_db_session)
n2 = create_sample_notification(notify_db, notify_db_session) n2 = create_sample_notification(notify_db, notify_db_session)
with notify_api.test_client() as client:
auth_header = create_authorization_header(service_id=sample_email_template.service_id) auth_header = create_authorization_header(service_id=sample_email_template.service_id)
response = client.get( response = client.get(
@@ -479,13 +461,11 @@ def test_invalid_page_size_param(notify_api, notify_db, notify_db_session, sampl
assert 'Not a valid integer.' in notifications['message']['page_size'] assert 'Not a valid integer.' in notifications['message']['page_size']
def test_should_return_pagination_links(notify_api, notify_db, notify_db_session, sample_email_template): def test_should_return_pagination_links(client, notify_db, notify_db_session, sample_email_template):
with notify_api.test_request_context():
with notify_api.test_client() as client:
# Effectively mocking page size # Effectively mocking page size
original_page_size = notify_api.config['PAGE_SIZE'] original_page_size = current_app.config['API_PAGE_SIZE']
try: try:
notify_api.config['PAGE_SIZE'] = 1 current_app.config['API_PAGE_SIZE'] = 1
create_sample_notification(notify_db, notify_db_session, sample_email_template.service) create_sample_notification(notify_db, notify_db_session, sample_email_template.service)
notification_2 = create_sample_notification(notify_db, notify_db_session, sample_email_template.service) notification_2 = create_sample_notification(notify_db, notify_db_session, sample_email_template.service)
@@ -506,12 +486,10 @@ def test_should_return_pagination_links(notify_api, notify_db, notify_db_session
assert response.status_code == 200 assert response.status_code == 200
finally: finally:
notify_api.config['PAGE_SIZE'] = original_page_size current_app.config['API_PAGE_SIZE'] = original_page_size
def test_get_all_notifications_returns_empty_list(notify_api, sample_api_key): def test_get_all_notifications_returns_empty_list(client, sample_api_key):
with notify_api.test_request_context():
with notify_api.test_client() as client:
auth_header = create_authorization_header(service_id=sample_api_key.service.id) auth_header = create_authorization_header(service_id=sample_api_key.service.id)
response = client.get( response = client.get(
@@ -523,9 +501,7 @@ def test_get_all_notifications_returns_empty_list(notify_api, sample_api_key):
assert len(notifications['notifications']) == 0 assert len(notifications['notifications']) == 0
def test_filter_by_template_type(notify_api, notify_db, notify_db_session, sample_template, sample_email_template): def test_filter_by_template_type(client, notify_db, notify_db_session, sample_template, sample_email_template):
with notify_api.test_request_context():
with notify_api.test_client() as client:
notification_1 = create_sample_notification( notification_1 = create_sample_notification(
notify_db, notify_db,
notify_db_session, notify_db_session,
@@ -549,13 +525,11 @@ def test_filter_by_template_type(notify_api, notify_db, notify_db_session, sampl
assert response.status_code == 200 assert response.status_code == 200
def test_filter_by_multiple_template_types(notify_api, def test_filter_by_multiple_template_types(client,
notify_db, notify_db,
notify_db_session, notify_db_session,
sample_template, sample_template,
sample_email_template): sample_email_template):
with notify_api.test_request_context():
with notify_api.test_client() as client:
notification_1 = create_sample_notification( notification_1 = create_sample_notification(
notify_db, notify_db,
notify_db_session, notify_db_session,
@@ -580,9 +554,7 @@ def test_filter_by_multiple_template_types(notify_api,
[x['template']['template_type'] for x in notifications['notifications']]) [x['template']['template_type'] for x in notifications['notifications']])
def test_filter_by_status(notify_api, notify_db, notify_db_session, sample_email_template): def test_filter_by_status(client, notify_db, notify_db_session, sample_email_template):
with notify_api.test_request_context():
with notify_api.test_client() as client:
notification_1 = create_sample_notification( notification_1 = create_sample_notification(
notify_db, notify_db,
notify_db_session, notify_db_session,
@@ -608,12 +580,10 @@ def test_filter_by_status(notify_api, notify_db, notify_db_session, sample_email
assert response.status_code == 200 assert response.status_code == 200
def test_filter_by_multiple_statuss(notify_api, def test_filter_by_multiple_statuss(client,
notify_db, notify_db,
notify_db_session, notify_db_session,
sample_email_template): sample_email_template):
with notify_api.test_request_context():
with notify_api.test_client() as client:
notification_1 = create_sample_notification( notification_1 = create_sample_notification(
notify_db, notify_db,
notify_db_session, notify_db_session,
@@ -641,13 +611,11 @@ def test_filter_by_multiple_statuss(notify_api,
[x['status'] for x in notifications['notifications']]) [x['status'] for x in notifications['notifications']])
def test_filter_by_status_and_template_type(notify_api, def test_filter_by_status_and_template_type(client,
notify_db, notify_db,
notify_db_session, notify_db_session,
sample_template, sample_template,
sample_email_template): sample_email_template):
with notify_api.test_request_context():
with notify_api.test_client() as client:
notification_1 = create_sample_notification( notification_1 = create_sample_notification(
notify_db, notify_db,
notify_db_session, notify_db_session,
@@ -680,15 +648,14 @@ def test_filter_by_status_and_template_type(notify_api,
def test_get_notification_by_id_returns_merged_template_content(notify_db, def test_get_notification_by_id_returns_merged_template_content(notify_db,
notify_db_session, notify_db_session,
notify_api, client,
sample_template_with_placeholders): sample_template_with_placeholders):
sample_notification = create_sample_notification(notify_db, sample_notification = create_sample_notification(notify_db,
notify_db_session, notify_db_session,
template=sample_template_with_placeholders, template=sample_template_with_placeholders,
personalisation={"name": "world"}) personalisation={"name": "world"})
with notify_api.test_request_context():
with notify_api.test_client() as client:
auth_header = create_authorization_header(service_id=sample_notification.service_id) auth_header = create_authorization_header(service_id=sample_notification.service_id)
response = client.get( response = client.get(
@@ -705,14 +672,13 @@ def test_get_notification_by_id_returns_merged_template_content(notify_db,
def test_get_notification_by_id_returns_merged_template_content_for_email( def test_get_notification_by_id_returns_merged_template_content_for_email(
notify_db, notify_db,
notify_db_session, notify_db_session,
notify_api, client,
sample_email_template_with_placeholders sample_email_template_with_placeholders
): ):
sample_notification = create_sample_notification(notify_db, sample_notification = create_sample_notification(notify_db,
notify_db_session, notify_db_session,
template=sample_email_template_with_placeholders, template=sample_email_template_with_placeholders,
personalisation={"name": "world"}) personalisation={"name": "world"})
with notify_api.test_request_context(), notify_api.test_client() as client:
auth_header = create_authorization_header(service_id=sample_notification.service_id) auth_header = create_authorization_header(service_id=sample_notification.service_id)
response = client.get( response = client.get(
@@ -726,7 +692,7 @@ def test_get_notification_by_id_returns_merged_template_content_for_email(
assert notification['content_char_count'] is None assert notification['content_char_count'] is None
def test_get_notifications_for_service_returns_merged_template_content(notify_api, def test_get_notifications_for_service_returns_merged_template_content(client,
notify_db, notify_db,
notify_db_session, notify_db_session,
sample_template_with_placeholders): sample_template_with_placeholders):
@@ -744,9 +710,6 @@ def test_get_notifications_for_service_returns_merged_template_content(notify_ap
template=sample_template_with_placeholders, template=sample_template_with_placeholders,
personalisation={"name": "merged with second"}) personalisation={"name": "merged with second"})
with notify_api.test_request_context():
with notify_api.test_client() as client:
auth_header = create_authorization_header(service_id=sample_template_with_placeholders.service_id) auth_header = create_authorization_header(service_id=sample_template_with_placeholders.service_id)
response = client.get( response = client.get(
@@ -760,7 +723,7 @@ def test_get_notifications_for_service_returns_merged_template_content(notify_ap
} }
def test_get_notification_selects_correct_template_for_personalisation(notify_api, def test_get_notification_selects_correct_template_for_personalisation(client,
notify_db, notify_db,
notify_db_session, notify_db_session,
sample_template): sample_template):
@@ -780,7 +743,6 @@ def test_get_notification_selects_correct_template_for_personalisation(notify_ap
template=sample_template, template=sample_template,
personalisation={"name": "foo"}) personalisation={"name": "foo"})
with notify_api.test_request_context(), notify_api.test_client() as client:
auth_header = create_authorization_header(service_id=sample_template.service_id) auth_header = create_authorization_header(service_id=sample_template.service_id)
response = client.get(path='/notifications', headers=[auth_header]) response = client.get(path='/notifications', headers=[auth_header])