Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
etchegom committed Apr 5, 2024
1 parent aab05f4 commit fe1f084
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion conventions/management/commands/generate_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def handle(self, *args, **options):
return

self.stdout.write(
self.style.SUCCESS(f"Generated PDF file: {local_docx_path}")
self.style.SUCCESS(f"Generated PDF file: {local_pdf_path}")
)

except subprocess.CalledProcessError as err:
Expand Down
13 changes: 13 additions & 0 deletions conventions/tests/services/test_convention_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from conventions.models import Convention, ConventionType1and2
from conventions.services.convention_generator import (
ConventionTypeConfigurationError,
PDFConversionError,
_compute_liste_des_annexes,
_compute_total_logement,
_get_adresse,
Expand Down Expand Up @@ -459,6 +460,8 @@ def test_compute_liste_des_annexes(self):
class TestGeneratePdf(TestCase):
@patch("conventions.services.convention_generator.subprocess.run")
def test_subprocess_command(self, mock_subprocess_run):
mock_subprocess_run.return_value = Mock(returncode=0, stderr=b"")

mock_doc = Mock(DocxTemplate, autospec=True)
convention_uuid = "8f59189c-3086-4355-b7eb-9a84bcab9582"
expected_local_path = Path(settings.MEDIA_ROOT, "tmp")
Expand All @@ -484,3 +487,13 @@ def test_subprocess_command(self, mock_subprocess_run):
capture_output=True,
)
mock_doc.save.assert_called_once_with(filename=expected_local_docx_path)

@patch("conventions.services.convention_generator.subprocess.run")
def test_command_return_code_err(self, mock_subprocess_run):
mock_subprocess_run.return_value = Mock(returncode=1, stderr=b"Error")

mock_doc = Mock(DocxTemplate, autospec=True)
convention_uuid = "8f59189c-3086-4355-b7eb-9a84bcab9582"

with self.assertRaises(PDFConversionError):
generate_pdf(doc=mock_doc, convention_uuid=convention_uuid)

0 comments on commit fe1f084

Please sign in to comment.