mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-31 23:26:23 -05:00
Improvements to the tests.
Update AuthError with a to_dict_v2 method.
This commit is contained in:
@@ -30,8 +30,9 @@ def test_create_content_for_notification_fails_with_missing_personalisation(samp
|
||||
|
||||
def test_create_content_for_notification_fails_with_additional_personalisation(sample_template_with_placeholders):
|
||||
template = Template.query.get(sample_template_with_placeholders.id)
|
||||
with pytest.raises(BadRequestError):
|
||||
create_content_for_notification(template, {'name': 'Bobbhy', 'Additional': 'Data'})
|
||||
with pytest.raises(BadRequestError) as e:
|
||||
create_content_for_notification(template, {'name': 'Bobby', 'Additional placeholder': 'Data'})
|
||||
assert e.value.message == 'Template personalisation not needed for template: Additional placeholder'
|
||||
|
||||
|
||||
def test_persist_notification_creates_and_save_to_db(sample_template, sample_api_key):
|
||||
@@ -41,7 +42,7 @@ def test_persist_notification_creates_and_save_to_db(sample_template, sample_api
|
||||
sample_template.service.id, {}, 'sms', sample_api_key.id,
|
||||
sample_api_key.key_type)
|
||||
assert Notification.query.count() == 1
|
||||
assert Notification.query.get(notification.id).__eq__(notification)
|
||||
assert Notification.query.get(notification.id) is not None
|
||||
assert NotificationHistory.query.count() == 1
|
||||
|
||||
|
||||
|
||||
@@ -97,17 +97,15 @@ def test_service_can_send_to_recipient_passes_for_live_service_non_team_member(k
|
||||
live_service) is None
|
||||
|
||||
|
||||
@pytest.mark.parametrize('key_type',
|
||||
['team'])
|
||||
def test_service_can_send_to_recipient_passes_for_whitelisted_recipient_passes(key_type, notify_db, notify_db_session,
|
||||
def test_service_can_send_to_recipient_passes_for_whitelisted_recipient_passes(notify_db, notify_db_session,
|
||||
sample_service):
|
||||
sample_service_whitelist(notify_db, notify_db_session, email_address="some_other_email@test.com")
|
||||
assert service_can_send_to_recipient("some_other_email@test.com",
|
||||
key_type,
|
||||
'team',
|
||||
sample_service) is None
|
||||
sample_service_whitelist(notify_db, notify_db_session, mobile_number='07513332413')
|
||||
assert service_can_send_to_recipient('07513332413',
|
||||
key_type,
|
||||
'team',
|
||||
sample_service) is None
|
||||
|
||||
|
||||
@@ -120,9 +118,9 @@ def test_service_can_send_to_recipient_fails_when_recipient_is_not_on_team(recip
|
||||
notify_db, notify_db_session):
|
||||
trial_mode_service = create_service(notify_db, notify_db_session, service_name='trial mode', restricted=True)
|
||||
with pytest.raises(BadRequestError) as exec_info:
|
||||
assert service_can_send_to_recipient(recipient,
|
||||
key_type,
|
||||
trial_mode_service) is None
|
||||
service_can_send_to_recipient(recipient,
|
||||
key_type,
|
||||
trial_mode_service)
|
||||
assert exec_info.value.status_code == 400
|
||||
assert exec_info.value.code == 10400
|
||||
assert exec_info.value.message == error_message
|
||||
@@ -133,9 +131,9 @@ def test_service_can_send_to_recipient_fails_when_recipient_is_not_on_team(recip
|
||||
def test_service_can_send_to_recipient_fails_when_mobile_number_is_not_on_team(notify_db, notify_db_session):
|
||||
live_service = create_service(notify_db, notify_db_session, service_name='live mode', restricted=False)
|
||||
with pytest.raises(BadRequestError) as e:
|
||||
assert service_can_send_to_recipient("0758964221",
|
||||
'team',
|
||||
live_service) is None
|
||||
service_can_send_to_recipient("0758964221",
|
||||
'team',
|
||||
live_service)
|
||||
assert e.value.status_code == 400
|
||||
assert e.value.code == 10400
|
||||
assert e.value.message == 'Can’t send to this recipient using a team-only API key'
|
||||
|
||||
Reference in New Issue
Block a user