mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-24 00:06:16 -04:00
Revert "Process SNS request triggered by a DVLA S3 update"
This commit is contained in:
@@ -12,19 +12,15 @@ from celery.exceptions import Retry
|
||||
from app import (encryption, DATETIME_FORMAT)
|
||||
from app.celery import provider_tasks
|
||||
from app.celery import tasks
|
||||
from app.celery.tasks import s3, build_dvla_file, create_dvla_file_contents, update_dvla_job_to_error
|
||||
from app.celery.tasks import (
|
||||
s3,
|
||||
build_dvla_file,
|
||||
create_dvla_file_contents,
|
||||
update_dvla_job_to_error,
|
||||
process_job,
|
||||
process_row,
|
||||
send_sms,
|
||||
send_email,
|
||||
persist_letter,
|
||||
get_template_class,
|
||||
update_job_to_sent_to_dvla,
|
||||
update_letter_notifications_statuses
|
||||
update_job_to_sent_to_dvla
|
||||
)
|
||||
from app.dao import jobs_dao, services_dao
|
||||
from app.models import (
|
||||
@@ -38,7 +34,6 @@ from app.models import (
|
||||
Job)
|
||||
|
||||
from tests.app import load_example_csv
|
||||
from tests.conftest import set_config
|
||||
from tests.app.conftest import (
|
||||
sample_service,
|
||||
sample_template,
|
||||
@@ -1076,37 +1071,3 @@ def test_update_dvla_job_to_error(sample_letter_template, sample_letter_job):
|
||||
assert not n.sent_by
|
||||
|
||||
assert 'error' == Job.query.filter_by(id=sample_letter_job.id).one().job_status
|
||||
|
||||
|
||||
def test_update_letter_notifications_statuses_raises_for_invalid_format(notify_api, mocker):
|
||||
invalid_file = b'ref-foo|Sent|1|Unsorted\nref-bar|Sent|2'
|
||||
mocker.patch('app.celery.tasks.s3.get_s3_object', return_value=invalid_file)
|
||||
|
||||
with pytest.raises(TypeError):
|
||||
update_letter_notifications_statuses(filename='foo.txt')
|
||||
|
||||
|
||||
def test_update_letter_notifications_statuses_calls_with_correct_bucket_location(notify_api, mocker):
|
||||
s3_mock = mocker.patch('app.celery.tasks.s3.get_s3_object')
|
||||
|
||||
with set_config(notify_api, 'NOTIFY_EMAIL_DOMAIN', 'foo.bar'):
|
||||
update_letter_notifications_statuses(filename='foo.txt')
|
||||
s3_mock.assert_called_with('{}-ftp'.format(current_app.config['NOTIFY_EMAIL_DOMAIN']), 'foo.txt')
|
||||
|
||||
|
||||
def test_update_letter_notifications_statuses_builds_updates_list(notify_api, mocker):
|
||||
valid_file = b'ref-foo|Sent|1|Unsorted\nref-bar|Sent|2|Sorted'
|
||||
mocker.patch('app.celery.tasks.s3.get_s3_object', return_value=valid_file)
|
||||
updates = update_letter_notifications_statuses(filename='foo.txt')
|
||||
|
||||
assert len(updates) == 2
|
||||
|
||||
assert updates[0].reference == 'ref-foo'
|
||||
assert updates[0].status == 'Sent'
|
||||
assert updates[0].page_count == '1'
|
||||
assert updates[0].cost_threshold == 'Unsorted'
|
||||
|
||||
assert updates[1].reference == 'ref-bar'
|
||||
assert updates[1].status == 'Sent'
|
||||
assert updates[1].page_count == '2'
|
||||
assert updates[1].cost_threshold == 'Sorted'
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import pytest
|
||||
import uuid
|
||||
|
||||
from datetime import datetime
|
||||
@@ -7,73 +6,21 @@ from flask import json
|
||||
from freezegun import freeze_time
|
||||
|
||||
import app.celery.tasks
|
||||
from app.errors import InvalidRequest
|
||||
from app.dao.notifications_dao import (
|
||||
get_notification_by_id
|
||||
)
|
||||
from app.models import NotificationStatistics
|
||||
from tests.app.notifications.test_notifications_ses_callback import ses_confirmation_callback
|
||||
from tests.app.conftest import sample_notification as create_sample_notification
|
||||
|
||||
|
||||
def test_dvla_callback_returns_400_with_invalid_request(client):
|
||||
data = json.dumps({"foo": "bar"})
|
||||
def test_dvla_callback_should_not_need_auth(client):
|
||||
data = json.dumps({"somekey": "somevalue"})
|
||||
response = client.post(
|
||||
path='/notifications/letter/dvla',
|
||||
data=data,
|
||||
headers=[('Content-Type', 'application/json')]
|
||||
)
|
||||
|
||||
json_resp = json.loads(response.get_data(as_text=True))
|
||||
|
||||
assert response.status_code == 400
|
||||
|
||||
|
||||
def test_dvla_callback_autoconfirms_subscription(client, mocker):
|
||||
autoconfirm_mock = mocker.patch('app.notifications.notifications_letter_callback.autoconfirm_subscription')
|
||||
|
||||
data = ses_confirmation_callback()
|
||||
response = client.post(
|
||||
path='/notifications/letter/dvla',
|
||||
data=data,
|
||||
headers=[('Content-Type', 'application/json')]
|
||||
)
|
||||
headers=[('Content-Type', 'application/json')])
|
||||
|
||||
assert response.status_code == 200
|
||||
assert autoconfirm_mock.called
|
||||
|
||||
|
||||
def test_dvla_callback_autoconfirm_does_not_call_update_letter_notifications_task(client, mocker):
|
||||
autoconfirm_mock = mocker.patch('app.notifications.notifications_letter_callback.autoconfirm_subscription')
|
||||
update_task = \
|
||||
mocker.patch('app.notifications.notifications_letter_callback.update_letter_notifications_statuses.apply_async')
|
||||
|
||||
data = ses_confirmation_callback()
|
||||
response = client.post(
|
||||
path='/notifications/letter/dvla',
|
||||
data=data,
|
||||
headers=[('Content-Type', 'application/json')]
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert autoconfirm_mock.called
|
||||
assert not update_task.called
|
||||
|
||||
|
||||
def test_dvla_callback_calls_update_letter_notifications_task(client, mocker):
|
||||
update_task = \
|
||||
mocker.patch('app.notifications.notifications_letter_callback.update_letter_notifications_statuses.apply_async')
|
||||
data = _sample_sns_s3_callback()
|
||||
response = client.post(
|
||||
path='/notifications/letter/dvla',
|
||||
data=data,
|
||||
headers=[('Content-Type', 'application/json')]
|
||||
)
|
||||
json_resp = json.loads(response.get_data(as_text=True))
|
||||
|
||||
assert response.status_code == 200
|
||||
assert update_task.called
|
||||
update_task.assert_called_with(['bar.txt'], queue='notify')
|
||||
|
||||
|
||||
def test_firetext_callback_should_not_need_auth(client, mocker):
|
||||
@@ -511,46 +458,3 @@ def test_firetext_callback_should_record_statsd(client, notify_db, notify_db_ses
|
||||
|
||||
def get_notification_stats(service_id):
|
||||
return NotificationStatistics.query.filter_by(service_id=service_id).one()
|
||||
|
||||
|
||||
def _sample_sns_s3_callback():
|
||||
return json.dumps({
|
||||
"SigningCertURL": "foo.pem",
|
||||
"UnsubscribeURL": "bar",
|
||||
"Signature": "some-signature",
|
||||
"Type": "Notification",
|
||||
"Timestamp": "2016-05-03T08:35:12.884Z",
|
||||
"SignatureVersion": "1",
|
||||
"MessageId": "6adbfe0a-d610-509a-9c47-af894e90d32d",
|
||||
"Subject": "Amazon S3 Notification",
|
||||
"TopicArn": "sample-topic-arn",
|
||||
"Message": {
|
||||
"Records": [{
|
||||
"eventVersion": "2.0",
|
||||
"eventSource": "aws:s3",
|
||||
"awsRegion": "eu-west-1",
|
||||
"eventTime": "2017-05-03T08:35:12.826Z",
|
||||
"eventName": "ObjectCreated:Put",
|
||||
"userIdentity": {"principalId": "some-p-id"},
|
||||
"requestParameters": {"sourceIPAddress": "8.8.8.8"},
|
||||
"responseElements": {"x-amz-request-id": "some-req-id", "x-amz-id-2": "some-amz-id"},
|
||||
"s3": {
|
||||
"s3SchemaVersion": "1.0",
|
||||
"configurationId": "some-config-id",
|
||||
"bucket": {
|
||||
"name": "some-bucket",
|
||||
"ownerIdentity": {"principalId": "some-p-id"},
|
||||
"arn": "some-bucket-arn"
|
||||
},
|
||||
"object": {
|
||||
"key": "bar.txt",
|
||||
"size": 200,
|
||||
"eTag": "some-etag",
|
||||
"versionId": "some-v-id",
|
||||
"sequencer": "some-seq"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user