Move dispatch_send_task_order_files tests into a test class
This commit is contained in:
parent
411f0477e9
commit
b8bf106a96
@ -415,12 +415,15 @@ def test_create_environment_role():
|
||||
assert env_role.cloud_id == "a-cloud-id"
|
||||
|
||||
|
||||
# TODO: Refactor the tests related to dispatch_send_task_order_files() into a class
|
||||
# and separate the success test into two tests
|
||||
def test_dispatch_send_task_order_files(monkeypatch, app):
|
||||
class TestDispatchSendTaskOrderFiles:
|
||||
@pytest.fixture(scope="function")
|
||||
def send_mail(self, monkeypatch):
|
||||
mock = Mock()
|
||||
monkeypatch.setattr("atst.jobs.send_mail", mock)
|
||||
return mock
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def download_task_order(self, monkeypatch):
|
||||
def _download_task_order(MockFileService, object_name):
|
||||
return {"name": object_name}
|
||||
|
||||
@ -429,29 +432,29 @@ def test_dispatch_send_task_order_files(monkeypatch, app):
|
||||
_download_task_order,
|
||||
)
|
||||
|
||||
# Create 3 new Task Orders
|
||||
def test_sends_multiple_emails(self, send_mail, download_task_order):
|
||||
# Create 3 Task Orders
|
||||
for i in range(3):
|
||||
TaskOrderFactory.create(create_clins=[{"number": "0001"}])
|
||||
|
||||
dispatch_send_task_order_files.run()
|
||||
|
||||
# Check that send_with_attachment was called once for each task order
|
||||
assert mock.call_count == 3
|
||||
mock.reset_mock()
|
||||
assert send_mail.call_count == 3
|
||||
|
||||
# Create new TO
|
||||
def test_kwargs(self, send_mail, download_task_order, app):
|
||||
task_order = TaskOrderFactory.create(create_clins=[{"number": "0001"}])
|
||||
assert not task_order.pdf_last_sent_at
|
||||
|
||||
dispatch_send_task_order_files.run()
|
||||
|
||||
# Check that send_with_attachment was called with correct kwargs
|
||||
mock.assert_called_once_with(
|
||||
send_mail.assert_called_once_with(
|
||||
recipients=[app.config.get("MICROSOFT_TASK_ORDER_EMAIL_ADDRESS")],
|
||||
subject=translate(
|
||||
"email.task_order_sent.subject", {"to_number": task_order.number}
|
||||
),
|
||||
body=translate("email.task_order_sent.body", {"to_number": task_order.number}),
|
||||
body=translate(
|
||||
"email.task_order_sent.body", {"to_number": task_order.number}
|
||||
),
|
||||
attachments=[
|
||||
{
|
||||
"name": task_order.pdf.object_name,
|
||||
@ -460,27 +463,20 @@ def test_dispatch_send_task_order_files(monkeypatch, app):
|
||||
}
|
||||
],
|
||||
)
|
||||
|
||||
assert task_order.pdf_last_sent_at
|
||||
|
||||
|
||||
def test_dispatch_send_task_order_files_send_failure(monkeypatch):
|
||||
def test_send_failure(self, monkeypatch):
|
||||
def _raise_smtp_exception(**kwargs):
|
||||
raise SMTPException
|
||||
|
||||
monkeypatch.setattr("atst.jobs.send_mail", _raise_smtp_exception)
|
||||
|
||||
task_order = TaskOrderFactory.create(create_clins=[{"number": "0001"}])
|
||||
dispatch_send_task_order_files.run()
|
||||
|
||||
# Check that pdf_last_sent_at has not been updated
|
||||
assert not task_order.pdf_last_sent_at
|
||||
|
||||
|
||||
def test_dispatch_send_task_order_files_download_failure(monkeypatch):
|
||||
mock = Mock()
|
||||
monkeypatch.setattr("atst.jobs.send_mail", mock)
|
||||
|
||||
def test_download_failure(self, send_mail, monkeypatch):
|
||||
def _download_task_order(MockFileService, object_name):
|
||||
raise AzureError("something went wrong")
|
||||
|
||||
@ -488,7 +484,6 @@ def test_dispatch_send_task_order_files_download_failure(monkeypatch):
|
||||
"atst.domain.csp.files.MockFileService.download_task_order",
|
||||
_download_task_order,
|
||||
)
|
||||
|
||||
task_order = TaskOrderFactory.create(create_clins=[{"number": "0002"}])
|
||||
dispatch_send_task_order_files.run()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user