Skip to content
This repository has been archived by the owner on May 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #176 from edx/aamishbaloch/YONK-837
Browse files Browse the repository at this point in the history
YONK-837: Added notification type in course announcement payload
  • Loading branch information
aamishbaloch authored Dec 19, 2017
2 parents 1d02faf + 81af8e0 commit 71aaba6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
16 changes: 13 additions & 3 deletions edx_notifications/channels/tests/test_urban_airship.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def setUp(self):
def test_tag_group_notification(self, mock_ua_push_api):
"""
Test publish notification to a tag group
:return:
"""
mock_ua_push_api.return_value = {'ok': 'true'}
self.msg.payload['open_url'] = 'http://example.com'
Expand All @@ -57,7 +56,6 @@ def test_tag_group_notification(self, mock_ua_push_api):
def test_bulk_user_notification(self, mock_ua_push_api):
"""
Test publish notification to list of users
:return:
"""
mock_ua_push_api.return_value = {'ok': 'true'}
response = bulk_publish_notification_to_users([10, 11, 12], self.msg, preferred_channel='urban-airship')
Expand All @@ -67,8 +65,20 @@ def test_bulk_user_notification(self, mock_ua_push_api):
def test_single_user_notification(self, mock_ua_push_api):
"""
Test publish notification to a single user
:return:
"""
mock_ua_push_api.return_value = {'ok': 'true'}
response = publish_notification_to_user(10, self.msg, preferred_channel='urban-airship')
self.assertEqual(response['ok'], 'true')

@patch("edx_notifications.channels.urban_airship.UrbanAirshipNotificationChannelProvider.call_ua_push_api")
def test_tag_group_announcement(self, mock_ua_push_api):
"""
Test publish notification to a tag group when notification_type is present
"""
mock_ua_push_api.return_value = {'ok': 'true'}
self.msg.payload['open_url'] = 'http://example.com'
self.msg.payload['tag_group'] = 'enrollments'
self.msg.payload['notification_type'] = 'courseannouncement'
response = bulk_publish_notification_to_users([], self.msg, preferred_channel='urban-airship')
self.assertTrue(response)
self.assertEqual(response['ok'], 'true')
25 changes: 25 additions & 0 deletions edx_notifications/channels/urban_airship.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,35 @@ def bulk_dispatch_notification(self, user_ids, msg, exclude_user_ids=None, chann
if user_id not in exclude_user_ids:
actual_user_ids.append(user_id)
payload = self.create_bulk_user_payload(actual_user_ids, msg)

self._add_type_in_payload(msg, payload)
payload = json.dumps(payload)
api_credentials = channel_context.get('api_credentials') if channel_context else None
return self.call_ua_push_api(payload, api_credentials)

def _add_type_in_payload(self, msg, payload):
"""
Adds a notification type in payload if notification_type is present in the message
Notification types:
- courseannouncement
:param msg:
:param payload:
"""
if 'notification_type' in msg.payload:
extra = {
"extra": {
"notification_type": msg.payload['notification_type']
}
}

ios_android_extras = {
"ios": extra,
"android": extra,
}
payload['notification'].update(ios_android_extras)

@staticmethod
def create_tag_group_payload(msg):
"""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def load_requirements(*requirements_paths):

setup(
name='edx-notifications',
version='0.6.1',
version='0.6.3',
description='Notification subsystem for Open edX',
long_description=open('README.md').read(),
author='edX',
Expand Down

0 comments on commit 71aaba6

Please sign in to comment.