mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-02 17:48:36 -04:00
Fix PEP8 issues
This commit is contained in:
@@ -144,6 +144,7 @@ EMAIL_TYPE = 'email'
|
|||||||
WHITELIST_RECIPIENT_TYPE = [MOBILE_TYPE, EMAIL_TYPE]
|
WHITELIST_RECIPIENT_TYPE = [MOBILE_TYPE, EMAIL_TYPE]
|
||||||
whitelist_recipient_types = db.Enum(*WHITELIST_RECIPIENT_TYPE, name='recipient_type')
|
whitelist_recipient_types = db.Enum(*WHITELIST_RECIPIENT_TYPE, name='recipient_type')
|
||||||
|
|
||||||
|
|
||||||
class ServiceWhitelist(db.Model):
|
class ServiceWhitelist(db.Model):
|
||||||
__tablename__ = 'service_whitelist'
|
__tablename__ = 'service_whitelist'
|
||||||
|
|
||||||
|
|||||||
@@ -254,7 +254,8 @@ def send_notification(notification_type):
|
|||||||
notification['to'],
|
notification['to'],
|
||||||
itertools.chain(
|
itertools.chain(
|
||||||
itertools.chain.from_iterable([user.mobile_number, user.email_address] for user in service.users),
|
itertools.chain.from_iterable([user.mobile_number, user.email_address] for user in service.users),
|
||||||
([member.recipient for member in service.whitelist]) if api_user.key_type == KEY_TYPE_NORMAL else iter([])
|
([member.recipient for member in service.whitelist])
|
||||||
|
if api_user.key_type == KEY_TYPE_NORMAL else iter([])
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)):
|
)):
|
||||||
|
|||||||
@@ -1004,12 +1004,11 @@ def test_should_not_persist_notification_or_send_sms_if_simulated_number(
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('to_sms', ['07827992635'])
|
@pytest.mark.parametrize('to_sms', ['07827992635'])
|
||||||
def test_should_not_send_sms_to_non_whitelist_recipient_in_trial_mode_with_live_key(
|
def test_should_not_send_sms_to_non_whitelist_recipient_in_trial_mode_with_live_key(client,
|
||||||
client,
|
notify_db,
|
||||||
notify_db,
|
notify_db_session,
|
||||||
notify_db_session,
|
to_sms,
|
||||||
to_sms,
|
mocker):
|
||||||
mocker):
|
|
||||||
apply_async = mocker.patch('app.celery.provider_tasks.send_sms_to_provider.apply_async')
|
apply_async = mocker.patch('app.celery.provider_tasks.send_sms_to_provider.apply_async')
|
||||||
service = create_sample_service(notify_db, notify_db_session, limit=2, restricted=True)
|
service = create_sample_service(notify_db, notify_db_session, limit=2, restricted=True)
|
||||||
service_whitelist = create_sample_service_whitelist(notify_db, notify_db_session, service=service)
|
service_whitelist = create_sample_service_whitelist(notify_db, notify_db_session, service=service)
|
||||||
@@ -1044,13 +1043,13 @@ def test_should_not_send_sms_to_non_whitelist_recipient_in_trial_mode_with_live_
|
|||||||
assert expected_response_message in json_resp['message']['to']
|
assert expected_response_message in json_resp['message']['to']
|
||||||
apply_async.assert_not_called()
|
apply_async.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('to_email', ['non_whitelist_recipient@mail.com'])
|
@pytest.mark.parametrize('to_email', ['non_whitelist_recipient@mail.com'])
|
||||||
def test_should_not_send_email_to_non_whitelist_recipient_in_trial_mode_with_live_key(
|
def test_should_not_send_email_to_non_whitelist_recipient_in_trial_mode_with_live_key(client,
|
||||||
client,
|
notify_db,
|
||||||
notify_db,
|
notify_db_session,
|
||||||
notify_db_session,
|
to_email,
|
||||||
to_email,
|
mocker):
|
||||||
mocker):
|
|
||||||
apply_async = mocker.patch('app.celery.provider_tasks.send_email_to_provider.apply_async')
|
apply_async = mocker.patch('app.celery.provider_tasks.send_email_to_provider.apply_async')
|
||||||
service = create_sample_service(notify_db, notify_db_session, limit=2, restricted=True)
|
service = create_sample_service(notify_db, notify_db_session, limit=2, restricted=True)
|
||||||
service_whitelist = create_sample_service_whitelist(notify_db, notify_db_session, service=service)
|
service_whitelist = create_sample_service_whitelist(notify_db, notify_db_session, service=service)
|
||||||
@@ -1087,15 +1086,15 @@ def test_should_not_send_email_to_non_whitelist_recipient_in_trial_mode_with_liv
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('to_sms', ['07827992635'])
|
@pytest.mark.parametrize('to_sms', ['07827992635'])
|
||||||
def test_should_not_send_sms_to_whitelist_recipient_in_trial_mode_with_team_key(
|
def test_should_not_send_sms_to_whitelist_recipient_in_trial_mode_with_team_key(client,
|
||||||
client,
|
notify_db,
|
||||||
notify_db,
|
notify_db_session,
|
||||||
notify_db_session,
|
to_sms,
|
||||||
to_sms,
|
mocker):
|
||||||
mocker):
|
|
||||||
apply_async = mocker.patch('app.celery.provider_tasks.send_sms_to_provider.apply_async')
|
apply_async = mocker.patch('app.celery.provider_tasks.send_sms_to_provider.apply_async')
|
||||||
service = create_sample_service(notify_db, notify_db_session, limit=2, restricted=True)
|
service = create_sample_service(notify_db, notify_db_session, limit=2, restricted=True)
|
||||||
service_whitelist = create_sample_service_whitelist(notify_db, notify_db_session, service=service, mobile_number=to_sms)
|
service_whitelist = create_sample_service_whitelist(notify_db, notify_db_session,
|
||||||
|
service=service, mobile_number=to_sms)
|
||||||
sms_template = create_sample_template(notify_db, notify_db_session, service=service)
|
sms_template = create_sample_template(notify_db, notify_db_session, service=service)
|
||||||
|
|
||||||
assert service_whitelist.service_id == service.id
|
assert service_whitelist.service_id == service.id
|
||||||
@@ -1124,15 +1123,15 @@ def test_should_not_send_sms_to_whitelist_recipient_in_trial_mode_with_team_key(
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('to_email', ['non_whitelist_recipient@mail.com'])
|
@pytest.mark.parametrize('to_email', ['non_whitelist_recipient@mail.com'])
|
||||||
def test_should_not_send_email_to_whitelist_recipient_in_trial_mode_with_team_key(
|
def test_should_not_send_email_to_whitelist_recipient_in_trial_mode_with_team_key(client,
|
||||||
client,
|
notify_db,
|
||||||
notify_db,
|
notify_db_session,
|
||||||
notify_db_session,
|
to_email,
|
||||||
to_email,
|
mocker):
|
||||||
mocker):
|
|
||||||
apply_async = mocker.patch('app.celery.provider_tasks.send_sms_to_provider.apply_async')
|
apply_async = mocker.patch('app.celery.provider_tasks.send_sms_to_provider.apply_async')
|
||||||
service = create_sample_service(notify_db, notify_db_session, limit=2, restricted=True)
|
service = create_sample_service(notify_db, notify_db_session, limit=2, restricted=True)
|
||||||
service_whitelist = create_sample_service_whitelist(notify_db, notify_db_session, service=service, email_address=to_email)
|
service_whitelist = create_sample_service_whitelist(notify_db, notify_db_session,
|
||||||
|
service=service, email_address=to_email)
|
||||||
email_template = create_sample_email_template(notify_db, notify_db_session, service=service)
|
email_template = create_sample_email_template(notify_db, notify_db_session, service=service)
|
||||||
|
|
||||||
assert service_whitelist.service_id == service.id
|
assert service_whitelist.service_id == service.id
|
||||||
@@ -1161,16 +1160,16 @@ def test_should_not_send_email_to_whitelist_recipient_in_trial_mode_with_team_ke
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('to_sms', ['07123123123'])
|
@pytest.mark.parametrize('to_sms', ['07123123123'])
|
||||||
def test_should_send_sms_to_whitelist_recipient_in_trial_mode_with_live_key(
|
def test_should_send_sms_to_whitelist_recipient_in_trial_mode_with_live_key(client,
|
||||||
client,
|
notify_db,
|
||||||
notify_db,
|
notify_db_session,
|
||||||
notify_db_session,
|
to_sms,
|
||||||
to_sms,
|
mocker):
|
||||||
mocker):
|
|
||||||
apply_async = mocker.patch('app.celery.provider_tasks.send_sms_to_provider.apply_async')
|
apply_async = mocker.patch('app.celery.provider_tasks.send_sms_to_provider.apply_async')
|
||||||
|
|
||||||
service = create_sample_service(notify_db, notify_db_session, limit=2, restricted=True)
|
service = create_sample_service(notify_db, notify_db_session, limit=2, restricted=True)
|
||||||
service_whitelist = create_sample_service_whitelist(notify_db, notify_db_session, service=service, mobile_number=to_sms)
|
service_whitelist = create_sample_service_whitelist(notify_db, notify_db_session,
|
||||||
|
service=service, mobile_number=to_sms)
|
||||||
sms_template = create_sample_template(notify_db, notify_db_session, service=service)
|
sms_template = create_sample_template(notify_db, notify_db_session, service=service)
|
||||||
|
|
||||||
assert service_whitelist.service_id == service.id
|
assert service_whitelist.service_id == service.id
|
||||||
@@ -1200,16 +1199,16 @@ def test_should_send_sms_to_whitelist_recipient_in_trial_mode_with_live_key(
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('to_email', ['whitelist_recipient@mail.com'])
|
@pytest.mark.parametrize('to_email', ['whitelist_recipient@mail.com'])
|
||||||
def test_should_send_email_to_whitelist_recipient_in_trial_mode_with_live_key(
|
def test_should_send_email_to_whitelist_recipient_in_trial_mode_with_live_key(client,
|
||||||
client,
|
notify_db,
|
||||||
notify_db,
|
notify_db_session,
|
||||||
notify_db_session,
|
to_email,
|
||||||
to_email,
|
mocker):
|
||||||
mocker):
|
|
||||||
apply_async = mocker.patch('app.celery.provider_tasks.send_email_to_provider.apply_async')
|
apply_async = mocker.patch('app.celery.provider_tasks.send_email_to_provider.apply_async')
|
||||||
|
|
||||||
service = create_sample_service(notify_db, notify_db_session, limit=2, restricted=True)
|
service = create_sample_service(notify_db, notify_db_session, limit=2, restricted=True)
|
||||||
service_whitelist = create_sample_service_whitelist(notify_db, notify_db_session, service=service, email_address=to_email)
|
service_whitelist = create_sample_service_whitelist(notify_db, notify_db_session,
|
||||||
|
service=service, email_address=to_email)
|
||||||
email_template = create_sample_email_template(notify_db, notify_db_session, service=service)
|
email_template = create_sample_email_template(notify_db, notify_db_session, service=service)
|
||||||
|
|
||||||
assert service_whitelist.service_id == service.id
|
assert service_whitelist.service_id == service.id
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ def test_get_whitelist_returns_data(client, sample_service_whitelist):
|
|||||||
'phone_numbers': []
|
'phone_numbers': []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def test_get_whitelist_separates_emails_and_phones(client, sample_service):
|
def test_get_whitelist_separates_emails_and_phones(client, sample_service):
|
||||||
dao_add_and_commit_whitelisted_contacts([
|
dao_add_and_commit_whitelisted_contacts([
|
||||||
ServiceWhitelist.from_string(sample_service.id, EMAIL_TYPE, 'service@example.com'),
|
ServiceWhitelist.from_string(sample_service.id, EMAIL_TYPE, 'service@example.com'),
|
||||||
@@ -71,6 +72,7 @@ def test_update_whitelist_replaces_old_whitelist(client, sample_service_whitelis
|
|||||||
assert whitelist[0].recipient == '07123456789'
|
assert whitelist[0].recipient == '07123456789'
|
||||||
assert whitelist[1].recipient == 'foo@bar.com'
|
assert whitelist[1].recipient == 'foo@bar.com'
|
||||||
|
|
||||||
|
|
||||||
def test_update_whitelist_doesnt_remove_old_whitelist_if_error(client, sample_service_whitelist):
|
def test_update_whitelist_doesnt_remove_old_whitelist_if_error(client, sample_service_whitelist):
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
|
|||||||
Reference in New Issue
Block a user