Skip to content

Commit cc2272d

Browse files
committed
Add support of python3 for prune_devices management command
1 parent 23b4561 commit cc2272d

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

push_notifications/apns.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html
55
"""
66

7+
import codecs
78
import json
89
import ssl
910
import struct
@@ -231,5 +232,5 @@ def apns_fetch_inactive_ids():
231232
# Maybe we should have a flag to return the timestamp?
232233
# It doesn't seem that useful right now, though.
233234
for tStamp, registration_id in _apns_receive_feedback(socket):
234-
inactive_ids.append(registration_id.encode('hex'))
235+
inactive_ids.append(codecs.encode(registration_id, 'hex_codec'))
235236
return inactive_ids

tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
from test_models import *
22
from test_gcm_push_payload import *
33
from test_apns_push_payload import *
4+
from test_management_commands import *

tests/test_management_commands.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import mock
2+
3+
from django.core.management import call_command
4+
5+
from django.test import TestCase
6+
from push_notifications.apns import _apns_send, APNSDataOverflow
7+
8+
9+
class CommandsTestCase(TestCase):
10+
11+
def test_prune_devices(self):
12+
from push_notifications.models import APNSDevice
13+
14+
device = APNSDevice.objects.create(
15+
registration_id="616263", # hex encoding of b'abc'
16+
)
17+
with mock.patch(
18+
'push_notifications.apns._apns_create_socket_to_feedback',
19+
mock.MagicMock()):
20+
with mock.patch('push_notifications.apns._apns_receive_feedback',
21+
mock.MagicMock()) as receiver:
22+
receiver.side_effect = lambda s: [(b'', b'abc')]
23+
call_command('prune_devices')
24+
device = APNSDevice.objects.get(pk=device.pk)
25+
self.assertFalse(device.active)

0 commit comments

Comments
 (0)