Skip to content

Commit 08cc892

Browse files
committed
chore(fcm): Add integration tests for AndroidConfigV2
1 parent 287bbd0 commit 08cc892

1 file changed

Lines changed: 151 additions & 0 deletions

File tree

‎integration/test_messaging.py‎

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,139 @@ def test_send():
7171
msg_id = messaging.send(msg, dry_run=True)
7272
assert re.match('^projects/.*/messages/.*$', msg_id)
7373

74+
75+
def _full_android_notification_v2():
76+
return messaging.AndroidNotificationV2(
77+
title='test.title',
78+
body='test.body',
79+
icon='test.icon',
80+
color='#AABBCC',
81+
sound='test.sound',
82+
tag='test.tag',
83+
id=42,
84+
click_action='test.click.action',
85+
body_loc_key='test.body.loc.key',
86+
body_loc_args=['body.arg1', 'body.arg2'],
87+
title_loc_key='test.title.loc.key',
88+
title_loc_args=['title.arg1', 'title.arg2'],
89+
channel_id='test.channel.id',
90+
image='https://example.com/image.png',
91+
ticker='test.ticker',
92+
sticky=True,
93+
event_time=datetime.now(),
94+
local_only=True,
95+
notification_priority='high',
96+
vibrate_timings_millis=[100, 50, 250],
97+
default_vibrate_timings=False,
98+
default_sound=True,
99+
light_settings=messaging.LightSettings(
100+
color='#AABBCC',
101+
light_on_duration_millis=200,
102+
light_off_duration_millis=300,
103+
),
104+
default_light_settings=False,
105+
visibility='private',
106+
notification_count=1,
107+
)
108+
109+
110+
def _full_android_config_v2_base(**kwargs):
111+
return messaging.AndroidConfigV2(
112+
collapse_key='test-key',
113+
ttl=5,
114+
restricted_package_name='com.google.firebase.testing',
115+
data={'androidFoo': 'androidBar'},
116+
fcm_options=messaging.AndroidFCMOptions(analytics_label='test-analytics'),
117+
direct_boot_ok=True,
118+
bandwidth_constrained_ok=True,
119+
restricted_satellite_ok=True,
120+
**kwargs,
121+
)
122+
123+
124+
def _android_v2_remote_notification_message():
125+
return messaging.Message(
126+
topic='foo-bar',
127+
notification=messaging.Notification('Title', 'Body'),
128+
android_v2=_full_android_config_v2_base(
129+
remote_notification=messaging.AndroidRemoteNotification(
130+
mutable_content=True,
131+
use_as_v1_data_message=True,
132+
notification=_full_android_notification_v2(),
133+
),
134+
),
135+
)
136+
137+
138+
def _android_v2_minimal_remote_notification_message():
139+
return messaging.Message(
140+
topic='foo-bar',
141+
android_v2=messaging.AndroidConfigV2(
142+
remote_notification=messaging.AndroidRemoteNotification(
143+
notification=messaging.AndroidNotificationV2(
144+
title='test.title',
145+
body='test.body',
146+
),
147+
),
148+
),
149+
)
150+
151+
152+
def _android_v2_background_sync_message():
153+
return messaging.Message(
154+
topic='foo-bar',
155+
android_v2=_full_android_config_v2_base(
156+
background_sync=messaging.AndroidBackgroundSyncMessage(),
157+
),
158+
)
159+
160+
161+
def _android_v2_minimal_background_sync_message():
162+
return messaging.Message(
163+
topic='foo-bar',
164+
android_v2=messaging.AndroidConfigV2(
165+
background_sync=messaging.AndroidBackgroundSyncMessage(),
166+
),
167+
)
168+
169+
170+
def test_send_android_v2_remote_notification():
171+
msg_id = messaging.send(_android_v2_remote_notification_message(), dry_run=True)
172+
assert re.match('^projects/.*/messages/.*$', msg_id)
173+
174+
175+
def test_send_android_v2_minimal_remote_notification():
176+
msg_id = messaging.send(_android_v2_minimal_remote_notification_message(), dry_run=True)
177+
assert re.match('^projects/.*/messages/.*$', msg_id)
178+
179+
180+
def test_send_android_v2_background_sync():
181+
msg_id = messaging.send(_android_v2_background_sync_message(), dry_run=True)
182+
assert re.match('^projects/.*/messages/.*$', msg_id)
183+
184+
185+
def test_send_android_v2_minimal_background_sync():
186+
msg_id = messaging.send(_android_v2_minimal_background_sync_message(), dry_run=True)
187+
assert re.match('^projects/.*/messages/.*$', msg_id)
188+
189+
190+
def test_send_each_android_v2():
191+
messages = [
192+
_android_v2_remote_notification_message(),
193+
_android_v2_minimal_remote_notification_message(),
194+
_android_v2_background_sync_message(),
195+
_android_v2_minimal_background_sync_message(),
196+
]
197+
batch_response = messaging.send_each(messages, dry_run=True)
198+
assert batch_response.success_count == 4
199+
assert batch_response.failure_count == 0
200+
assert len(batch_response.responses) == 4
201+
for response in batch_response.responses:
202+
assert response.success is True
203+
assert response.exception is None
204+
assert re.match('^projects/.*/messages/.*$', response.message_id)
205+
206+
74207
def test_send_invalid_token():
75208
msg = messaging.Message(
76209
token=_REGISTRATION_TOKEN,
@@ -244,3 +377,21 @@ async def test_send_each_for_multicast_async():
244377
assert response.success is False
245378
assert response.exception is not None
246379
assert response.message_id is None
380+
381+
382+
@pytest.mark.asyncio(loop_scope="session")
383+
async def test_send_each_android_v2_async():
384+
messages = [
385+
_android_v2_remote_notification_message(),
386+
_android_v2_minimal_remote_notification_message(),
387+
_android_v2_background_sync_message(),
388+
_android_v2_minimal_background_sync_message(),
389+
]
390+
batch_response = await messaging.send_each_async(messages, dry_run=True)
391+
assert batch_response.success_count == 4
392+
assert batch_response.failure_count == 0
393+
assert len(batch_response.responses) == 4
394+
for response in batch_response.responses:
395+
assert response.success is True
396+
assert response.exception is None
397+
assert re.match('^projects/.*/messages/.*$', response.message_id)

0 commit comments

Comments
 (0)