-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
84 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ | |
"conventions.models.convention.Convention.get_email_bailleur_users", | ||
Mock(return_value=["[email protected]"]), | ||
) | ||
@patch("conventions.tasks.task_generate_and_send", autospec=True) | ||
@patch("conventions.tasks.generate_pdf", autospec=True) | ||
@patch("conventions.tasks.get_or_generate_convention_doc", autospec=True) | ||
class GenerateAndSendTest(TestCase): | ||
def _create_pdf_file_in_storage(self, convention_uuid: str): | ||
|
@@ -50,7 +50,7 @@ def setUp(self): | |
self._create_pdf_file_in_storage(convention_uuid=str(self.convention.uuid)) | ||
|
||
def test_generate_and_send_logement_ordinaire( | ||
self, mock_generate_convention_doc, mock_generate_pdf | ||
self, mock_get_or_generate_convention_doc, mock_generate_pdf | ||
): | ||
self.programme.nature_logement = NatureLogement.LOGEMENTSORDINAIRES | ||
self.programme.save() | ||
|
@@ -63,12 +63,12 @@ def test_generate_and_send_logement_ordinaire( | |
|
||
task_generate_and_send(**task_kwargs) | ||
|
||
mock_generate_convention_doc.assert_called_once_with( | ||
mock_get_or_generate_convention_doc.assert_called_once_with( | ||
convention=self.convention, save_data=True | ||
) | ||
mock_generate_pdf.assert_called_once_with( | ||
convention_uuid=str(self.convention.uuid), | ||
doc=mock_generate_convention_doc.return_value, | ||
doc=mock_get_or_generate_convention_doc.return_value, | ||
) | ||
|
||
self.assertEqual( | ||
|
@@ -91,126 +91,33 @@ def test_generate_and_send_logement_ordinaire( | |
}, | ||
) | ||
|
||
with patch("conventions.tasks.get_or_generate_convention_doc", autospec=True): | ||
with patch( | ||
"conventions.tasks.generate_pdf", autospec=True | ||
) as mocked_generate_pdf: | ||
mocked_generate_pdf.return_value = "convention.pdf" | ||
args = { | ||
"convention_uuid": str(self.convention.uuid), | ||
"convention_url": "https://target.to.convention.display", | ||
"convention_email_validator": "[email protected]", | ||
} | ||
generate_and_send(args) | ||
self.assertEqual( | ||
mail.outbox[0].anymail_test_params["attachments"][0].name, | ||
"convention.pdf", | ||
) | ||
self.assertEqual( | ||
mail.outbox[0].anymail_test_params["template_id"], | ||
EmailTemplateID.ItoB_CONVENTION_VALIDEE.value, | ||
) | ||
self.assertDictEqual( | ||
mail.outbox[0].anymail_test_params["merge_global_data"], | ||
{ | ||
"convention_url": "https://target.to.convention.display", | ||
"convention": str(self.convention), | ||
"adresse": "1 rue de la paix", | ||
"code_postal": "75000", | ||
"ville": "Paris", | ||
"nb_convention_exemplaires": 12, | ||
}, | ||
) | ||
self.convention.programme.nature_logement = ( | ||
NatureLogement.RESIDENCEUNIVERSITAIRE | ||
) | ||
self.convention.programme.save() | ||
generate_and_send(args) | ||
self.assertEqual( | ||
mail.outbox[0].anymail_test_params["attachments"][0].name, | ||
"convention.pdf", | ||
) | ||
self.assertEqual( | ||
mail.outbox[0].anymail_test_params["template_id"], | ||
EmailTemplateID.ItoB_CONVENTION_VALIDEE.value, | ||
) | ||
self.assertDictEqual( | ||
mail.outbox[0].anymail_test_params["merge_global_data"], | ||
{ | ||
"convention_url": "https://target.to.convention.display", | ||
"convention": str(self.convention), | ||
"adresse": "1 rue de la paix", | ||
"code_postal": "75000", | ||
"ville": "Paris", | ||
"nb_convention_exemplaires": 12, | ||
}, | ||
) | ||
|
||
self.programme.nature_logement = NatureLogement.RESIDENCEUNIVERSITAIRE | ||
self.programme.save() | ||
|
||
with patch("conventions.tasks.get_or_generate_convention_doc", autospec=True): | ||
with patch( | ||
"conventions.tasks.generate_pdf", autospec=True | ||
) as mocked_generate_pdf: | ||
mocked_generate_pdf.return_value = "convention.pdf" | ||
generate_and_send(args) | ||
self.assertEqual( | ||
mail.outbox[0].anymail_test_params["attachments"][0].name, | ||
f"convention_{self.convention.uuid}.zip", | ||
) | ||
self.assertEqual( | ||
mail.outbox[0].anymail_test_params["template_id"], | ||
EmailTemplateID.ItoB_CONVENTION_VALIDEE.value, | ||
) | ||
self.assertDictEqual( | ||
mail.outbox[0].anymail_test_params["merge_global_data"], | ||
{ | ||
"convention_url": "https://target.to.convention.display", | ||
"convention": str(self.convention), | ||
"adresse": "1 rue de la paix", | ||
"code_postal": "75000", | ||
"ville": "Paris", | ||
"nb_convention_exemplaires": 12, | ||
}, | ||
) | ||
|
||
mock_generate_convention_doc.assert_called_once_with( | ||
convention=self.convention, save_data=True | ||
self.convention.programme.nature_logement = ( | ||
NatureLogement.RESIDENCEUNIVERSITAIRE | ||
) | ||
mock_generate_pdf.assert_called_once_with( | ||
convention_uuid=str(self.convention.uuid), | ||
doc=mock_generate_convention_doc.return_value, | ||
self.convention.programme.save() | ||
task_generate_and_send(**task_kwargs) | ||
self.assertEqual( | ||
mail.outbox[0].anymail_test_params["attachments"][0].name, | ||
f"{self.convention.uuid}.pdf", | ||
) | ||
self.assertEqual( | ||
mail.outbox[0].anymail_test_params["template_id"], | ||
EmailTemplateID.ItoB_CONVENTION_VALIDEE.value, | ||
) | ||
self.assertDictEqual( | ||
mail.outbox[0].anymail_test_params["merge_global_data"], | ||
{ | ||
"convention_url": "https://target.to.convention.display", | ||
"convention": str(self.convention), | ||
"adresse": "1 rue de la paix", | ||
"code_postal": "75000", | ||
"ville": "Paris", | ||
"nb_convention_exemplaires": 12, | ||
}, | ||
) | ||
|
||
with patch("conventions.tasks.get_or_generate_convention_doc", autospec=True): | ||
with patch( | ||
"conventions.tasks.generate_pdf", autospec=True | ||
) as mocked_generate_pdf: | ||
mocked_generate_pdf.return_value = "convention.pdf" | ||
task_generate_and_send(args) | ||
self.assertEqual( | ||
mail.outbox[0].anymail_test_params["attachments"][0].name, | ||
f"convention_{self.convention.uuid}.zip", | ||
) | ||
self.assertEqual( | ||
mail.outbox[0].anymail_test_params["template_id"], | ||
EmailTemplateID.ItoB_CONVENTION_VALIDEE.value, | ||
) | ||
self.assertDictEqual( | ||
mail.outbox[0].anymail_test_params["merge_global_data"], | ||
{ | ||
"convention_url": "https://target.to.convention.display", | ||
"convention": str(self.convention), | ||
"adresse": "1 rue de la paix", | ||
"code_postal": "75000", | ||
"ville": "Paris", | ||
"nb_convention_exemplaires": 12, | ||
}, | ||
) | ||
|
||
def test_generate_and_send_foyer( | ||
self, mock_generate_convention_doc, mock_generate_pdf | ||
self, mock_get_or_generate_convention_doc, mock_generate_pdf | ||
): | ||
self.programme.nature_logement = NatureLogement.AUTRE | ||
self.programme.save() | ||
|
@@ -221,12 +128,12 @@ def test_generate_and_send_foyer( | |
convention_email_validator="[email protected]", | ||
) | ||
|
||
mock_generate_convention_doc.assert_called_once_with( | ||
mock_get_or_generate_convention_doc.assert_called_once_with( | ||
convention=self.convention, save_data=True | ||
) | ||
mock_generate_pdf.assert_called_once_with( | ||
convention_uuid=str(self.convention.uuid), | ||
doc=mock_generate_convention_doc.return_value, | ||
doc=mock_get_or_generate_convention_doc.return_value, | ||
) | ||
|
||
self.assertEqual( | ||
|
@@ -250,7 +157,7 @@ def test_generate_and_send_foyer( | |
) | ||
|
||
def test_generate_and_send_residence( | ||
self, mock_generate_convention_doc, mock_generate_pdf | ||
self, mock_get_or_generate_convention_doc, mock_generate_pdf | ||
): | ||
self.programme.nature_logement = NatureLogement.RESIDENCEDACCUEIL | ||
self.programme.save() | ||
|
@@ -261,12 +168,12 @@ def test_generate_and_send_residence( | |
convention_email_validator="[email protected]", | ||
) | ||
|
||
mock_generate_convention_doc.assert_called_once_with( | ||
mock_get_or_generate_convention_doc.assert_called_once_with( | ||
convention=self.convention, save_data=True | ||
) | ||
mock_generate_pdf.assert_called_once_with( | ||
convention_uuid=str(self.convention.uuid), | ||
doc=mock_generate_convention_doc.return_value, | ||
doc=mock_get_or_generate_convention_doc.return_value, | ||
) | ||
|
||
self.assertEqual( | ||
|
@@ -290,7 +197,7 @@ def test_generate_and_send_residence( | |
) | ||
|
||
def test_generate_and_send_avenant( | ||
self, mock_generate_convention_doc, mock_generate_pdf | ||
self, mock_get_or_generate_convention_doc, mock_generate_pdf | ||
): | ||
self.programme.nature_logement = NatureLogement.RESIDENCEDACCUEIL | ||
self.programme.save() | ||
|
@@ -301,32 +208,34 @@ def test_generate_and_send_avenant( | |
"convention_url": "https://target.to.convention.display", | ||
"convention_email_validator": "[email protected]", | ||
} | ||
with patch("conventions.tasks.get_or_generate_convention_doc", autospec=True): | ||
with patch( | ||
"conventions.tasks.generate_pdf", autospec=True | ||
) as mocked_generate_pdf: | ||
args = { | ||
"convention_uuid": str(avenant.uuid), | ||
"convention_url": "https://target.to.convention.display", | ||
"convention_email_validator": "[email protected]", | ||
} | ||
task_generate_and_send(args) | ||
self.assertEqual( | ||
mail.outbox[0].anymail_test_params["attachments"][0].name, | ||
"convention.pdf", | ||
) | ||
self.assertEqual( | ||
mail.outbox[0].anymail_test_params["template_id"], | ||
EmailTemplateID.ItoB_AVENANT_VALIDE.value, | ||
) | ||
self.assertDictEqual( | ||
mail.outbox[0].anymail_test_params["merge_global_data"], | ||
{ | ||
"convention_url": "https://target.to.convention.display", | ||
"convention": str(avenant), | ||
"adresse": "1 rue de la paix", | ||
"code_postal": "75000", | ||
"ville": "Paris", | ||
"nb_convention_exemplaires": 12, | ||
}, | ||
) | ||
self._create_pdf_file_in_storage(convention_uuid=str(avenant.uuid)) | ||
|
||
task_generate_and_send(**args) | ||
|
||
mock_get_or_generate_convention_doc.assert_called_once_with( | ||
convention=avenant, save_data=True | ||
) | ||
mock_generate_pdf.assert_called_once_with( | ||
convention_uuid=str(avenant.uuid), | ||
doc=mock_get_or_generate_convention_doc.return_value, | ||
) | ||
|
||
self.assertEqual( | ||
mail.outbox[0].anymail_test_params["attachments"][0].name, | ||
f"{avenant.uuid}.pdf", | ||
) | ||
self.assertEqual( | ||
mail.outbox[0].anymail_test_params["template_id"], | ||
EmailTemplateID.ItoB_AVENANT_VALIDE.value, | ||
) | ||
self.assertDictEqual( | ||
mail.outbox[0].anymail_test_params["merge_global_data"], | ||
{ | ||
"convention_url": "https://target.to.convention.display", | ||
"convention": str(avenant), | ||
"adresse": "1 rue de la paix", | ||
"code_postal": "75000", | ||
"ville": "Paris", | ||
"nb_convention_exemplaires": 12, | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters