mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 18:31:13 -05:00
Revert "ensure we're passing through api keys and key types from notifications"
This reverts commit 25d1777937.
This commit is contained in:
@@ -124,14 +124,7 @@ def process_row(row_number, recipient, personalisation, template, job, service):
|
|||||||
|
|
||||||
|
|
||||||
def send_notification_to_persist_queue(
|
def send_notification_to_persist_queue(
|
||||||
notification_id,
|
notification_id, service, template_type, encrypted, priority=False, research_mode=False
|
||||||
service,
|
|
||||||
template_type,
|
|
||||||
encrypted,
|
|
||||||
api_key_id,
|
|
||||||
key_type,
|
|
||||||
priority=False,
|
|
||||||
research_mode=False
|
|
||||||
):
|
):
|
||||||
queues = {
|
queues = {
|
||||||
SMS_TYPE: 'db-sms',
|
SMS_TYPE: 'db-sms',
|
||||||
@@ -156,12 +149,8 @@ def send_notification_to_persist_queue(
|
|||||||
str(service.id),
|
str(service.id),
|
||||||
notification_id,
|
notification_id,
|
||||||
encrypted,
|
encrypted,
|
||||||
datetime.utcnow().strftime(DATETIME_FORMAT),
|
datetime.utcnow().strftime(DATETIME_FORMAT)
|
||||||
),
|
),
|
||||||
kwargs={
|
|
||||||
'api_key_id': api_key_id,
|
|
||||||
'key_type': key_type
|
|
||||||
},
|
|
||||||
queue=queue_name
|
queue=queue_name
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -147,14 +147,12 @@ def send_notification(notification_type):
|
|||||||
|
|
||||||
if not simulated:
|
if not simulated:
|
||||||
tasks.send_notification_to_persist_queue(
|
tasks.send_notification_to_persist_queue(
|
||||||
notification_id=notification_model.id,
|
notification_model.id,
|
||||||
service=service,
|
service,
|
||||||
template_type=template.template_type,
|
template.template_type,
|
||||||
encrypted=encrypted,
|
encrypted,
|
||||||
api_key_id=str(notification_model.api_key_id),
|
template.process_type == PRIORITY,
|
||||||
key_type=api_user.key_type,
|
service.research_mode or api_user.key_type == KEY_TYPE_TEST
|
||||||
priority=template.process_type == PRIORITY,
|
|
||||||
research_mode=service.research_mode or api_user.key_type == KEY_TYPE_TEST
|
|
||||||
)
|
)
|
||||||
# queue_name = 'notify' if template.process_type == PRIORITY else None
|
# queue_name = 'notify' if template.process_type == PRIORITY else None
|
||||||
# send_notification_to_queue(notification=notification_model,
|
# send_notification_to_queue(notification=notification_model,
|
||||||
|
|||||||
@@ -68,14 +68,12 @@ def post_notification(notification_type):
|
|||||||
|
|
||||||
if not simulated:
|
if not simulated:
|
||||||
tasks.send_notification_to_persist_queue(
|
tasks.send_notification_to_persist_queue(
|
||||||
notification_id=notification.id,
|
notification.id,
|
||||||
service=service,
|
service,
|
||||||
template_type=template.template_type,
|
template.template_type,
|
||||||
encrypted=encrypted,
|
encrypted,
|
||||||
api_key_id=str(notification.api_key_id),
|
template.process_type == PRIORITY,
|
||||||
key_type=api_user.key_type,
|
service.research_mode or api_user.key_type == KEY_TYPE_TEST
|
||||||
priority=template.process_type == PRIORITY,
|
|
||||||
research_mode=service.research_mode or api_user.key_type == KEY_TYPE_TEST
|
|
||||||
)
|
)
|
||||||
# not doing this during paas migration
|
# not doing this during paas migration
|
||||||
# queue_name = 'notify' if template.process_type == PRIORITY else None
|
# queue_name = 'notify' if template.process_type == PRIORITY else None
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import uuid
|
import uuid
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from unittest.mock import Mock, ANY
|
from unittest.mock import Mock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
@@ -65,22 +65,17 @@ def test_should_have_decorated_tasks_functions():
|
|||||||
def email_job_with_placeholders(notify_db, notify_db_session, sample_email_template_with_placeholders):
|
def email_job_with_placeholders(notify_db, notify_db_session, sample_email_template_with_placeholders):
|
||||||
return sample_job(notify_db, notify_db_session, template=sample_email_template_with_placeholders)
|
return sample_job(notify_db, notify_db_session, template=sample_email_template_with_placeholders)
|
||||||
|
|
||||||
# --- send_notification_to_persist_queue tests -- #
|
|
||||||
|
|
||||||
|
|
||||||
@freeze_time("2016-01-01 11:09:00.061258")
|
@freeze_time("2016-01-01 11:09:00.061258")
|
||||||
def test_should_put_sms_messages_in_db_sms_queue(sample_service, sample_template, mocker):
|
def test_should_put_sms_messages_in_db_sms_queue(sample_service, sample_template, mocker):
|
||||||
mocker.patch('app.celery.tasks.send_sms.apply_async')
|
mocker.patch('app.celery.tasks.send_sms.apply_async')
|
||||||
send_notification_to_persist_queue(
|
send_notification_to_persist_queue("notification-id", sample_service, sample_template.template_type, "encrypted")
|
||||||
'notification-id', sample_service, sample_template.template_type, 'encrypted', 'api_key_id', 'key_type'
|
|
||||||
)
|
|
||||||
|
|
||||||
tasks.send_sms.apply_async.assert_called_once_with(
|
tasks.send_sms.apply_async.assert_called_once_with(
|
||||||
(str(sample_service.id),
|
(str(sample_service.id),
|
||||||
"notification-id",
|
"notification-id",
|
||||||
"encrypted",
|
"encrypted",
|
||||||
"2016-01-01T11:09:00.061258Z"),
|
"2016-01-01T11:09:00.061258Z"),
|
||||||
kwargs=ANY,
|
|
||||||
queue="db-sms"
|
queue="db-sms"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -89,8 +84,7 @@ def test_should_put_sms_messages_in_db_sms_queue(sample_service, sample_template
|
|||||||
def test_should_put_messages_in_priority_queue(sample_service, sample_template, mocker):
|
def test_should_put_messages_in_priority_queue(sample_service, sample_template, mocker):
|
||||||
mocker.patch('app.celery.tasks.send_sms.apply_async')
|
mocker.patch('app.celery.tasks.send_sms.apply_async')
|
||||||
send_notification_to_persist_queue(
|
send_notification_to_persist_queue(
|
||||||
'notification-id', sample_service, sample_template.template_type, 'encrypted', 'api_key_id', 'key_type',
|
"notification-id", sample_service, sample_template.template_type, "encrypted", True
|
||||||
priority=True
|
|
||||||
)
|
)
|
||||||
|
|
||||||
tasks.send_sms.apply_async.assert_called_once_with(
|
tasks.send_sms.apply_async.assert_called_once_with(
|
||||||
@@ -98,47 +92,15 @@ def test_should_put_messages_in_priority_queue(sample_service, sample_template,
|
|||||||
"notification-id",
|
"notification-id",
|
||||||
"encrypted",
|
"encrypted",
|
||||||
"2016-01-01T11:09:00.061258Z"),
|
"2016-01-01T11:09:00.061258Z"),
|
||||||
kwargs=ANY,
|
|
||||||
queue="notify"
|
queue="notify"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@freeze_time("2016-01-01 11:09:00.061258")
|
|
||||||
def test_should_pass_through_api_key_info(sample_service, sample_template, mocker):
|
|
||||||
mocker.patch('app.celery.tasks.send_sms.apply_async')
|
|
||||||
api_key_id = 'foo'
|
|
||||||
key_type = 'bar'
|
|
||||||
send_notification_to_persist_queue(
|
|
||||||
"notification-id",
|
|
||||||
sample_service,
|
|
||||||
sample_template.template_type,
|
|
||||||
"encrypted",
|
|
||||||
api_key_id,
|
|
||||||
key_type
|
|
||||||
)
|
|
||||||
|
|
||||||
tasks.send_sms.apply_async.assert_called_once_with(
|
|
||||||
ANY,
|
|
||||||
kwargs={
|
|
||||||
'api_key_id': api_key_id,
|
|
||||||
'key_type': key_type
|
|
||||||
},
|
|
||||||
queue=ANY
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@freeze_time("2016-01-01 11:09:00.061258")
|
@freeze_time("2016-01-01 11:09:00.061258")
|
||||||
def test_should_put_messages_in_research_mode_queue(sample_service, sample_template, mocker):
|
def test_should_put_messages_in_research_mode_queue(sample_service, sample_template, mocker):
|
||||||
mocker.patch('app.celery.tasks.send_sms.apply_async')
|
mocker.patch('app.celery.tasks.send_sms.apply_async')
|
||||||
send_notification_to_persist_queue(
|
send_notification_to_persist_queue(
|
||||||
"notification-id",
|
"notification-id", sample_service, sample_template.template_type, "encrypted", False, True
|
||||||
sample_service,
|
|
||||||
sample_template.template_type,
|
|
||||||
"encrypted",
|
|
||||||
'api_key_id',
|
|
||||||
'key_type',
|
|
||||||
priority=False,
|
|
||||||
research_mode=True
|
|
||||||
)
|
)
|
||||||
|
|
||||||
tasks.send_sms.apply_async.assert_called_once_with(
|
tasks.send_sms.apply_async.assert_called_once_with(
|
||||||
@@ -146,7 +108,6 @@ def test_should_put_messages_in_research_mode_queue(sample_service, sample_templ
|
|||||||
"notification-id",
|
"notification-id",
|
||||||
"encrypted",
|
"encrypted",
|
||||||
"2016-01-01T11:09:00.061258Z"),
|
"2016-01-01T11:09:00.061258Z"),
|
||||||
kwargs=ANY,
|
|
||||||
queue="research-mode"
|
queue="research-mode"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -155,14 +116,7 @@ def test_should_put_messages_in_research_mode_queue(sample_service, sample_templ
|
|||||||
def test_should_put_messages_in_research_mode_queue_overriding_priority_mode(sample_service, sample_template, mocker):
|
def test_should_put_messages_in_research_mode_queue_overriding_priority_mode(sample_service, sample_template, mocker):
|
||||||
mocker.patch('app.celery.tasks.send_sms.apply_async')
|
mocker.patch('app.celery.tasks.send_sms.apply_async')
|
||||||
send_notification_to_persist_queue(
|
send_notification_to_persist_queue(
|
||||||
"notification-id",
|
"notification-id", sample_service, sample_template.template_type, "encrypted", True, True
|
||||||
sample_service,
|
|
||||||
sample_template.template_type,
|
|
||||||
"encrypted",
|
|
||||||
'api_key_id',
|
|
||||||
'key_type',
|
|
||||||
priority=True,
|
|
||||||
research_mode=True
|
|
||||||
)
|
)
|
||||||
|
|
||||||
tasks.send_sms.apply_async.assert_called_once_with(
|
tasks.send_sms.apply_async.assert_called_once_with(
|
||||||
@@ -170,7 +124,6 @@ def test_should_put_messages_in_research_mode_queue_overriding_priority_mode(sam
|
|||||||
"notification-id",
|
"notification-id",
|
||||||
"encrypted",
|
"encrypted",
|
||||||
"2016-01-01T11:09:00.061258Z"),
|
"2016-01-01T11:09:00.061258Z"),
|
||||||
kwargs=ANY,
|
|
||||||
queue="research-mode"
|
queue="research-mode"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -179,7 +132,7 @@ def test_should_put_messages_in_research_mode_queue_overriding_priority_mode(sam
|
|||||||
def test_should_put_email_messages_in_db_email_queue(sample_service, sample_email_template, mocker):
|
def test_should_put_email_messages_in_db_email_queue(sample_service, sample_email_template, mocker):
|
||||||
mocker.patch('app.celery.tasks.send_email.apply_async')
|
mocker.patch('app.celery.tasks.send_email.apply_async')
|
||||||
send_notification_to_persist_queue(
|
send_notification_to_persist_queue(
|
||||||
'notification-id', sample_service, sample_email_template.template_type, 'encrypted', 'api_key_id', 'key_type'
|
"notification-id", sample_service, sample_email_template.template_type, "encrypted"
|
||||||
)
|
)
|
||||||
|
|
||||||
tasks.send_email.apply_async.assert_called_once_with(
|
tasks.send_email.apply_async.assert_called_once_with(
|
||||||
@@ -187,7 +140,6 @@ def test_should_put_email_messages_in_db_email_queue(sample_service, sample_emai
|
|||||||
"notification-id",
|
"notification-id",
|
||||||
"encrypted",
|
"encrypted",
|
||||||
"2016-01-01T11:09:00.061258Z"),
|
"2016-01-01T11:09:00.061258Z"),
|
||||||
kwargs=ANY,
|
|
||||||
queue="db-email"
|
queue="db-email"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -502,8 +454,6 @@ def test_process_row_sends_letter_task(template_type, research_mode, expected_fu
|
|||||||
),
|
),
|
||||||
queue=expected_queue
|
queue=expected_queue
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# -------- send_sms and send_email tests -------- #
|
# -------- send_sms and send_email tests -------- #
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user