Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
worker: Ensure complete coverage for PushNotificationsWorker.
Abhijeet Prasad Bodase63e86dcb21a
diff --git a/zerver/tests/test_queue_worker.py b/zerver/tests/test_queue_worker.pyindex 18936207014..8a72599c128 100644--- a/zerver/tests/test_queue_worker.py+++ b/zerver/tests/test_queue_worker.py@@ -301,6 +301,23 @@ class WorkerTest(ZulipTestCase):* 2,)+ # This verifies the compatibility code for the `message_id` -> `message_ids`+ # conversion for "remove" events.+ with patch(+ "zerver.worker.queue_processors.handle_remove_push_notification"+ ) as mock_handle_remove, patch(+ "zerver.worker.queue_processors.initialize_push_notifications"+ ):+ event_new = dict(+ user_profile_id=10,+ message_id=33,+ type="remove",+ )+ fake_client.enqueue("missedmessage_mobile_notifications", event_new)+ worker.start()+ # The `message_id` field should have been converted to a list with a single element.+ mock_handle_remove.assert_called_once_with(10, [33])+@patch("zerver.worker.queue_processors.mirror_email")def test_mirror_worker(self, mock_mirror_email: MagicMock) -> None:fake_client = self.FakeClient()diff --git a/zerver/worker/queue_processors.py b/zerver/worker/queue_processors.pyindex 556be5a5cac..6cb8472e048 100644--- a/zerver/worker/queue_processors.py+++ b/zerver/worker/queue_processors.py@@ -667,7 +667,7 @@ class EmailSendingWorker(LoopQueueProcessingWorker):@assign_queue("missedmessage_mobile_notifications")-class PushNotificationsWorker(QueueProcessingWorker): # nocoverage+class PushNotificationsWorker(QueueProcessingWorker):def start(self) -> None:# initialize_push_notifications doesn't strictly do anything# beyond printing some logging warnings if push notifications@@ -679,7 +679,13 @@ class PushNotificationsWorker(QueueProcessingWorker): # nocoveragetry:if event.get("type", "add") == "remove":message_ids = event.get("message_ids")- if message_ids is None: # legacy task across an upgrade+ if message_ids is None:+ # TODO/compatibility: Previously, we sent only one `message_id` in+ # a payload for notification remove events. This was later changed+ # to send a list of `message_ids` (with that field name), but we need+ # compatibility code for events present in the queue during upgrade.+ # Remove this when one can no longer upgrade from 1.9.2 (or earlier)+ # to any version after 2.0.0message_ids = [event["message_id"]]handle_remove_push_notification(event["user_profile_id"], message_ids)else: