Skip to content

Commit

Permalink
Merge pull request #17 from seporaitis/master
Browse files Browse the repository at this point in the history
Allow empty push notification.
  • Loading branch information
dgilland committed Dec 15, 2015
2 parents 1deead8 + c8fe2cf commit cd7bb94
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pushjack/__meta__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
__summary__ = 'Push notifications for APNS (iOS) and GCM (Android).'
__url__ = 'https://github.com/dgilland/pushjack'

__version__ = '1.2.0'
__version__ = '1.2.1'

__install_requires__ = ['requests']

Expand Down
13 changes: 1 addition & 12 deletions pushjack/apns.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,10 +501,6 @@ def to_dict(self):
'content-available': 1 if self.content_available else None
})

if not message['aps']:
# Don't include 'aps' field if empty.
del message['aps']

return message

def to_json(self):
Expand All @@ -513,11 +509,7 @@ def to_json(self):

def __len__(self):
"""Return length of serialized message."""
if not self.to_dict():
# Consider message length 0 if there is no message data.
return 0
else:
return len(self.to_json())
return len(self.to_json())


class APNSMessageStream(object):
Expand Down Expand Up @@ -767,9 +759,6 @@ def validate_tokens(tokens):

def validate_message(message):
"""Check whether `message` is valid."""
if len(message) == 0:
raise APNSMissingPayloadError('Notification body size cannot be 0')

if len(message) > APNS_MAX_NOTIFICATION_SIZE:
raise APNSInvalidPayloadSizeError(
('Notification body cannot exceed '
Expand Down
1 change: 0 additions & 1 deletion tests/test_apns.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ def test_apns_socket_write(apns_client, apns_socket):

@parametrize('exception,alert', [
(exceptions.APNSInvalidPayloadSizeError, '_' * 2049),
(exceptions.APNSMissingPayloadError, None)
])
def test_apns_invalid_payload_size(apns_client, exception, alert):
with mock.patch('pushjack.apns.APNSMessageStream.pack') as pack_frame:
Expand Down

0 comments on commit cd7bb94

Please sign in to comment.