@@ -102,11 +102,8 @@ class TestMulticastMessage:
102102 def test_invalid_targets (self ):
103103 with pytest .raises (ValueError ) as excinfo :
104104 messaging .MulticastMessage ()
105- assert str (excinfo .value ) == "Must specify either 'tokens' or 'fids'."
106-
107- with pytest .raises (ValueError ) as excinfo :
108- messaging .MulticastMessage (tokens = ['token' ], fids = ['fid' ])
109- assert str (excinfo .value ) == "Must specify either 'tokens' or 'fids'."
105+ expected = "Must specify at least one of MulticastMessage.tokens or MulticastMessage.fids."
106+ assert str (excinfo .value ) == expected
110107
111108 @pytest .mark .parametrize ('tokens' , NON_LIST_ARGS )
112109 def test_invalid_tokens_type (self , tokens ):
@@ -122,7 +119,7 @@ def test_invalid_tokens_type(self, tokens):
122119 def test_tokens_over_500 (self ):
123120 with pytest .raises (ValueError ) as excinfo :
124121 messaging .MulticastMessage (tokens = ['token' for _ in range (0 , 501 )])
125- expected = 'MulticastMessage. tokens must not contain more than 500 tokens .'
122+ expected = 'Total number of tokens and fids must not exceed 500.'
126123 assert str (excinfo .value ) == expected
127124
128125 def test_tokens_type (self ):
@@ -146,7 +143,7 @@ def test_invalid_fids_type(self, fids):
146143 def test_fids_over_500 (self ):
147144 with pytest .raises (ValueError ) as excinfo :
148145 messaging .MulticastMessage (fids = ['fid' for _ in range (0 , 501 )])
149- expected = 'MulticastMessage. fids must not contain more than 500 fids .'
146+ expected = 'Total number of tokens and fids must not exceed 500.'
150147 assert str (excinfo .value ) == expected
151148
152149 def test_fids_type (self ):
@@ -156,13 +153,27 @@ def test_fids_type(self):
156153 message = messaging .MulticastMessage (fids = ['fid' for _ in range (0 , 500 )])
157154 assert len (message .fids ) == 500
158155
156+ def test_combined_over_500 (self ):
157+ with pytest .raises (ValueError ) as excinfo :
158+ messaging .MulticastMessage (
159+ tokens = ['token' for _ in range (0 , 250 )],
160+ fids = ['fid' for _ in range (0 , 251 )]
161+ )
162+ expected = 'Total number of tokens and fids must not exceed 500.'
163+ assert str (excinfo .value ) == expected
164+
165+ def test_mixed_targets (self ):
166+ message = messaging .MulticastMessage (tokens = ['token' ], fids = ['fid' ])
167+ assert len (message .tokens ) == 1
168+ assert len (message .fids ) == 1
169+
159170 def test_tokens_deprecation_warning (self ):
160- msg = 'MulticastMessage.tokens is deprecated. Use fids instead.'
171+ msg = 'MulticastMessage.tokens is deprecated. Use MulticastMessage. fids instead.'
161172 with pytest .warns (DeprecationWarning , match = msg ):
162173 messaging .MulticastMessage (tokens = ['token' ])
163174
164175 def test_tokens_deprecation_warning_positional (self ):
165- msg = 'MulticastMessage.tokens is deprecated. Use fids instead.'
176+ msg = 'MulticastMessage.tokens is deprecated. Use MulticastMessage. fids instead.'
166177 with pytest .warns (DeprecationWarning , match = msg ):
167178 messaging .MulticastMessage (['token' ])
168179
@@ -222,7 +233,7 @@ def test_empty_message(self):
222233 check_encoding (messaging .Message (condition = 'value' ), {'condition' : 'value' })
223234
224235 def test_token_deprecation_warning (self ):
225- msg = 'Message.token is deprecated. Use fid instead.'
236+ msg = 'Message.token is deprecated. Use Message. fid instead.'
226237 with pytest .warns (DeprecationWarning , match = msg ):
227238 messaging .Message (token = 'value' )
228239
@@ -2290,6 +2301,20 @@ def test_send_each_for_multicast_fids(self):
22902301 assert all (r .success for r in batch_response .responses )
22912302 assert not any (r .exception for r in batch_response .responses )
22922303
2304+ def test_send_each_for_multicast_mixed (self ):
2305+ payload1 = json .dumps ({'name' : 'message-id1' })
2306+ payload2 = json .dumps ({'name' : 'message-id2' })
2307+ _ = self ._instrument_messaging_service (
2308+ response_dict = {'foo1' : [200 , payload1 ], 'foo2' : [200 , payload2 ]})
2309+ msg = messaging .MulticastMessage (tokens = ['foo1' ], fids = ['foo2' ])
2310+ batch_response = messaging .send_each_for_multicast (msg , dry_run = True )
2311+ assert batch_response .success_count == 2
2312+ assert batch_response .failure_count == 0
2313+ assert len (batch_response .responses ) == 2
2314+ assert [r .message_id for r in batch_response .responses ] == ['message-id1' , 'message-id2' ]
2315+ assert all (r .success for r in batch_response .responses )
2316+ assert not any (r .exception for r in batch_response .responses )
2317+
22932318 @respx .mock
22942319 @pytest .mark .asyncio
22952320 async def test_send_each_for_multicast_async (self ):
0 commit comments