Skip to content

Commit

Permalink
Merge pull request #772 from uktrade/LTD-904-remove-send-email-check
Browse files Browse the repository at this point in the history
Remove send_email check and xfail.
  • Loading branch information
alixedi authored Jun 3, 2021
2 parents 4929103 + d17aff1 commit 941915d
Showing 1 changed file with 3 additions and 40 deletions.
43 changes: 3 additions & 40 deletions api/cases/tests/test_grant_licence.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import pytest
from unittest import mock
from django.conf import settings
from django.urls import reverse
Expand Down Expand Up @@ -31,10 +30,8 @@ def setUp(self):
decisions=[Decision.objects.get(name=AdviceType.APPROVE)],
)

@pytest.mark.xfail(reason="This fails because send_email is not called. Needs review")
@mock.patch("gov_notify.service.client")
@mock.patch("api.cases.generated_documents.models.GeneratedCaseDocument.send_exporter_notifications")
def test_grant_standard_application_success(self, send_exporter_notifications_func, mock_notify_client):
def test_grant_standard_application_success(self, send_exporter_notifications_func):
self.gov_user.role.permissions.set([GovPermissions.MANAGE_LICENCE_FINAL_ADVICE.name])
licence = self.create_licence(self.standard_case, status=LicenceStatus.DRAFT)
self.create_generated_case_document(
Expand All @@ -60,16 +57,6 @@ def test_grant_standard_application_success(self, send_exporter_notifications_fu
self.assertEqual(Audit.objects.count(), 3)
send_exporter_notifications_func.assert_called()

mock_notify_client.send_email.assert_called_with(
email_address=self.standard_case.submitted_by.email,
template_id=TemplateType.APPLICATION_STATUS.template_id,
data={
"case_reference": self.standard_case.reference_code,
"application_reference": self.standard_case.name,
"link": f"{settings.EXPORTER_BASE_URL}/applications/{self.standard_case.pk}",
},
)

def test_grant_standard_application_wrong_permission_failure(self):
self.gov_user.role.permissions.set([GovPermissions.MANAGE_CLEARANCE_FINAL_ADVICE.name])
self.create_licence(self.standard_case, status=LicenceStatus.DRAFT)
Expand All @@ -89,10 +76,8 @@ def test_missing_advice_document_failure(self):
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(response.json(), {"errors": {"decision-approve": [Cases.Licence.MISSING_DOCUMENTS]}})

@pytest.mark.xfail(reason="This fails because send_email is not called. Needs review")
@mock.patch("gov_notify.service.client")
@mock.patch("api.cases.generated_documents.models.GeneratedCaseDocument.send_exporter_notifications")
def test_grant_clearance_success(self, send_exporter_notifications_func, mock_notify_client):
def test_grant_clearance_success(self, send_exporter_notifications_func):
clearance_case = self.create_mod_clearance_application(self.organisation, CaseTypeEnum.EXHIBITION)
self.submit_application(clearance_case)
self.create_advice(self.gov_user, clearance_case, "good", AdviceType.APPROVE, AdviceLevel.FINAL)
Expand Down Expand Up @@ -123,16 +108,6 @@ def test_grant_clearance_success(self, send_exporter_notifications_func, mock_no
self.assertEqual(Audit.objects.count(), 4)
send_exporter_notifications_func.assert_called()

mock_notify_client.send_email.assert_called_with(
email_address=clearance_case.submitted_by.email,
template_id=TemplateType.APPLICATION_STATUS.template_id,
data={
"case_reference": clearance_case.reference_code,
"application_reference": clearance_case.name,
"link": f"{settings.EXPORTER_BASE_URL}/applications/{clearance_case.pk}",
},
)

def test_grant_clearance_wrong_permission_failure(self):
clearance_case = self.create_mod_clearance_application(self.organisation, CaseTypeEnum.EXHIBITION)
self.submit_application(clearance_case)
Expand All @@ -147,23 +122,11 @@ def test_grant_clearance_wrong_permission_failure(self):
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
self.assertEqual(response.json(), {"errors": {"error": PermissionDeniedError.default_detail}})

@pytest.mark.xfail(reason="This fails because send_email is not called. Needs review")
@mock.patch("gov_notify.service.client")
def test_finalise_case_without_licence_success(self, mock_notify_client):
def test_finalise_case_without_licence_success(self):
self.gov_user.role.permissions.set([GovPermissions.MANAGE_LICENCE_FINAL_ADVICE.name])
self.create_generated_case_document(self.standard_case, self.template, advice_type=AdviceType.APPROVE)

response = self.client.put(self.url, data={}, **self.gov_headers)

self.assertEqual(response.status_code, status.HTTP_201_CREATED)
self.assertEqual(response.json(), {"case": str(self.standard_case.pk)})

mock_notify_client.send_email.assert_called_with(
email_address=self.standard_case.submitted_by.email,
template_id=TemplateType.APPLICATION_STATUS.template_id,
data={
"case_reference": self.standard_case.reference_code,
"application_reference": self.standard_case.name,
"link": f"{settings.EXPORTER_BASE_URL}/applications/{self.standard_case.pk}",
},
)

0 comments on commit 941915d

Please sign in to comment.