mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-04 05:30:53 -04:00
Merge branch 'master' into async-job-stats
This commit is contained in:
@@ -311,6 +311,8 @@ def test_should_by_able_to_update_status_by_id(sample_template, sample_job, mmg_
|
||||
data = _notification_json(sample_template, job_id=sample_job.id, status='sending')
|
||||
notification = Notification(**data)
|
||||
dao_create_notification(notification)
|
||||
assert notification._status_enum == 'sending'
|
||||
assert notification._status_fkey == 'sending'
|
||||
|
||||
assert Notification.query.get(notification.id).status == 'sending'
|
||||
|
||||
@@ -321,6 +323,8 @@ def test_should_by_able_to_update_status_by_id(sample_template, sample_job, mmg_
|
||||
assert updated.updated_at == datetime(2000, 1, 2, 12, 0, 0)
|
||||
assert Notification.query.get(notification.id).status == 'delivered'
|
||||
assert notification.updated_at == datetime(2000, 1, 2, 12, 0, 0)
|
||||
assert notification._status_enum == 'delivered'
|
||||
assert notification._status_fkey == 'delivered'
|
||||
|
||||
|
||||
def test_should_not_update_status_by_id_if_not_sending_and_does_not_update_job(notify_db, notify_db_session):
|
||||
@@ -825,7 +829,7 @@ def test_get_notification_billable_unit_count_per_month(notify_db, notify_db_ses
|
||||
) == months
|
||||
|
||||
|
||||
def test_update_notification(sample_notification, sample_template):
|
||||
def test_update_notification(sample_notification):
|
||||
assert sample_notification.status == 'created'
|
||||
sample_notification.status = 'failed'
|
||||
dao_update_notification(sample_notification)
|
||||
@@ -833,6 +837,37 @@ def test_update_notification(sample_notification, sample_template):
|
||||
assert notification_from_db.status == 'failed'
|
||||
|
||||
|
||||
def test_update_notification_with_no_notification_status(sample_notification):
|
||||
# specifically, it has an old enum status, but not a new status (because the upgrade script has just run)
|
||||
update_dict = {'_status_enum': 'created', '_status_fkey': None}
|
||||
Notification.query.filter(Notification.id == sample_notification.id).update(update_dict)
|
||||
|
||||
# now lets update the status to failed - both columns should now be populated
|
||||
sample_notification.status = 'failed'
|
||||
dao_update_notification(sample_notification)
|
||||
|
||||
notification_from_db = Notification.query.get(sample_notification.id)
|
||||
assert notification_from_db.status == 'failed'
|
||||
assert notification_from_db._status_enum == 'failed'
|
||||
assert notification_from_db._status_fkey == 'failed'
|
||||
|
||||
|
||||
def test_updating_notification_with_no_notification_status_updates_notification_history(sample_notification):
|
||||
# same as above, but with notification history
|
||||
update_dict = {'_status_enum': 'created', '_status_fkey': None}
|
||||
Notification.query.filter(Notification.id == sample_notification.id).update(update_dict)
|
||||
NotificationHistory.query.filter(NotificationHistory.id == sample_notification.id).update(update_dict)
|
||||
|
||||
# now lets update the notification's status to failed - both columns should now be populated on the history object
|
||||
sample_notification.status = 'failed'
|
||||
dao_update_notification(sample_notification)
|
||||
|
||||
hist_from_db = NotificationHistory.query.get(sample_notification.id)
|
||||
assert hist_from_db.status == 'failed'
|
||||
assert hist_from_db._status_enum == 'failed'
|
||||
assert hist_from_db._status_fkey == 'failed'
|
||||
|
||||
|
||||
@freeze_time("2016-01-10 12:00:00.000000")
|
||||
def test_should_delete_notifications_after_seven_days(notify_db, notify_db_session):
|
||||
assert len(Notification.query.all()) == 0
|
||||
|
||||
@@ -447,6 +447,25 @@ def test_get_all_notifications_for_job_filtered_by_status(
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
def test_get_all_notifications_for_job_returns_correct_format(
|
||||
client,
|
||||
sample_notification_with_job
|
||||
):
|
||||
service_id = sample_notification_with_job.service_id
|
||||
job_id = sample_notification_with_job.job_id
|
||||
response = client.get(
|
||||
path='/service/{}/job/{}/notifications'.format(service_id, job_id),
|
||||
headers=[create_authorization_header()]
|
||||
)
|
||||
assert response.status_code == 200
|
||||
resp = json.loads(response.get_data(as_text=True))
|
||||
assert len(resp['notifications']) == 1
|
||||
assert resp['notifications'][0]['id'] == str(sample_notification_with_job.id)
|
||||
assert resp['notifications'][0]['status'] == sample_notification_with_job.status
|
||||
assert '_status_fkey' not in resp['notifications'][0]
|
||||
assert '_status_enum' not in resp['notifications'][0]
|
||||
|
||||
|
||||
def test_get_job_by_id(notify_api, sample_job):
|
||||
job_id = str(sample_job.id)
|
||||
service_id = sample_job.service.id
|
||||
|
||||
@@ -1240,17 +1240,16 @@ def test_get_monthly_notification_stats(mocker, client, sample_service, url, exp
|
||||
assert json.loads(response.get_data(as_text=True)) == expected_json
|
||||
|
||||
|
||||
def test_get_services_with_detailed_flag(notify_api, notify_db, notify_db_session):
|
||||
def test_get_services_with_detailed_flag(client, notify_db, notify_db_session):
|
||||
notifications = [
|
||||
create_sample_notification(notify_db, notify_db_session),
|
||||
create_sample_notification(notify_db, notify_db_session),
|
||||
create_sample_notification(notify_db, notify_db_session, key_type=KEY_TYPE_TEST)
|
||||
]
|
||||
with notify_api.test_request_context(), notify_api.test_client() as client:
|
||||
resp = client.get(
|
||||
'/service?detailed=True',
|
||||
headers=[create_authorization_header()]
|
||||
)
|
||||
resp = client.get(
|
||||
'/service?detailed=True',
|
||||
headers=[create_authorization_header()]
|
||||
)
|
||||
|
||||
assert resp.status_code == 200
|
||||
data = json.loads(resp.get_data(as_text=True))['data']
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import pytest
|
||||
|
||||
from marshmallow import ValidationError
|
||||
from sqlalchemy import desc
|
||||
|
||||
@@ -33,6 +32,22 @@ def test_notification_schema_adds_api_key_name(sample_notification_with_api_key)
|
||||
assert data['key_name'] == 'Test key'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('schema_name', [
|
||||
'notification_with_template_schema',
|
||||
'notification_schema',
|
||||
'notification_with_template_schema',
|
||||
'notification_with_personalisation_schema',
|
||||
])
|
||||
def test_notification_schema_has_correct_status(sample_notification, schema_name):
|
||||
from app import schemas
|
||||
|
||||
data = getattr(schemas, schema_name).dump(sample_notification).data
|
||||
|
||||
assert data['status'] == sample_notification.status
|
||||
assert '_status_enum' not in data
|
||||
assert '_status_fkey' not in data
|
||||
|
||||
|
||||
@pytest.mark.parametrize('user_attribute, user_value', [
|
||||
('name', 'New User'),
|
||||
('email_address', 'newuser@mail.com'),
|
||||
|
||||
@@ -131,10 +131,15 @@ def test_post_sms_schema_with_personalisation_that_is_not_a_dict():
|
||||
assert len(error.keys()) == 2
|
||||
|
||||
|
||||
@pytest.mark.parametrize('invalid_phone_number, err_msg',
|
||||
[('08515111111', 'phone_number Not a UK mobile number'),
|
||||
('07515111*11', 'phone_number Must not contain letters or symbols'),
|
||||
('notaphoneumber', 'phone_number Must not contain letters or symbols')])
|
||||
@pytest.mark.parametrize('invalid_phone_number, err_msg', [
|
||||
('08515111111', 'phone_number Not a UK mobile number'),
|
||||
('07515111*11', 'phone_number Must not contain letters or symbols'),
|
||||
('notaphoneumber', 'phone_number Must not contain letters or symbols'),
|
||||
(7700900001, 'phone_number 7700900001 is not of type string'),
|
||||
(None, 'phone_number None is not of type string'),
|
||||
([], 'phone_number [] is not of type string'),
|
||||
({}, 'phone_number {} is not of type string'),
|
||||
])
|
||||
def test_post_sms_request_schema_invalid_phone_number(invalid_phone_number, err_msg):
|
||||
j = {"phone_number": invalid_phone_number,
|
||||
"template_id": str(uuid.uuid4())
|
||||
@@ -213,12 +218,22 @@ def test_post_email_schema_bad_uuid_and_missing_email_address():
|
||||
validate(j, post_email_request_schema)
|
||||
|
||||
|
||||
def test_post_email_schema_invalid_email_address():
|
||||
j = {"template_id": str(uuid.uuid4()),
|
||||
"email_address": "notavalidemail@address"}
|
||||
with pytest.raises(ValidationError):
|
||||
@pytest.mark.parametrize('email_address, err_msg', [
|
||||
('example', 'email_address Not a valid email address'),
|
||||
(12345, 'email_address 12345 is not of type string'),
|
||||
(None, 'email_address None is not of type string'),
|
||||
([], 'email_address [] is not of type string'),
|
||||
({}, 'email_address {} is not of type string'),
|
||||
])
|
||||
def test_post_email_schema_invalid_email_address(email_address, err_msg):
|
||||
j = {"template_id": str(uuid.uuid4()), "email_address": email_address}
|
||||
with pytest.raises(ValidationError) as e:
|
||||
validate(j, post_email_request_schema)
|
||||
|
||||
errors = json.loads(str(e.value)).get('errors')
|
||||
assert len(errors) == 1
|
||||
assert {"error": "ValidationError", "message": err_msg} == errors[0]
|
||||
|
||||
|
||||
def valid_email_response():
|
||||
return {
|
||||
|
||||
@@ -76,7 +76,8 @@ def notify_db_session(notify_db):
|
||||
"job_status",
|
||||
"provider_details_history",
|
||||
"template_process_type",
|
||||
"dvla_organisation"]:
|
||||
"dvla_organisation",
|
||||
"notification_status_types"]:
|
||||
notify_db.engine.execute(tbl.delete())
|
||||
notify_db.session.commit()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user