mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-11 10:28:55 -04:00
Merge branch 'master' into update-notification-international
This commit is contained in:
@@ -456,3 +456,10 @@ def dao_update_notifications_sent_to_dvla(job_id, provider):
|
|||||||
{'status': NOTIFICATION_SENDING, "sent_by": provider, "sent_at": now, "updated_at": now})
|
{'status': NOTIFICATION_SENDING, "sent_by": provider, "sent_at": now, "updated_at": now})
|
||||||
|
|
||||||
return updated_count
|
return updated_count
|
||||||
|
|
||||||
|
|
||||||
|
@statsd(namespace="dao")
|
||||||
|
def dao_get_notifications_by_to_field(service_id, search_term):
|
||||||
|
return Notification.query.filter(
|
||||||
|
Notification.service_id == service_id,
|
||||||
|
func.replace(func.lower(Notification.to), " ", "") == search_term.lower().replace(" ", "")).all()
|
||||||
|
|||||||
@@ -492,6 +492,7 @@ class NotificationsFilterSchema(ma.Schema):
|
|||||||
include_from_test_key = fields.Boolean(required=False)
|
include_from_test_key = fields.Boolean(required=False)
|
||||||
older_than = fields.UUID(required=False)
|
older_than = fields.UUID(required=False)
|
||||||
format_for_csv = fields.String()
|
format_for_csv = fields.String()
|
||||||
|
to = fields.String()
|
||||||
|
|
||||||
@pre_load
|
@pre_load
|
||||||
def handle_multidict(self, in_data):
|
def handle_multidict(self, in_data):
|
||||||
|
|||||||
@@ -242,6 +242,8 @@ def get_service_history(service_id):
|
|||||||
@service_blueprint.route('/<uuid:service_id>/notifications', methods=['GET'])
|
@service_blueprint.route('/<uuid:service_id>/notifications', methods=['GET'])
|
||||||
def get_all_notifications_for_service(service_id):
|
def get_all_notifications_for_service(service_id):
|
||||||
data = notifications_filter_schema.load(request.args).data
|
data = notifications_filter_schema.load(request.args).data
|
||||||
|
if data.get("to", None):
|
||||||
|
return search_for_notification_by_to_field(service_id, request.query_string.decode())
|
||||||
page = data['page'] if 'page' in data else 1
|
page = data['page'] if 'page' in data else 1
|
||||||
page_size = data['page_size'] if 'page_size' in data else current_app.config.get('PAGE_SIZE')
|
page_size = data['page_size'] if 'page_size' in data else current_app.config.get('PAGE_SIZE')
|
||||||
limit_days = data.get('limit_days')
|
limit_days = data.get('limit_days')
|
||||||
@@ -271,6 +273,13 @@ def get_all_notifications_for_service(service_id):
|
|||||||
), 200
|
), 200
|
||||||
|
|
||||||
|
|
||||||
|
def search_for_notification_by_to_field(service_id, search_term):
|
||||||
|
search_term = search_term.replace('to=', '')
|
||||||
|
results = notifications_dao.dao_get_notifications_by_to_field(service_id, search_term)
|
||||||
|
return jsonify(
|
||||||
|
notifications=notification_with_template_schema.dump(results, many=True).data), 200
|
||||||
|
|
||||||
|
|
||||||
@service_blueprint.route('/<uuid:service_id>/notifications/monthly', methods=['GET'])
|
@service_blueprint.route('/<uuid:service_id>/notifications/monthly', methods=['GET'])
|
||||||
def get_monthly_notification_stats(service_id):
|
def get_monthly_notification_stats(service_id):
|
||||||
service = dao_fetch_service_by_id(service_id)
|
service = dao_fetch_service_by_id(service_id)
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ celery==3.1.23
|
|||||||
monotonic==1.2
|
monotonic==1.2
|
||||||
statsd==3.2.1
|
statsd==3.2.1
|
||||||
jsonschema==2.5.1
|
jsonschema==2.5.1
|
||||||
Flask-Redis==0.1.0
|
|
||||||
gunicorn==19.6.0
|
gunicorn==19.6.0
|
||||||
docopt==0.6.2
|
docopt==0.6.2
|
||||||
six==1.10.0
|
six==1.10.0
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ from app.dao.notifications_dao import (
|
|||||||
dao_delete_notifications_and_history_by_id,
|
dao_delete_notifications_and_history_by_id,
|
||||||
dao_timeout_notifications,
|
dao_timeout_notifications,
|
||||||
is_delivery_slow_for_provider,
|
is_delivery_slow_for_provider,
|
||||||
dao_update_notifications_sent_to_dvla)
|
dao_update_notifications_sent_to_dvla, dao_get_notifications_by_to_field)
|
||||||
|
|
||||||
from app.dao.services_dao import dao_update_service
|
from app.dao.services_dao import dao_update_service
|
||||||
from tests.app.db import create_notification
|
from tests.app.db import create_notification
|
||||||
@@ -1626,3 +1626,33 @@ def test_dao_update_notifications_sent_to_dvla_does_update_history_if_test_key(
|
|||||||
assert updated_notification.sent_at
|
assert updated_notification.sent_at
|
||||||
assert updated_notification.updated_at
|
assert updated_notification.updated_at
|
||||||
assert not NotificationHistory.query.get(notification.id)
|
assert not NotificationHistory.query.get(notification.id)
|
||||||
|
|
||||||
|
|
||||||
|
def test_dao_get_notifications_by_to_field(sample_template):
|
||||||
|
notification1 = create_notification(template=sample_template, to_field='+447700900855')
|
||||||
|
notification2 = create_notification(template=sample_template, to_field='jack@gmail.com')
|
||||||
|
notification3 = create_notification(template=sample_template, to_field='jane@gmail.com')
|
||||||
|
results = dao_get_notifications_by_to_field(notification1.service_id, "+447700900855")
|
||||||
|
assert len(results) == 1
|
||||||
|
assert results[0].id == notification1.id
|
||||||
|
|
||||||
|
|
||||||
|
def test_dao_get_notifications_by_to_field_search_is_not_case_sensitive(sample_template):
|
||||||
|
notification1 = create_notification(template=sample_template, to_field='+447700900855')
|
||||||
|
notification2 = create_notification(template=sample_template, to_field='jack@gmail.com')
|
||||||
|
notification3 = create_notification(template=sample_template, to_field='jane@gmail.com')
|
||||||
|
results = dao_get_notifications_by_to_field(notification1.service_id, 'JACK@gmail.com')
|
||||||
|
assert len(results) == 1
|
||||||
|
assert results[0].id == notification2.id
|
||||||
|
|
||||||
|
|
||||||
|
def test_dao_get_notifications_by_to_field_search_ignores_spaces(sample_template):
|
||||||
|
notification1 = create_notification(template=sample_template, to_field='+447700900855')
|
||||||
|
notification2 = create_notification(template=sample_template, to_field='+44 77 00900 855')
|
||||||
|
notification3 = create_notification(template=sample_template, to_field=' +4477009 00 855 ')
|
||||||
|
notification4 = create_notification(template=sample_template, to_field='jack@gmail.com')
|
||||||
|
results = dao_get_notifications_by_to_field(notification1.service_id, '+447700900855')
|
||||||
|
assert len(results) == 3
|
||||||
|
assert notification1.id in [r.id for r in results]
|
||||||
|
assert notification2.id in [r.id for r in results]
|
||||||
|
assert notification3.id in [r.id for r in results]
|
||||||
|
|||||||
@@ -1614,3 +1614,48 @@ def test_get_monthly_billing_usage_returns_empty_list_if_no_notifications(client
|
|||||||
)
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert json.loads(response.get_data(as_text=True)) == []
|
assert json.loads(response.get_data(as_text=True)) == []
|
||||||
|
|
||||||
|
|
||||||
|
def test_search_for_notification_by_to_field(client, notify_db, notify_db_session):
|
||||||
|
notification1 = create_sample_notification(notify_db, notify_db_session,
|
||||||
|
to_field="+447700900855")
|
||||||
|
notification2 = create_sample_notification(notify_db, notify_db_session, to_field="jack@gmail.com")
|
||||||
|
|
||||||
|
response = client.get('/service/{}/notifications?to={}'.format(notification1.service_id, "jack@gmail.com"),
|
||||||
|
headers=[create_authorization_header()])
|
||||||
|
assert response.status_code == 200
|
||||||
|
result = json.loads(response.get_data(as_text=True))
|
||||||
|
assert len(result["notifications"]) == 1
|
||||||
|
assert result["notifications"][0]["id"] == str(notification2.id)
|
||||||
|
|
||||||
|
|
||||||
|
def test_search_for_notification_by_to_field_return_empty_list_if_there_is_no_match(
|
||||||
|
client, notify_db, notify_db_session):
|
||||||
|
notification1 = create_sample_notification(notify_db, notify_db_session,
|
||||||
|
to_field="+447700900855")
|
||||||
|
notification2 = create_sample_notification(notify_db, notify_db_session, to_field="jack@gmail.com")
|
||||||
|
|
||||||
|
response = client.get('/service/{}/notifications?to={}'.format(notification1.service_id, "+447700900800"),
|
||||||
|
headers=[create_authorization_header()])
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert len(json.loads(response.get_data(as_text=True))["notifications"]) == 0
|
||||||
|
|
||||||
|
|
||||||
|
def test_search_for_notification_by_to_field_return_multiple_matches(
|
||||||
|
client, notify_db, notify_db_session):
|
||||||
|
notification1 = create_sample_notification(notify_db, notify_db_session,
|
||||||
|
to_field="+447700900855")
|
||||||
|
notification2 = create_sample_notification(notify_db, notify_db_session,
|
||||||
|
to_field=" +44 77009 00855 ")
|
||||||
|
notification3 = create_sample_notification(notify_db, notify_db_session,
|
||||||
|
to_field="+44770 0900 855")
|
||||||
|
notification4 = create_sample_notification(notify_db, notify_db_session, to_field="jack@gmail.com")
|
||||||
|
|
||||||
|
response = client.get('/service/{}/notifications?to={}'.format(notification1.service_id, "+447700900855"),
|
||||||
|
headers=[create_authorization_header()])
|
||||||
|
assert response.status_code == 200
|
||||||
|
result = json.loads(response.get_data(as_text=True))
|
||||||
|
assert len(result["notifications"]) == 3
|
||||||
|
assert str(notification1.id) in [n["id"] for n in result["notifications"]]
|
||||||
|
assert str(notification2.id) in [n["id"] for n in result["notifications"]]
|
||||||
|
assert str(notification3.id) in [n["id"] for n in result["notifications"]]
|
||||||
|
|||||||
Reference in New Issue
Block a user