Commit fc605d59 authored by hupantingxue's avatar hupantingxue

1. Fix issue: silent push cannot disable sound;

2. Fix example options issue;
3. Add silent push test case;
parent 669eece8
......@@ -6,5 +6,5 @@ push = _jpush.create_push()
push.audience = jpush.all_
push.notification = jpush.notification(alert="Hello, world!")
push.platform = jpush.all_
push.options = {"time_to_live":86400, "send no":12345,"apns_production":True}
push.options = {"time_to_live":86400, "sendno":12345,"apns_production":True}
push.send()
import jpush as jpush
from conf import app_key, master_secret
_jpush = jpush.JPush(app_key, master_secret)
push = _jpush.create_push()
push.audience = jpush.all_
ios_msg = jpush.ios(alert="Hello, IOS JPush!", badge="+1", extras={'k1':'v1'}, sound_disable=True)
android_msg = jpush.android(alert="Hello, android msg")
push.notification = jpush.notification(alert="Hello, JPush!", android=android_msg, ios=ios_msg)
push.platform = jpush.all_
push.send()
......@@ -45,8 +45,7 @@ class Push(object):
response = self._jpush._request('POST', body,
common.PUSH_URL, 'application/json', version=3)
data = response.json()
print (response.content)
return PushResponse(response)
......
......@@ -27,7 +27,7 @@ def notification(alert=None, ios=None, android=None, winphone=None):
def ios(alert=None, badge=None, sound=None, content_available=False,
extras=None):
extras=None, sound_disable=False):
"""iOS/APNS specific platform override payload.
:keyword alert: iOS format alert, as either a string or dictionary.
......@@ -37,6 +37,7 @@ def ios(alert=None, badge=None, sound=None, content_available=False,
for Newsstand iOS applications.
:keyword extra: A set of key/value pairs to include in the push payload
sent to the device.
:keyword sound_disalbe: Disable sound to implement slient push.
>>> ios(alert='Hello!', sound='cat.caf',
... extra={'articleid': '12345'})
......@@ -54,6 +55,7 @@ def ios(alert=None, badge=None, sound=None, content_available=False,
if isinstance(badge, str) and not VALID_AUTOBADGE.match(badge):
raise ValueError("Invalid iOS autobadge value")
payload['badge'] = badge
if not sound_disable:
if sound is not None:
payload['sound'] = sound
else:
......@@ -64,7 +66,6 @@ def ios(alert=None, badge=None, sound=None, content_available=False,
payload['extras'] = extras
return payload
def android(alert, title=None, builder_id=None, extras=None):
"""Android specific platform override payload.
......
......@@ -13,6 +13,12 @@ class TestMessage(unittest.TestCase):
{'ios': {'sound': 'a.caf', 'extras': {'k1': 'v1'}, 'badge': '+1', 'alert': 'Hello'}}
)
def test_iossilent(self):
self.assertEqual(
jpush.notification(ios=jpush.ios(alert="Hello", badge="+1", extras={'k1':'v1'}, sound_disable=True)),
{'ios': {'extras': {'k1': 'v1'}, 'badge': '+1', 'alert': 'Hello'}}
)
def test_android(self):
self.assertEqual(
jpush.notification(android=jpush.android(alert="Hello", extras={'k2':'v2'})),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment