@@ -47,6 +47,68 @@ def test_send():
4747    msg_id  =  messaging .send (msg , dry_run = True )
4848    assert  re .match ('^projects/.*/messages/.*$' , msg_id )
4949
50+ def  test_send_all ():
51+     messages  =  [
52+         messaging .Message (
53+             topic = 'foo-bar' , notification = messaging .Notification ('Title' , 'Body' )),
54+         messaging .Message (
55+             topic = 'foo-bar' , notification = messaging .Notification ('Title' , 'Body' )),
56+         messaging .Message (
57+             token = 'not-a-token' , notification = messaging .Notification ('Title' , 'Body' )),
58+     ]
59+ 
60+     batch_response  =  messaging .send_all (messages , dry_run = True )
61+ 
62+     assert  batch_response .success_count  ==  2 
63+     assert  batch_response .failure_count  ==  1 
64+     assert  len (batch_response .responses ) ==  3 
65+ 
66+     response  =  batch_response .responses [0 ]
67+     assert  response .success  is  True 
68+     assert  response .exception  is  None 
69+     assert  re .match ('^projects/.*/messages/.*$' , response .message_id )
70+ 
71+     response  =  batch_response .responses [1 ]
72+     assert  response .success  is  True 
73+     assert  response .exception  is  None 
74+     assert  re .match ('^projects/.*/messages/.*$' , response .message_id )
75+ 
76+     response  =  batch_response .responses [2 ]
77+     assert  response .success  is  False 
78+     assert  response .exception  is  not None 
79+     assert  response .message_id  is  None 
80+ 
81+ def  test_send_one_hundred ():
82+     messages  =  []
83+     for  msg_number  in  range (100 ):
84+         topic  =  'foo-bar-{0}' .format (msg_number  %  10 )
85+         messages .append (messaging .Message (topic = topic ))
86+ 
87+     batch_response  =  messaging .send_all (messages , dry_run = True )
88+ 
89+     assert  batch_response .success_count  ==  100 
90+     assert  batch_response .failure_count  ==  0 
91+     assert  len (batch_response .responses ) ==  100 
92+     for  response  in  batch_response .responses :
93+         assert  response .success  is  True 
94+         assert  response .exception  is  None 
95+         assert  re .match ('^projects/.*/messages/.*$' , response .message_id )
96+ 
97+ def  test_send_multicast ():
98+     multicast  =  messaging .MulticastMessage (
99+         notification = messaging .Notification ('Title' , 'Body' ),
100+         tokens = ['not-a-token' , 'also-not-a-token' ])
101+ 
102+     batch_response  =  messaging .send_multicast (multicast )
103+ 
104+     assert  batch_response .success_count  is  0 
105+     assert  batch_response .failure_count  ==  2 
106+     assert  len (batch_response .responses ) ==  2 
107+     for  response  in  batch_response .responses :
108+         assert  response .success  is  False 
109+         assert  response .exception  is  not None 
110+         assert  response .message_id  is  None 
111+ 
50112def  test_subscribe ():
51113    resp  =  messaging .subscribe_to_topic (_REGISTRATION_TOKEN , 'mock-topic' )
52114    assert  resp .success_count  +  resp .failure_count  ==  1 
0 commit comments