From 95e6fb85a1c755fcfc93d444df3072debd46c822 Mon Sep 17 00:00:00 2001 From: Kili Date: Mon, 9 Mar 2026 22:11:35 +0100 Subject: [PATCH] Fix Gmail delete_message to execute API request (#668) * Fix Gmail delete to execute request and add regression test * Fix duplicate GmailConnection import in tests --- parsedmarc/mail/gmail.py | 2 +- tests.py | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/parsedmarc/mail/gmail.py b/parsedmarc/mail/gmail.py index 92eac12..ac8f453 100644 --- a/parsedmarc/mail/gmail.py +++ b/parsedmarc/mail/gmail.py @@ -158,7 +158,7 @@ class GmailConnection(MailboxConnection): return urlsafe_b64decode(msg["raw"]).decode(errors="replace") def delete_message(self, message_id: str): - self.service.users().messages().delete(userId="me", id=message_id) + self.service.users().messages().delete(userId="me", id=message_id).execute() def move_message(self, message_id: str, folder_name: str): label_id = self._find_label_id_for_label(folder_name) diff --git a/tests.py b/tests.py index e24e0f8..dd81b20 100755 --- a/tests.py +++ b/tests.py @@ -257,6 +257,7 @@ class TestGmailConnection(unittest.TestCase): messages_api.modify.assert_called_once() connection.delete_message("m1") messages_api.delete.assert_called_once_with(userId="me", id="m1") + messages_api.delete.return_value.execute.assert_called_once() def testGetCredsFromTokenFile(self): creds = MagicMock() @@ -613,8 +614,6 @@ class TestImapConnection(unittest.TestCase): with self.assertRaises(_BreakLoop): connection.watch(callback, check_timeout=1) callback.assert_called_once_with(connection) - - class TestGmailAuthModes(unittest.TestCase): @patch("parsedmarc.mail.gmail.service_account.Credentials.from_service_account_file") def testGetCredsServiceAccountWithoutSubject(self, mock_from_service_account_file): @@ -787,7 +786,5 @@ scopes = https://www.googleapis.com/auth/gmail.modify mock_gmail_connection.call_args.kwargs.get("service_account_user"), "delegated@example.com", ) - - if __name__ == "__main__": unittest.main(verbosity=2)