mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-08 07:08:24 -04:00
Refactor tests
This commit is contained in:
@@ -69,7 +69,7 @@ def get_all_notifications_for_service_job(service_id, job_id):
|
|||||||
data = notifications_filter_schema.load(request.args).data
|
data = notifications_filter_schema.load(request.args).data
|
||||||
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')
|
||||||
pagination = get_notifications_for_job(
|
paginated_notifications = get_notifications_for_job(
|
||||||
service_id,
|
service_id,
|
||||||
job_id,
|
job_id,
|
||||||
filter_dict=data,
|
filter_dict=data,
|
||||||
@@ -82,16 +82,16 @@ def get_all_notifications_for_service_job(service_id, job_id):
|
|||||||
|
|
||||||
notifications = None
|
notifications = None
|
||||||
if data.get('format_for_csv'):
|
if data.get('format_for_csv'):
|
||||||
notifications = [notification.serialize_for_csv() for notification in pagination.items]
|
notifications = [notification.serialize_for_csv() for notification in paginated_notifications.items]
|
||||||
else:
|
else:
|
||||||
notifications = notification_with_template_schema.dump(pagination.items, many=True).data
|
notifications = notification_with_template_schema.dump(paginated_notifications.items, many=True).data
|
||||||
|
|
||||||
return jsonify(
|
return jsonify(
|
||||||
notifications=notifications,
|
notifications=notifications,
|
||||||
page_size=page_size,
|
page_size=page_size,
|
||||||
total=pagination.total,
|
total=paginated_notifications.total,
|
||||||
links=pagination_links(
|
links=pagination_links(
|
||||||
pagination,
|
paginated_notifications,
|
||||||
'.get_all_notifications_for_service_job',
|
'.get_all_notifications_for_service_job',
|
||||||
**kwargs
|
**kwargs
|
||||||
)
|
)
|
||||||
|
|||||||
1
celerybeat.pid
Normal file
1
celerybeat.pid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
9772
|
||||||
@@ -731,8 +731,10 @@ def test_get_all_notifications_for_job_returns_csv_format(
|
|||||||
created_at=datetime.utcnow(),
|
created_at=datetime.utcnow(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
path = '/service/{}/job/{}/notifications'.format(notification.service.id, job.id)
|
||||||
|
|
||||||
response = client.get(
|
response = client.get(
|
||||||
path='/service/{}/job/{}/notifications?'.format(notification.service.id, job.id, True),
|
path=path,
|
||||||
headers=[create_authorization_header()],
|
headers=[create_authorization_header()],
|
||||||
query_string={'format_for_csv': True}
|
query_string={'format_for_csv': True}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -87,18 +87,8 @@ def test_notification_for_csv_returns_correct_type(notify_db, notify_db_session,
|
|||||||
to_field=recipient
|
to_field=recipient
|
||||||
)
|
)
|
||||||
|
|
||||||
expected_resp = {
|
|
||||||
"recipient": recipient,
|
|
||||||
"row_number": "",
|
|
||||||
"template_name": "Template Name",
|
|
||||||
"template_type": template_type,
|
|
||||||
"created_at": "Friday 01 January 2016 at 11:09",
|
|
||||||
"job_name": "some.csv",
|
|
||||||
"status": "Sending"
|
|
||||||
}
|
|
||||||
|
|
||||||
serialized = notification.serialize_for_csv()
|
serialized = notification.serialize_for_csv()
|
||||||
assert serialized == expected_resp
|
assert serialized['template_type'] == template_type
|
||||||
|
|
||||||
|
|
||||||
@freeze_time("2016-01-01 11:09:00.000000")
|
@freeze_time("2016-01-01 11:09:00.000000")
|
||||||
@@ -108,59 +98,49 @@ def test_notification_for_csv_returns_correct_job_row_number(notify_db, notify_d
|
|||||||
notify_db_session,
|
notify_db_session,
|
||||||
job_row_number=0
|
job_row_number=0
|
||||||
)
|
)
|
||||||
expected_resp = {
|
|
||||||
"recipient": "+447700900855",
|
|
||||||
"row_number": 1,
|
|
||||||
"template_name": "Template Name",
|
|
||||||
"template_type": "sms",
|
|
||||||
"created_at": "Friday 01 January 2016 at 11:09",
|
|
||||||
"job_name": "some.csv",
|
|
||||||
"status": "Sending"
|
|
||||||
}
|
|
||||||
|
|
||||||
serialized = notification.serialize_for_csv()
|
serialized = notification.serialize_for_csv()
|
||||||
assert serialized == expected_resp
|
assert serialized['row_number'] == 1
|
||||||
|
|
||||||
|
|
||||||
@freeze_time("2016-01-30 12:39:58.321312")
|
@freeze_time("2016-01-30 12:39:58.321312")
|
||||||
def test_notifiation_for_csv_returns_formatted_status(notify_db, notify_db_session):
|
@pytest.mark.parametrize('template_type, status, expected_status', [
|
||||||
|
('email', 'failed', 'Failed'),
|
||||||
|
('email', 'technical-failure', 'Technical failure'),
|
||||||
|
('email', 'temporary-failure', 'Inbox not accepting messages right now'),
|
||||||
|
('email', 'permanent-failure', 'Email address doesn’t exist'),
|
||||||
|
('sms', 'temporary-failure', 'Phone not accepting messages right now'),
|
||||||
|
('sms', 'permanent-failure', 'Phone number doesn’t exist'),
|
||||||
|
('letter', 'permanent-failure', 'Permanent failure'),
|
||||||
|
('letter', 'delivered', 'Delivered')
|
||||||
|
])
|
||||||
|
def test_notification_for_csv_returns_formatted_status(
|
||||||
|
notify_db,
|
||||||
|
notify_db_session,
|
||||||
|
template_type,
|
||||||
|
status,
|
||||||
|
expected_status
|
||||||
|
):
|
||||||
|
template = create_sample_template(notify_db, notify_db_session, template_type=template_type)
|
||||||
notification = create_sample_notification_with_job(
|
notification = create_sample_notification_with_job(
|
||||||
notify_db,
|
notify_db,
|
||||||
notify_db_session,
|
notify_db_session,
|
||||||
job_row_number=51,
|
status=status,
|
||||||
status='temporary-failure'
|
template=template
|
||||||
)
|
)
|
||||||
expected_resp = {
|
|
||||||
"recipient": "+447700900855",
|
|
||||||
"row_number": 52,
|
|
||||||
"template_name": "Template Name",
|
|
||||||
"template_type": "sms",
|
|
||||||
"created_at": "Saturday 30 January 2016 at 12:39",
|
|
||||||
"job_name": "some.csv",
|
|
||||||
"status": "Phone not accepting messages right now"
|
|
||||||
}
|
|
||||||
|
|
||||||
serialized = notification.serialize_for_csv()
|
serialized = notification.serialize_for_csv()
|
||||||
assert serialized == expected_resp
|
assert serialized['status'] == expected_status
|
||||||
|
|
||||||
|
|
||||||
@freeze_time("2017-03-26 23:01:53.321312")
|
@freeze_time("2017-03-26 23:01:53.321312")
|
||||||
def test_notifiation_for_csv_returns_bst_correctly(notify_db, notify_db_session):
|
def test_notification_for_csv_returns_bst_correctly(notify_db, notify_db_session):
|
||||||
notification = create_sample_notification_with_job(
|
notification = create_sample_notification_with_job(
|
||||||
notify_db,
|
notify_db,
|
||||||
notify_db_session,
|
notify_db_session,
|
||||||
job_row_number=100,
|
job_row_number=100,
|
||||||
status='permanent-failure'
|
status='permanent-failure'
|
||||||
)
|
)
|
||||||
expected_resp = {
|
|
||||||
"recipient": "+447700900855",
|
|
||||||
"row_number": 101,
|
|
||||||
"template_name": "Template Name",
|
|
||||||
"template_type": "sms",
|
|
||||||
"created_at": "Monday 27 March 2017 at 00:01",
|
|
||||||
"job_name": "some.csv",
|
|
||||||
"status": "Phone number doesn’t exist"
|
|
||||||
}
|
|
||||||
|
|
||||||
serialized = notification.serialize_for_csv()
|
serialized = notification.serialize_for_csv()
|
||||||
assert serialized == expected_resp
|
assert serialized['created_at'] == 'Monday 27 March 2017 at 00:01'
|
||||||
|
|||||||
Reference in New Issue
Block a user