Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
4b6a1716
Commit
4b6a1716
authored
Apr 27, 2015
by
Nimisha Asthagiri
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #7805 from edx/mobile/push-notification-ios
MA-668 Mobile Push Notification payload update
parents
4a4c3c56
c8e0095f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
11 deletions
+41
-11
cms/djangoapps/contentstore/push_notification.py
+30
-10
cms/djangoapps/contentstore/views/tests/test_course_updates.py
+11
-1
No files found.
cms/djangoapps/contentstore/push_notification.py
View file @
4b6a1716
...
...
@@ -2,6 +2,7 @@
Helper methods for push notifications from Studio.
"""
from
uuid
import
uuid4
from
django.conf
import
settings
from
logging
import
exception
as
log_exception
...
...
@@ -46,17 +47,36 @@ def send_push_course_update(course_key_string, course_subscription_id, course_di
settings
.
PARSE_KEYS
[
"APPLICATION_ID"
],
settings
.
PARSE_KEYS
[
"REST_API_KEY"
],
)
push_payload
=
{
"action"
:
"course.announcement"
,
"notification-id"
:
unicode
(
uuid4
()),
"course-id"
:
course_key_string
,
"course-name"
:
course_display_name
,
}
push_channels
=
[
course_subscription_id
]
# Push to all Android devices
Push
.
alert
(
data
=
push_payload
,
channels
=
{
"$in"
:
push_channels
},
where
=
{
"deviceType"
:
"android"
},
)
# Push to all iOS devices
# With additional payload so that
# 1. The push is displayed automatically
# 2. The app gets it even in the background.
# See http://stackoverflow.com/questions/19239737/silent-push-notification-in-ios-7-does-not-work
push_payload
.
update
({
"alert"
:
""
,
"content-available"
:
1
})
Push
.
alert
(
data
=
{
"course-id"
:
course_key_string
,
"action"
:
"course.announcement"
,
"action-loc-key"
:
"VIEW_BUTTON"
,
"loc-key"
:
"COURSE_ANNOUNCEMENT_NOTIFICATION_BODY"
,
"loc-args"
:
[
course_display_name
],
"title-loc-key"
:
"COURSE_ANNOUNCEMENT_NOTIFICATION_TITLE"
,
"title-loc-args"
:
[],
},
channels
=
[
course_subscription_id
],
data
=
push_payload
,
channels
=
{
"$in"
:
push_channels
},
where
=
{
"deviceType"
:
"ios"
},
)
except
ParseError
as
error
:
log_exception
(
error
.
message
)
cms/djangoapps/contentstore/views/tests/test_course_updates.py
View file @
4b6a1716
...
...
@@ -303,4 +303,14 @@ class CourseUpdateTest(CourseTestCase):
def
test_notifications_sent_to_parse
(
self
,
mock_parse_push
):
PushNotificationConfig
(
enabled
=
True
)
.
save
()
self
.
post_course_update
(
send_push_notification
=
True
)
self
.
assertTrue
(
mock_parse_push
.
alert
.
called
)
self
.
assertEquals
(
mock_parse_push
.
alert
.
call_count
,
2
)
@override_settings
(
PARSE_KEYS
=
{
"APPLICATION_ID"
:
"TEST_APPLICATION_ID"
,
"REST_API_KEY"
:
"TEST_REST_API_KEY"
})
@patch
(
"contentstore.push_notification.log_exception"
)
@patch
(
"contentstore.push_notification.Push"
)
def
test_notifications_error_from_parse
(
self
,
mock_parse_push
,
mock_log_exception
):
PushNotificationConfig
(
enabled
=
True
)
.
save
()
from
parse_rest.core
import
ParseError
mock_parse_push
.
alert
.
side_effect
=
ParseError
self
.
post_course_update
(
send_push_notification
=
True
)
self
.
assertTrue
(
mock_log_exception
.
called
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment