def test_adding_data_str(self):
        PushMessage.queue_message(self.user, 'hi', data="string")
        self.assertTrue(PushMessage.objects.all().count() > 0)

        PushMessage.send_pending_messages()

        unsent = PushMessage.objects.filter(sent=False).count()
        self.assertEqual(0, unsent)
    def test_adding_data_str(self):
        PushMessage.queue_message(self.user, 'hi', data="string")
        self.assertTrue(PushMessage.objects.all().count() > 0)

        PushMessage.send_pending_messages()

        unsent = PushMessage.objects.filter(sent=False).count()
        self.assertEqual(0, unsent)
    def test_message_sent(self):
        PushMessage.queue_message(self.user, 'hi')
        unsent = PushMessage.objects.filter(sent=False).count()
        self.assertEqual(1, unsent)

        PushMessage.send_pending_messages()

        unsent = PushMessage.objects.filter(sent=False).count()
        self.assertEqual(0, unsent)
    def test_message_sent(self):
        PushMessage.queue_message(self.user, 'hi')
        unsent = PushMessage.objects.filter(sent=False).count()
        self.assertEqual(1, unsent)

        PushMessage.send_pending_messages()

        unsent = PushMessage.objects.filter(sent=False).count()
        self.assertEqual(0, unsent)
 def test_future_schedule(self):
     future = datetime.max.replace(tzinfo=timezone.utc)
     PushMessage.queue_message(self.user, 'hi', readytime=future)
     self.assertTrue(PushMessage.objects.filter(sent=False).count() > 0)
     send_count = PushMessage.send_pending_messages()
     self.assertEqual(0, send_count)
     self.assertTrue(PushMessage.objects.filter(sent=False).count() > 0)
 def test_future_schedule(self):
     future = datetime.max.replace(tzinfo=timezone.utc)
     PushMessage.queue_message(self.user, 'hi', readytime=future)
     self.assertTrue(PushMessage.objects.filter(sent=False).count() > 0)
     send_count = PushMessage.send_pending_messages()
     self.assertEqual(0, send_count)
     self.assertTrue(PushMessage.objects.filter(sent=False).count() > 0)
    def test_custom_badge_counter(self):
        self.msg_str = ''

        @classmethod
        def mock_get_connection(cls):
            class MockSocket(object):
                 def send(mockself, msg):
                     self.msg_str = str(msg)

                 def close(mockself):
                     pass

            return MockSocket()

        MobileDevice.get_push_service_connection = mock_get_connection
        PushMessage.queue_message(self.user, 'hi')
        with override_settings(NOTIFY_BADGE='notify.tests.MockBadgeCounter'):
            PushMessage.send_pending_messages()

        self.assertTrue(0 < self.msg_str.find('badge":42'))
    def test_custom_badge_counter(self):
        self.msg_str = ''

        @classmethod
        def mock_get_connection(cls):
            class MockSocket(object):
                def send(mockself, msg):
                    self.msg_str = str(msg)

                def close(mockself):
                    pass

            return MockSocket()

        MobileDevice.get_push_service_connection = mock_get_connection
        PushMessage.queue_message(self.user, 'hi')
        with override_settings(NOTIFY_BADGE='notify.tests.MockBadgeCounter'):
            PushMessage.send_pending_messages()

        self.assertTrue(0 < self.msg_str.find('badge":42'))