Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

remote_server: Fix send_to_push_bouncer type.

Anders Kaseorgdbd1b563628e
diff --git a/zerver/lib/remote_server.py b/zerver/lib/remote_server.py
index 2f0338327ee..ccf93005e2e 100644
--- a/zerver/lib/remote_server.py
+++ b/zerver/lib/remote_server.py
@@ -21,10 +21,12 @@ class PushNotificationBouncerException(Exception):
class PushNotificationBouncerRetryLaterError(JsonableError):
http_status_code = 502
-def send_to_push_bouncer(method: str,
- endpoint: str,
- post_data: Union[str, Dict[str, Any]],
- extra_headers: Mapping[str, Any] = {}) -> Dict[str, Any]:
+def send_to_push_bouncer(
+ method: str,
+ endpoint: str,
+ post_data: Union[str, Mapping[str, Union[str, bytes]]],
+ extra_headers: Mapping[str, str] = {},
+) -> Dict[str, object]:
"""While it does actually send the notice, this function has a lot of
code and comments around error handling for the push notifications
bouncer. There are several classes of failures, each with its own
@@ -93,7 +95,7 @@ def send_to_push_bouncer(method: str,
# If we don't throw an exception, it's a successful bounce!
return ujson.loads(res.content)
-def send_json_to_push_bouncer(method: str, endpoint: str, post_data: Dict[str, Any]) -> None:
+def send_json_to_push_bouncer(method: str, endpoint: str, post_data: Mapping[str, object]) -> None:
send_to_push_bouncer(
method,
endpoint,
diff --git a/zerver/tests/test_push_notifications.py b/zerver/tests/test_push_notifications.py
index 3b4e755a49b..5334a325998 100644
--- a/zerver/tests/test_push_notifications.py
+++ b/zerver/tests/test_push_notifications.py
@@ -1569,13 +1569,13 @@ class TestSendToPushBouncer(ZulipTestCase):
@mock.patch('logging.warning')
def test_500_error(self, mock_request: mock.MagicMock, mock_warning: mock.MagicMock) -> None:
with self.assertRaises(PushNotificationBouncerRetryLaterError):
- result, failed = send_to_push_bouncer('register', 'register', {'data': True})
+ result, failed = send_to_push_bouncer('register', 'register', {'data': 'true'})
mock_warning.assert_called_once()
@mock.patch('requests.request', return_value=Result(status=400))
def test_400_error(self, mock_request: mock.MagicMock) -> None:
with self.assertRaises(JsonableError) as exc:
- send_to_push_bouncer('register', 'register', {'msg': True})
+ send_to_push_bouncer('register', 'register', {'msg': 'true'})
self.assertEqual(exc.exception.msg, 'error')
def test_400_error_invalid_server_key(self) -> None:
@@ -1587,7 +1587,7 @@ class TestSendToPushBouncer(ZulipTestCase):
return_value=Result(status=400,
content=ujson.dumps(error_obj.to_json()))):
with self.assertRaises(PushNotificationBouncerException) as exc:
- send_to_push_bouncer('register', 'register', {'msg': True})
+ send_to_push_bouncer('register', 'register', {'msg': 'true'})
self.assertEqual(str(exc.exception),
'Push notifications bouncer error: '
'Zulip server auth failure: testRole is not registered')
@@ -1595,14 +1595,14 @@ class TestSendToPushBouncer(ZulipTestCase):
@mock.patch('requests.request', return_value=Result(status=400, content='/'))
def test_400_error_when_content_is_not_serializable(self, mock_request: mock.MagicMock) -> None:
with self.assertRaises(ValueError) as exc:
- send_to_push_bouncer('register', 'register', {'msg': True})
+ send_to_push_bouncer('register', 'register', {'msg': 'true'})
self.assertEqual(str(exc.exception),
'Expected object or value')
@mock.patch('requests.request', return_value=Result(status=300, content='/'))
def test_300_error(self, mock_request: mock.MagicMock) -> None:
with self.assertRaises(PushNotificationBouncerException) as exc:
- send_to_push_bouncer('register', 'register', {'msg': True})
+ send_to_push_bouncer('register', 'register', {'msg': 'true'})
self.assertEqual(str(exc.exception),
'Push notification bouncer returned unexpected status code 300')