|
5 | 5 | import pytest
|
6 | 6 | from django.test import TestCase
|
7 | 7 |
|
| 8 | +from aioapns.common import NotificationResult |
8 | 9 |
|
9 | 10 | try:
|
10 | 11 | from push_notifications.apns_async import TokenCredentials, apns_send_message
|
@@ -53,11 +54,7 @@ def test_push_payload_with_thread_id(self, mock_apns):
|
53 | 54 | sound="chime",
|
54 | 55 | extra={"custom_data": 12345},
|
55 | 56 | expiration=int(time.time()) + 3,
|
56 |
| - creds=TokenCredentials( |
57 |
| - key="aaa", |
58 |
| - key_id="bbb", |
59 |
| - team_id="ccc", |
60 |
| - ), |
| 57 | + creds=TokenCredentials(key="aaa", key_id="bbb", team_id="ccc"), |
61 | 58 | )
|
62 | 59 | args, kwargs = mock_apns.return_value.send_notification.call_args
|
63 | 60 | req = args[0]
|
@@ -159,6 +156,34 @@ def test_collapse_id(self, mock_apns):
|
159 | 156 | self.assertEqual(req.message["aps"]["alert"], "sample")
|
160 | 157 | self.assertEqual(req.collapse_key, "456789")
|
161 | 158 |
|
| 159 | + @mock.patch("aioapns.client.APNsCertConnectionPool", autospec=True) |
| 160 | + @mock.patch("aioapns.client.APNsKeyConnectionPool", autospec=True) |
| 161 | + def test_aioapns_err_func(self, mock_cert_pool, mock_key_pool): |
| 162 | + mock_cert_pool.return_value.send_notification = mock.AsyncMock() |
| 163 | + result = NotificationResult( |
| 164 | + "123", "400" |
| 165 | + ) |
| 166 | + mock_cert_pool.return_value.send_notification.return_value = result |
| 167 | + err_func = mock.AsyncMock() |
| 168 | + with pytest.raises(Exception): |
| 169 | + apns_send_message( |
| 170 | + "123", |
| 171 | + "sample", |
| 172 | + creds=TokenCredentials( |
| 173 | + key="aaa", |
| 174 | + key_id="bbb", |
| 175 | + team_id="ccc", |
| 176 | + ), |
| 177 | + topic="default", |
| 178 | + err_func=err_func, |
| 179 | + ) |
| 180 | + mock_cert_pool.assert_called_once() |
| 181 | + mock_cert_pool.return_value.send_notification.assert_called_once() |
| 182 | + mock_cert_pool.return_value.send_notification.assert_awaited_once() |
| 183 | + err_func.assert_called_with( |
| 184 | + mock.ANY, result |
| 185 | + ) |
| 186 | + |
162 | 187 | # def test_bad_priority(self):
|
163 | 188 | # with mock.patch("apns2.credentials.init_context"):
|
164 | 189 | # with mock.patch("apns2.client.APNsClient.connect"):
|
|
0 commit comments