remote_server: Handle data of non existent realms.

This commit adds code to make sure that the push
notification does not crash on receiving data for
a non-existent realm.
This commit is contained in:
Sahil Batra
2023-12-14 02:10:54 +05:30
committed by Tim Abbott
parent c43eb10224
commit f0d429d0f9
2 changed files with 40 additions and 1 deletions

View File

@@ -1909,6 +1909,36 @@ class AnalyticsBouncerTest(BouncerTestCase):
],
)
@override_settings(PUSH_NOTIFICATION_BOUNCER_URL="https://push.zulip.org.example.com")
@responses.activate
def test_non_existent_realm_uuid(self) -> None:
self.add_mock_response()
realm_info = get_realms_info_for_push_bouncer()
# Hard-delete a realm to test the non existent realm uuid case.
realm = Realm.objects.order_by("id").first()
assert realm is not None
deleted_realm_uuid = realm.uuid
realm.delete()
with mock.patch(
"zerver.lib.remote_server.get_realms_info_for_push_bouncer", return_value=realm_info
) as m, self.assertLogs("zulip.analytics", level="WARNING") as analytics_logger:
send_server_data_to_push_bouncer(consider_usage_statistics=False)
m.assert_called()
realms = Realm.objects.all()
for realm in realms:
self.assertEqual(realm.push_notifications_enabled, True)
self.assertEqual(realm.push_notifications_enabled_end_timestamp, None)
self.assertEqual(
analytics_logger.output,
[
"WARNING:zulip.analytics:"
f"Received unexpected realm UUID from bouncer {deleted_realm_uuid}"
],
)
class PushNotificationTest(BouncerTestCase):
@override