mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 17:31:14 -05:00
Remove letters-related code (#175)
This deletes a big ol' chunk of code related to letters. It's not everything—there are still a few things that might be tied to sms/email—but it's the the heart of letters function. SMS and email function should be untouched by this. Areas affected: - Things obviously about letters - PDF tasks, used for precompiling letters - Virus scanning, used for those PDFs - FTP, used to send letters to the printer - Postage stuff
This commit is contained in:
@@ -1,21 +1,18 @@
|
||||
import uuid
|
||||
from unittest.mock import ANY, call
|
||||
from unittest.mock import ANY
|
||||
|
||||
import pytest
|
||||
import requests_mock
|
||||
from flask import current_app, json
|
||||
from freezegun import freeze_time
|
||||
from flask import json
|
||||
|
||||
from app.celery.research_mode_tasks import (
|
||||
HTTPError,
|
||||
create_fake_letter_response_file,
|
||||
send_email_response,
|
||||
send_sms_response,
|
||||
ses_notification_callback,
|
||||
sns_callback,
|
||||
)
|
||||
from app.config import QueueNames
|
||||
from tests.conftest import Matcher, set_config_values
|
||||
from tests.conftest import Matcher
|
||||
|
||||
dvla_response_file_matcher = Matcher(
|
||||
'dvla_response_file',
|
||||
@@ -96,114 +93,3 @@ def test_temp_failure_sns_callback():
|
||||
assert data['status'] == "4"
|
||||
assert data['reference'] == "sns_reference"
|
||||
assert data['CID'] == "1234"
|
||||
|
||||
|
||||
@freeze_time("2018-01-25 14:00:30")
|
||||
@pytest.mark.skip(reason="Skipping letter-related functionality for now")
|
||||
def test_create_fake_letter_response_file_uploads_response_file_s3(
|
||||
notify_api, mocker):
|
||||
mocker.patch('app.celery.research_mode_tasks.file_exists', return_value=False)
|
||||
mock_s3upload = mocker.patch('app.celery.research_mode_tasks.s3upload')
|
||||
|
||||
with requests_mock.Mocker() as request_mock:
|
||||
request_mock.post(
|
||||
'http://localhost:6011/notifications/letter/dvla',
|
||||
content=b'{}',
|
||||
status_code=200
|
||||
)
|
||||
|
||||
create_fake_letter_response_file('random-ref')
|
||||
|
||||
mock_s3upload.assert_called_once_with(
|
||||
filedata='random-ref|Sent|0|Sorted',
|
||||
region=current_app.config['AWS_REGION'],
|
||||
bucket_name=current_app.config['DVLA_RESPONSE_BUCKET_NAME'],
|
||||
file_location=dvla_response_file_matcher
|
||||
)
|
||||
|
||||
|
||||
@freeze_time("2018-01-25 14:00:30")
|
||||
@pytest.mark.skip(reason="Skipping letter-related functionality for now")
|
||||
def test_create_fake_letter_response_file_calls_dvla_callback_on_development(
|
||||
notify_api, mocker):
|
||||
mocker.patch('app.celery.research_mode_tasks.file_exists', return_value=False)
|
||||
mocker.patch('app.celery.research_mode_tasks.s3upload')
|
||||
|
||||
with set_config_values(notify_api, {
|
||||
'NOTIFY_ENVIRONMENT': 'development'
|
||||
}):
|
||||
with requests_mock.Mocker() as request_mock:
|
||||
request_mock.post(
|
||||
'http://localhost:6011/notifications/letter/dvla',
|
||||
content=b'{}',
|
||||
status_code=200
|
||||
)
|
||||
|
||||
create_fake_letter_response_file('random-ref')
|
||||
|
||||
assert request_mock.last_request.json() == {
|
||||
"Type": "Notification",
|
||||
"MessageId": "some-message-id",
|
||||
"Message": ANY
|
||||
}
|
||||
assert json.loads(request_mock.last_request.json()['Message']) == {
|
||||
"Records": [
|
||||
{
|
||||
"s3": {
|
||||
"object": {
|
||||
"key": dvla_response_file_matcher
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@freeze_time("2018-01-25 14:00:30")
|
||||
@pytest.mark.skip(reason="Skipping letter-related functionality for now")
|
||||
def test_create_fake_letter_response_file_does_not_call_dvla_callback_on_preview(
|
||||
notify_api, mocker):
|
||||
mocker.patch('app.celery.research_mode_tasks.file_exists', return_value=False)
|
||||
mocker.patch('app.celery.research_mode_tasks.s3upload')
|
||||
|
||||
with set_config_values(notify_api, {
|
||||
'NOTIFY_ENVIRONMENT': 'preview'
|
||||
}):
|
||||
with requests_mock.Mocker() as request_mock:
|
||||
create_fake_letter_response_file('random-ref')
|
||||
|
||||
assert request_mock.last_request is None
|
||||
|
||||
|
||||
@freeze_time("2018-01-25 14:00:30")
|
||||
@pytest.mark.skip(reason="Skipping letter-related functionality for now")
|
||||
def test_create_fake_letter_response_file_tries_to_create_files_with_other_filenames(notify_api, mocker):
|
||||
mock_file_exists = mocker.patch('app.celery.research_mode_tasks.file_exists', side_effect=[True, True, False])
|
||||
mock_s3upload = mocker.patch('app.celery.research_mode_tasks.s3upload')
|
||||
|
||||
create_fake_letter_response_file('random-ref')
|
||||
|
||||
assert mock_file_exists.mock_calls == [
|
||||
call('test.notify.com-ftp', dvla_response_file_matcher),
|
||||
call('test.notify.com-ftp', dvla_response_file_matcher),
|
||||
call('test.notify.com-ftp', dvla_response_file_matcher),
|
||||
]
|
||||
mock_s3upload.assert_called_once_with(
|
||||
filedata=ANY,
|
||||
region=ANY,
|
||||
bucket_name=ANY,
|
||||
file_location=dvla_response_file_matcher
|
||||
)
|
||||
|
||||
|
||||
@freeze_time("2018-01-25 14:00:30")
|
||||
@pytest.mark.skip(reason="Skipping letter-related functionality for now")
|
||||
def test_create_fake_letter_response_file_gives_up_after_thirty_times(notify_api, mocker):
|
||||
mock_file_exists = mocker.patch('app.celery.research_mode_tasks.file_exists', return_value=True)
|
||||
mock_s3upload = mocker.patch('app.celery.research_mode_tasks.s3upload')
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
create_fake_letter_response_file('random-ref')
|
||||
|
||||
assert len(mock_file_exists.mock_calls) == 30
|
||||
assert not mock_s3upload.called
|
||||
|
||||
Reference in New Issue
Block a user