|
17 | 17 | from itertools import chain, repeat
|
18 | 18 | import json
|
19 | 19 | import numbers
|
| 20 | +import httpx |
20 | 21 | import respx
|
21 | 22 |
|
22 | 23 | from googleapiclient import http
|
@@ -2100,54 +2101,26 @@ async def test_send_each_async_error_500_pass_on_retry_config(self):
|
2100 | 2101 | assert all([r.success for r in batch_response.responses])
|
2101 | 2102 | assert not any([r.exception for r in batch_response.responses])
|
2102 | 2103 |
|
2103 |
| - # @respx.mock |
2104 |
| - # @pytest.mark.asyncio |
2105 |
| - # async def test_send_each_async_error_request(self): |
2106 |
| - # payload = json.dumps({ |
2107 |
| - # 'error': { |
2108 |
| - # 'status': 'INTERNAL', |
2109 |
| - # 'message': 'test INTERNAL error', |
2110 |
| - # 'details': [ |
2111 |
| - # { |
2112 |
| - # '@type': 'type.googleapis.com/google.firebase.fcm.v1.FcmError', |
2113 |
| - # 'errorCode': 'SOME_UNKNOWN_CODE', |
2114 |
| - # }, |
2115 |
| - # ], |
2116 |
| - # } |
2117 |
| - # }) |
2118 |
| - # responses = chain( |
2119 |
| - # [ |
2120 |
| - # httpx.ConnectError("Test request error", request=httpx.Request('POST', 'URL')) |
2121 |
| - # # respx.MockResponse(500, http_version='HTTP/2', content=payload), |
2122 |
| - # ], |
2123 |
| - # # repeat( |
2124 |
| - # respx.MockResponse(200, http_version='HTTP/2', json={'name': 'message-id1'})), |
2125 |
| - # # respx.MockResponse(200, http_version='HTTP/2', json={'name': 'message-id3'}), |
2126 |
| - # ) |
2127 |
| - |
2128 |
| - # # responses = repeat(respx.MockResponse(500, http_version='HTTP/2', content=payload)) |
2129 |
| - |
2130 |
| - # msg1 = messaging.Message(topic='foo1') |
2131 |
| - # route = respx.request( |
2132 |
| - # 'POST', |
2133 |
| - # 'https://fcm.googleapis.com/v1/projects/explicit-project-id/messages:send' |
2134 |
| - # ).mock(side_effect=responses) |
2135 |
| - # batch_response = await messaging.send_each_async([msg1], dry_run=True) |
2136 |
| - |
2137 |
| - # assert route.call_count == 1 |
2138 |
| - # assert batch_response.success_count == 0 |
2139 |
| - # assert batch_response.failure_count == 1 |
2140 |
| - # assert len(batch_response.responses) == 1 |
2141 |
| - # exception = batch_response.responses[0].exception |
2142 |
| - # assert isinstance(exception, exceptions.UnavailableError) |
2143 |
| - |
2144 |
| - # # assert route.call_count == 4 |
2145 |
| - # # assert batch_response.success_count == 1 |
2146 |
| - # # assert batch_response.failure_count == 0 |
2147 |
| - # # assert len(batch_response.responses) == 1 |
2148 |
| - # # assert [r.message_id for r in batch_response.responses] == ['message-id1'] |
2149 |
| - # # assert all([r.success for r in batch_response.responses]) |
2150 |
| - # # assert not any([r.exception for r in batch_response.responses]) |
| 2104 | + @respx.mock |
| 2105 | + @pytest.mark.asyncio |
| 2106 | + async def test_send_each_async_request_error(self): |
| 2107 | + responses = httpx.ConnectError("Test request error", request=httpx.Request( |
| 2108 | + 'POST', |
| 2109 | + 'https://fcm.googleapis.com/v1/projects/explicit-project-id/messages:send')) |
| 2110 | + |
| 2111 | + msg1 = messaging.Message(topic='foo1') |
| 2112 | + route = respx.request( |
| 2113 | + 'POST', |
| 2114 | + 'https://fcm.googleapis.com/v1/projects/explicit-project-id/messages:send' |
| 2115 | + ).mock(side_effect=responses) |
| 2116 | + batch_response = await messaging.send_each_async([msg1], dry_run=True) |
| 2117 | + |
| 2118 | + assert route.call_count == 1 |
| 2119 | + assert batch_response.success_count == 0 |
| 2120 | + assert batch_response.failure_count == 1 |
| 2121 | + assert len(batch_response.responses) == 1 |
| 2122 | + exception = batch_response.responses[0].exception |
| 2123 | + assert isinstance(exception, exceptions.UnavailableError) |
2151 | 2124 |
|
2152 | 2125 | @pytest.mark.parametrize('status', HTTP_ERROR_CODES)
|
2153 | 2126 | def test_send_each_detailed_error(self, status):
|
|
0 commit comments