mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-23 00:41:35 -05:00
- Refactor version 1 of post notificaitons to use the common persist_notificaiton and send_notification_to_queue methods.
- It would be nice to refactor the send_sms and send_email tasks to use these common functions as well, that way I can get rid of the new Notifications.from_v2_api_request method. - Still not happy with the format of the errors. Would like to find a happy place, where the message is descript enough that we do not need external documentation to explain the error. Perhaps we still only need documentation to explain the trial mode concept.
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import pytest
|
||||
|
||||
from app.errors import InvalidRequest
|
||||
from app.notifications.validators import check_service_message_limit, check_template_is_for_notification_type, \
|
||||
check_template_is_active, service_can_send_to_recipient, check_sms_content_char_count
|
||||
from app.v2.errors import BadRequestError, TooManyRequestsError
|
||||
@@ -53,7 +52,7 @@ def test_check_template_is_active_passes(sample_template):
|
||||
assert check_template_is_active(sample_template) is None
|
||||
|
||||
|
||||
def test_check_template_is_active_passes(sample_template):
|
||||
def test_check_template_is_active_fails(sample_template):
|
||||
sample_template.archived = True
|
||||
from app.dao.templates_dao import dao_update_template
|
||||
dao_update_template(sample_template)
|
||||
@@ -64,7 +63,6 @@ def test_check_template_is_active_passes(sample_template):
|
||||
assert e.code == '10400'
|
||||
assert e.message == 'Template has been deleted'
|
||||
assert e.link == "link to documentation"
|
||||
assert e.fields[0]["template"] == "has been deleted"
|
||||
|
||||
|
||||
@pytest.mark.parametrize('key_type',
|
||||
@@ -73,12 +71,10 @@ def test_service_can_send_to_recipient_passes(key_type, notify_db, notify_db_ses
|
||||
trial_mode_service = create_service(notify_db, notify_db_session, service_name='trial mode', restricted=True)
|
||||
assert service_can_send_to_recipient(trial_mode_service.users[0].email_address,
|
||||
key_type,
|
||||
trial_mode_service,
|
||||
"email") is None
|
||||
trial_mode_service) is None
|
||||
assert service_can_send_to_recipient(trial_mode_service.users[0].mobile_number,
|
||||
key_type,
|
||||
trial_mode_service,
|
||||
"sms") is None
|
||||
trial_mode_service) is None
|
||||
|
||||
|
||||
@pytest.mark.parametrize('key_type',
|
||||
@@ -87,12 +83,10 @@ def test_service_can_send_to_recipient_passes_for_live_service_non_team_member(k
|
||||
live_service = create_service(notify_db, notify_db_session, service_name='live', restricted=False)
|
||||
assert service_can_send_to_recipient("some_other_email@test.com",
|
||||
key_type,
|
||||
live_service,
|
||||
"email") is None
|
||||
live_service) is None
|
||||
assert service_can_send_to_recipient('07513332413',
|
||||
key_type,
|
||||
live_service,
|
||||
"sms") is None
|
||||
live_service) is None
|
||||
|
||||
|
||||
@pytest.mark.parametrize('key_type',
|
||||
@@ -102,13 +96,11 @@ def test_service_can_send_to_recipient_passes_for_whitelisted_recipient_passes(k
|
||||
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,
|
||||
sample_service,
|
||||
"email") is None
|
||||
sample_service) is None
|
||||
sample_service_whitelist(notify_db, notify_db_session, mobile_number='07513332413')
|
||||
assert service_can_send_to_recipient('07513332413',
|
||||
key_type,
|
||||
sample_service,
|
||||
"sms") is None
|
||||
sample_service) is None
|
||||
|
||||
|
||||
@pytest.mark.parametrize('key_type',
|
||||
@@ -118,13 +110,11 @@ def test_service_can_send_to_recipient_fails_when_recipient_is_not_on_team(key_t
|
||||
with pytest.raises(BadRequestError):
|
||||
assert service_can_send_to_recipient("some_other_email@test.com",
|
||||
key_type,
|
||||
trial_mode_service,
|
||||
"email") is None
|
||||
trial_mode_service) is None
|
||||
with pytest.raises(BadRequestError):
|
||||
assert service_can_send_to_recipient('07513332413',
|
||||
key_type,
|
||||
trial_mode_service,
|
||||
"sms") is None
|
||||
trial_mode_service) is None
|
||||
|
||||
|
||||
def test_service_can_send_to_recipient_fails_when_mobile_number_is_not_on_team(notify_db, notify_db_session):
|
||||
@@ -132,8 +122,7 @@ def test_service_can_send_to_recipient_fails_when_mobile_number_is_not_on_team(n
|
||||
with pytest.raises(BadRequestError):
|
||||
assert service_can_send_to_recipient("0758964221",
|
||||
'team',
|
||||
live_service,
|
||||
"sms") is None
|
||||
live_service) is None
|
||||
|
||||
|
||||
@pytest.mark.parametrize('char_count', [495, 0, 494, 200])
|
||||
|
||||
Reference in New Issue
Block a user