Skip to content

Commit

Permalink
Added autospec=True to patch in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Bart van der Schoor committed Mar 5, 2024
1 parent 26c5358 commit c04166a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
10 changes: 7 additions & 3 deletions tests/test_process_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ class ProcessTestCase(TestCase):
note the patched helpers are individually and more exhaustively tested elsewhere
"""

@patch("mail_editor.process.cid_for_bytes", return_value="MY_CID")
@patch("mail_editor.process.load_image", return_value=FileData(b"abc", "image/jpg"))
@patch("mail_editor.process.cid_for_bytes", return_value="MY_CID", autospec=True)
@patch(
"mail_editor.process.load_image",
return_value=FileData(b"abc", "image/jpg"),
autospec=True,
)
def test_extract_images(self, m1, m2):
html = """
<html><body>
Expand All @@ -27,7 +31,7 @@ def test_extract_images(self, m1, m2):
self.assertHTMLEqual(result.html, expected_html)
self.assertEqual(result.cid_attachments, [("MY_CID", b"abc", "image/jpg")])

@patch("mail_editor.process.load_image", return_value=None)
@patch("mail_editor.process.load_image", return_value=None, autospec=True)
def test_extract_images__keeps_absolute_url_when_not_loadable(self, m):
html = """
<html><body>
Expand Down
8 changes: 6 additions & 2 deletions tests/test_send.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,12 @@ def test_send_email(self):
self.assertIn(str(_("Test mail sent from testcase with 111")), message.body)
self.assertEqual(message.attachments, [])

@patch("mail_editor.process.cid_for_bytes", return_value="MY_CID")
@patch("mail_editor.process.load_image", return_value=FileData(b"abc", "image/jpg"))
@patch("mail_editor.process.cid_for_bytes", return_value="MY_CID", autospec=True)
@patch(
"mail_editor.process.load_image",
return_value=FileData(b"abc", "image/jpg"),
autospec=True,
)
@override_settings(MAIL_EDITOR_CONF=CONFIG)
def test_send_email_processed_content(self, m0, m1):
subject_context = {"id": "111"}
Expand Down

0 comments on commit c04166a

Please sign in to comment.