import mock

from django.core.management import call_command

from django.test import TestCase


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, certificate: [(b'', b'abc')]
				call_command('prune_devices')
		device.refresh_from_db()
		self.assertFalse(device.active)
