Skip to content

Commit

Permalink
Add support of python3 for prune_devices management command
Browse files Browse the repository at this point in the history
  • Loading branch information
ticosax committed Jun 23, 2015
1 parent 23b4561 commit cc2272d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
3 changes: 2 additions & 1 deletion push_notifications/apns.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html
"""

import codecs
import json
import ssl
import struct
Expand Down Expand Up @@ -231,5 +232,5 @@ def apns_fetch_inactive_ids():
# Maybe we should have a flag to return the timestamp?
# It doesn't seem that useful right now, though.
for tStamp, registration_id in _apns_receive_feedback(socket):
inactive_ids.append(registration_id.encode('hex'))
inactive_ids.append(codecs.encode(registration_id, 'hex_codec'))
return inactive_ids
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from test_models import *
from test_gcm_push_payload import *
from test_apns_push_payload import *
from test_management_commands import *
25 changes: 25 additions & 0 deletions tests/test_management_commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import mock

from django.core.management import call_command

from django.test import TestCase
from push_notifications.apns import _apns_send, APNSDataOverflow


class CommandsTestCase(TestCase):

def test_prune_devices(self):
from push_notifications.models import APNSDevice

device = APNSDevice.objects.create(
registration_id="616263", # hex encoding of b'abc'
)
with mock.patch(
'push_notifications.apns._apns_create_socket_to_feedback',
mock.MagicMock()):
with mock.patch('push_notifications.apns._apns_receive_feedback',
mock.MagicMock()) as receiver:
receiver.side_effect = lambda s: [(b'', b'abc')]
call_command('prune_devices')
device = APNSDevice.objects.get(pk=device.pk)
self.assertFalse(device.active)

0 comments on commit cc2272d

Please sign in to comment.