mirror of
https://github.com/zulip/zulip.git
synced 2025-11-01 20:44:04 +00:00
push_notifs: Order device args to send_notifications_to_bouncer by id.
This ensures determinism in these tests doing mock_send.assert_called with - avoids producing test flakes due to a different order of retrieval of these objects from the database.
This commit is contained in:
committed by
Tim Abbott
parent
2916a601b3
commit
3bcfb9c005
@@ -1190,10 +1190,10 @@ def handle_remove_push_notification(user_profile_id: int, message_ids: List[int]
|
|||||||
apns_payload = get_remove_payload_apns(user_profile, truncated_message_ids)
|
apns_payload = get_remove_payload_apns(user_profile, truncated_message_ids)
|
||||||
|
|
||||||
android_devices = list(
|
android_devices = list(
|
||||||
PushDeviceToken.objects.filter(user=user_profile, kind=PushDeviceToken.GCM)
|
PushDeviceToken.objects.filter(user=user_profile, kind=PushDeviceToken.GCM).order_by("id")
|
||||||
)
|
)
|
||||||
apple_devices = list(
|
apple_devices = list(
|
||||||
PushDeviceToken.objects.filter(user=user_profile, kind=PushDeviceToken.APNS)
|
PushDeviceToken.objects.filter(user=user_profile, kind=PushDeviceToken.APNS).order_by("id")
|
||||||
)
|
)
|
||||||
if uses_notification_bouncer():
|
if uses_notification_bouncer():
|
||||||
send_notifications_to_bouncer(
|
send_notifications_to_bouncer(
|
||||||
@@ -1356,11 +1356,11 @@ def handle_push_notification(user_profile_id: int, missed_message: Dict[str, Any
|
|||||||
logger.info("Sending push notifications to mobile clients for user %s", user_profile_id)
|
logger.info("Sending push notifications to mobile clients for user %s", user_profile_id)
|
||||||
|
|
||||||
android_devices = list(
|
android_devices = list(
|
||||||
PushDeviceToken.objects.filter(user=user_profile, kind=PushDeviceToken.GCM)
|
PushDeviceToken.objects.filter(user=user_profile, kind=PushDeviceToken.GCM).order_by("id")
|
||||||
)
|
)
|
||||||
|
|
||||||
apple_devices = list(
|
apple_devices = list(
|
||||||
PushDeviceToken.objects.filter(user=user_profile, kind=PushDeviceToken.APNS)
|
PushDeviceToken.objects.filter(user=user_profile, kind=PushDeviceToken.APNS).order_by("id")
|
||||||
)
|
)
|
||||||
if uses_notification_bouncer():
|
if uses_notification_bouncer():
|
||||||
total_android_devices, total_apple_devices = send_notifications_to_bouncer(
|
total_android_devices, total_apple_devices = send_notifications_to_bouncer(
|
||||||
|
|||||||
@@ -2393,8 +2393,16 @@ class HandlePushNotificationTest(PushNotificationTest):
|
|||||||
{"apns": True},
|
{"apns": True},
|
||||||
{"gcm": True},
|
{"gcm": True},
|
||||||
{},
|
{},
|
||||||
list(PushDeviceToken.objects.filter(user=user_profile, kind=PushDeviceToken.GCM)),
|
list(
|
||||||
list(PushDeviceToken.objects.filter(user=user_profile, kind=PushDeviceToken.APNS)),
|
PushDeviceToken.objects.filter(
|
||||||
|
user=user_profile, kind=PushDeviceToken.GCM
|
||||||
|
).order_by("id")
|
||||||
|
),
|
||||||
|
list(
|
||||||
|
PushDeviceToken.objects.filter(
|
||||||
|
user=user_profile, kind=PushDeviceToken.APNS
|
||||||
|
).order_by("id")
|
||||||
|
),
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
mock_logging_info.output,
|
mock_logging_info.output,
|
||||||
@@ -2508,8 +2516,16 @@ class HandlePushNotificationTest(PushNotificationTest):
|
|||||||
"zulip_message_id": message.id,
|
"zulip_message_id": message.id,
|
||||||
},
|
},
|
||||||
{"priority": "normal"},
|
{"priority": "normal"},
|
||||||
list(PushDeviceToken.objects.filter(user=user_profile, kind=PushDeviceToken.GCM)),
|
list(
|
||||||
list(PushDeviceToken.objects.filter(user=user_profile, kind=PushDeviceToken.APNS)),
|
PushDeviceToken.objects.filter(
|
||||||
|
user=user_profile, kind=PushDeviceToken.GCM
|
||||||
|
).order_by("id")
|
||||||
|
),
|
||||||
|
list(
|
||||||
|
PushDeviceToken.objects.filter(
|
||||||
|
user=user_profile, kind=PushDeviceToken.APNS
|
||||||
|
).order_by("id")
|
||||||
|
),
|
||||||
)
|
)
|
||||||
user_message = UserMessage.objects.get(user_profile=self.user_profile, message=message)
|
user_message = UserMessage.objects.get(user_profile=self.user_profile, message=message)
|
||||||
self.assertEqual(user_message.flags.active_mobile_push_notification, False)
|
self.assertEqual(user_message.flags.active_mobile_push_notification, False)
|
||||||
|
|||||||
Reference in New Issue
Block a user