From f2c7e765a9f867f7e3fe90ceee27c555c8b8df0a Mon Sep 17 00:00:00 2001 From: hiranya911 Date: Mon, 20 May 2019 15:21:32 -0700 Subject: [PATCH 1/2] Added integration tests for the new multicast APIs --- CHANGELOG.md | 2 ++ integration/test_messaging.py | 59 +++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7dadefbda..c9a3bc42e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Unreleased +- [added] Added new `send_all()` and `send_multicast()` APIs to the + `messasing` module. - [added] Added a new `auth.DELETE_ATTRIBUTE` sentinel value, which can be used to delete `phone_number`, `display_name`, `photo_url` and `custom_claims` attributes from a user account. It is now recommended to use this sentinel diff --git a/integration/test_messaging.py b/integration/test_messaging.py index e58737c70..46dd9dcb3 100644 --- a/integration/test_messaging.py +++ b/integration/test_messaging.py @@ -47,6 +47,65 @@ def test_send(): msg_id = messaging.send(msg, dry_run=True) assert re.match('^projects/.*/messages/.*$', msg_id) +def test_send_all(): + messages = [ + messaging.Message(topic='foo-bar', notification=messaging.Notification('Title', 'Body')), + messaging.Message(topic='foo-bar', notification=messaging.Notification('Title', 'Body')), + messaging.Message(token='not-a-token', notification=messaging.Notification('Title', 'Body')), + ] + + batch_response = messaging.send_all(messages, dry_run=True) + + assert batch_response.success_count == 2 + assert batch_response.failure_count == 1 + assert len(batch_response.responses) == 3 + + response = batch_response.responses[0] + assert response.success is True + assert response.exception is None + assert re.match('^projects/.*/messages/.*$', response.message_id) + + response = batch_response.responses[1] + assert response.success is True + assert response.exception is None + assert re.match('^projects/.*/messages/.*$', response.message_id) + + response = batch_response.responses[2] + assert response.success is False + assert response.exception is not None + assert response.message_id is None + +def test_send_one_hundred(): + messages = [] + for i in range(100): + topic = 'foo-bar-{0}'.format(i % 10) + messages.append(messaging.Message(topic=topic)) + + batch_response = messaging.send_all(messages, dry_run=True) + + assert batch_response.success_count == 100 + assert batch_response.failure_count == 0 + assert len(batch_response.responses) == 100 + for response in batch_response.responses: + assert response.success is True + assert response.exception is None + assert re.match('^projects/.*/messages/.*$', response.message_id) + +def test_send_multicast(): + multicast = messaging.MulticastMessage( + notification=messaging.Notification('Title', 'Body'), + tokens=['not-a-token', 'also-not-a-token']) + + batch_response = messaging.send_multicast(multicast) + + assert batch_response.success_count is 0 + assert batch_response.failure_count == 2 + assert len(batch_response.responses) == 2 + for response in batch_response.responses: + assert response.success is False + assert response.exception is not None + assert response.message_id is None + def test_subscribe(): resp = messaging.subscribe_to_topic(_REGISTRATION_TOKEN, 'mock-topic') assert resp.success_count + resp.failure_count == 1 From 3fcb62908a63dcde473343f919155972c496e527 Mon Sep 17 00:00:00 2001 From: hiranya911 Date: Tue, 21 May 2019 15:22:39 -0700 Subject: [PATCH 2/2] Fixing a lint error --- integration/test_messaging.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/integration/test_messaging.py b/integration/test_messaging.py index 46dd9dcb3..7ebd5866a 100644 --- a/integration/test_messaging.py +++ b/integration/test_messaging.py @@ -49,9 +49,12 @@ def test_send(): def test_send_all(): messages = [ - messaging.Message(topic='foo-bar', notification=messaging.Notification('Title', 'Body')), - messaging.Message(topic='foo-bar', notification=messaging.Notification('Title', 'Body')), - messaging.Message(token='not-a-token', notification=messaging.Notification('Title', 'Body')), + messaging.Message( + topic='foo-bar', notification=messaging.Notification('Title', 'Body')), + messaging.Message( + topic='foo-bar', notification=messaging.Notification('Title', 'Body')), + messaging.Message( + token='not-a-token', notification=messaging.Notification('Title', 'Body')), ] batch_response = messaging.send_all(messages, dry_run=True) @@ -77,8 +80,8 @@ def test_send_all(): def test_send_one_hundred(): messages = [] - for i in range(100): - topic = 'foo-bar-{0}'.format(i % 10) + for msg_number in range(100): + topic = 'foo-bar-{0}'.format(msg_number % 10) messages.append(messaging.Message(topic=topic)) batch_response = messaging.send_all(messages, dry_run=True)