forked from firebase/firebase-admin-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_messaging.py
More file actions
56 lines (47 loc) · 1.96 KB
/
test_messaging.py
File metadata and controls
56 lines (47 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Copyright 2017 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Integration tests for firebase_admin.messaging module."""
import re
from firebase_admin import messaging
_REGISTRATION_TOKEN = ('fGw0qy4TGgk:APA91bGtWGjuhp4WRhHXgbabIYp1jxEKI08ofj_v1bKhWAGJQ4e3arRCWzeTf'
'HaLz83mBnDh0aPWB1AykXAVUUGl2h1wT4XI6XazWpvY7RBUSYfoxtqSWGIm2nvWh2BOP1YG50'
'1SsRoE')
def test_send():
msg = messaging.Message(
topic='foo-bar',
notification=messaging.Notification('test-title', 'test-body'),
android=messaging.AndroidConfig(
restricted_package_name='com.google.firebase.demos',
notification=messaging.AndroidNotification(
title='android-title',
body='android-body'
)
),
apns=messaging.APNSConfig(payload=messaging.APNSPayload(
aps=messaging.Aps(
alert=messaging.ApsAlert(
title='apns-title',
body='apns-body'
)
)
))
)
msg_id = messaging.send(msg, dry_run=True)
assert re.match('^projects/.*/messages/.*$', msg_id)
def test_subscribe():
resp = messaging.subscribe_to_topic(_REGISTRATION_TOKEN, 'mock-topic')
assert resp.success_count + resp.failure_count == 1
def test_unsubscribe():
resp = messaging.unsubscribe_from_topic(_REGISTRATION_TOKEN, 'mock-topic')
assert resp.success_count + resp.failure_count == 1