@@ -86,6 +86,68 @@ def test_send_malformed_token():
8686 with pytest .raises (exceptions .InvalidArgumentError ):
8787 messaging .send (msg , dry_run = True )
8888
89+ def test_send_each ():
90+ messages = [
91+ messaging .Message (
92+ topic = 'foo-bar' , notification = messaging .Notification ('Title' , 'Body' )),
93+ messaging .Message (
94+ topic = 'foo-bar' , notification = messaging .Notification ('Title' , 'Body' )),
95+ messaging .Message (
96+ token = 'not-a-token' , notification = messaging .Notification ('Title' , 'Body' )),
97+ ]
98+
99+ batch_response = messaging .send_each (messages , dry_run = True )
100+
101+ assert batch_response .success_count == 2
102+ assert batch_response .failure_count == 1
103+ assert len (batch_response .responses ) == 3
104+
105+ response = batch_response .responses [0 ]
106+ assert response .success is True
107+ assert response .exception is None
108+ assert re .match ('^projects/.*/messages/.*$' , response .message_id )
109+
110+ response = batch_response .responses [1 ]
111+ assert response .success is True
112+ assert response .exception is None
113+ assert re .match ('^projects/.*/messages/.*$' , response .message_id )
114+
115+ response = batch_response .responses [2 ]
116+ assert response .success is False
117+ assert isinstance (response .exception , exceptions .InvalidArgumentError )
118+ assert response .message_id is None
119+
120+ def test_send_each_500 ():
121+ messages = []
122+ for msg_number in range (500 ):
123+ topic = 'foo-bar-{0}' .format (msg_number % 10 )
124+ messages .append (messaging .Message (topic = topic ))
125+
126+ batch_response = messaging .send_each (messages , dry_run = True )
127+
128+ assert batch_response .success_count == 500
129+ assert batch_response .failure_count == 0
130+ assert len (batch_response .responses ) == 500
131+ for response in batch_response .responses :
132+ assert response .success is True
133+ assert response .exception is None
134+ assert re .match ('^projects/.*/messages/.*$' , response .message_id )
135+
136+ def test_send_each_for_multicast ():
137+ multicast = messaging .MulticastMessage (
138+ notification = messaging .Notification ('Title' , 'Body' ),
139+ tokens = ['not-a-token' , 'also-not-a-token' ])
140+
141+ batch_response = messaging .send_each_for_multicast (multicast )
142+
143+ assert batch_response .success_count == 0
144+ assert batch_response .failure_count == 2
145+ assert len (batch_response .responses ) == 2
146+ for response in batch_response .responses :
147+ assert response .success is False
148+ assert response .exception is not None
149+ assert response .message_id is None
150+
89151def test_send_all ():
90152 messages = [
91153 messaging .Message (
0 commit comments