Exemplo n.º 1
0
 def test_process_response_expired(self):
     pusher = Pusher()
     response = self._create_mocked_response(code=404,
                                             notification='Dropped',
                                             subscription='Expired')
     with self.assertRaises(SubscriptionExpiredError):
         pusher._processResponse(response)
Exemplo n.º 2
0
 def test_process_response_expired(self):
     pusher = Pusher()
     response = self._create_mocked_response(code=404,
                                             notification='Dropped',
                                             subscription='Expired')
     with self.assertRaises(SubscriptionExpiredError):
         pusher._processResponse(response)
Exemplo n.º 3
0
 def test_process_response_disconnected(self):
     pusher = Pusher()
     response = self._create_mocked_response(code=412,
                                             notification='Dropped',
                                             device='Disconnected')
     with self.assertRaises(DeviceDisconnectedError):
         pusher._processResponse(response)
Exemplo n.º 4
0
 def test_process_response_received(self):
     pusher = Pusher()
     response = self._create_mocked_response()
     status = pusher._processResponse(response)
     self.assertEqual(status.notification, 'Received')
     self.assertEqual(status.subscription, 'Active')
     self.assertEqual(status.device, 'Connected')
Exemplo n.º 5
0
 def test_process_response_disconnected(self):
     pusher = Pusher()
     response = self._create_mocked_response(code=412,
                                             notification='Dropped',
                                             device='Disconnected')
     with self.assertRaises(DeviceDisconnectedError):
         pusher._processResponse(response)
Exemplo n.º 6
0
 def test_process_response_received(self):
     pusher = Pusher()
     response = self._create_mocked_response()
     status = pusher._processResponse(response)
     self.assertEqual(status.notification, 'Received')
     self.assertEqual(status.subscription, 'Active')
     self.assertEqual(status.device, 'Connected')
Exemplo n.º 7
0
 def _assert_raises_HTTPError_with_extras(self, code):
     pusher = Pusher()
     resp = self._create_mocked_response(code=code)
     try:
         pusher._processErrorResponse(resp)
         self.assertFail()
     except HTTPError as error:
         self.assertEqual(code, error.extra['response code'])
         if code in Pusher.RESPONSE_TO_ERROR:
             self.assertEqual(Pusher.RESPONSE_TO_ERROR[code], error.message)
         else:
             self.assertEqual('Unknown response code', error.message)
Exemplo n.º 8
0
    def test_send_unprocessable(self):
        pusher = Pusher()
        notification = self._create_mocked_notification()
        response = self._create_mocked_response(code=400)

        pusher._agent.request = Mock(return_value=response)
        pusher._processResponse = Mock()
        pusher._processErrorResponse = Mock()

        pusher.send(notification)

        pusher._processErrorResponse.assert_called_once_with(response)
        self.assertFalse(pusher._processResponse.called)
Exemplo n.º 9
0
 def _assert_raises_HTTPError_with_extras(self, code):
     pusher = Pusher()
     resp = self._create_mocked_response(code=code)
     try:
         pusher._processErrorResponse(resp)
         self.assertFail()
     except HTTPError as error:
         self.assertEqual(code, error.extra['response code'])
         if code in Pusher.RESPONSE_TO_ERROR:
             self.assertEqual(Pusher.RESPONSE_TO_ERROR[code],
                              error.message)
         else:
             self.assertEqual('Unknown response code', error.message)
Exemplo n.º 10
0
    def test_send_unprocessable(self):
        pusher = Pusher()
        notification = self._create_mocked_notification()
        response = self._create_mocked_response(code=400)

        pusher._agent.request = Mock(return_value=response)
        pusher._processResponse = Mock()
        pusher._processErrorResponse = Mock()

        pusher.send(notification)

        pusher._processErrorResponse.assert_called_once_with(response)
        self.assertFalse(pusher._processResponse.called)
Exemplo n.º 11
0
 def test_process_response_unknown_status(self):
     pusher = Pusher()
     response = self._create_mocked_response(notification='foo')
     with self.assertRaises(InvalidResponseError):
         pusher._processResponse(response)
Exemplo n.º 12
0
 def test_extract_header_missing(self):
     pusher = Pusher()
     resp = self._create_mocked_response()
     self.assertEqual(pusher._extractHeader(resp, 'foo'), '')
Exemplo n.º 13
0
 def test_extract_header_defined(self):
     pusher = Pusher()
     resp = self._create_mocked_response()
     self.assertEqual(pusher._extractHeader(resp, 'X-NotificationStatus'),
                      'Received')
Exemplo n.º 14
0
 def test_process_response_throttled(self):
     pusher = Pusher()
     response = self._create_mocked_response(code=406,
                                             notification='Dropped')
     with self.assertRaises(ThrottlingLimitError):
         pusher._processResponse(response)
Exemplo n.º 15
0
 def test_proces_response_suppressed(self):
     pusher = Pusher()
     response = self._create_mocked_response(notification='Suppressed')
     status = pusher._processResponse(response)
     self.assertEqual(status.notification, 'Suppressed')
Exemplo n.º 16
0
 def test_process_response_queue_full(self):
     pusher = Pusher()
     response = self._create_mocked_response(notification='QueueFull')
     with self.assertRaises(QueueFullError):
         pusher._processResponse(response)
Exemplo n.º 17
0
 def test_proces_response_suppressed(self):
     pusher = Pusher()
     response = self._create_mocked_response(notification='Suppressed')
     status = pusher._processResponse(response)
     self.assertEqual(status.notification, 'Suppressed')
Exemplo n.º 18
0
 def test_process_response_unknown_status(self):
     pusher = Pusher()
     response = self._create_mocked_response(notification='foo')
     with self.assertRaises(InvalidResponseError):
         pusher._processResponse(response)
Exemplo n.º 19
0
 def test_extract_header_missing(self):
     pusher = Pusher()
     resp = self._create_mocked_response()
     self.assertEqual(pusher._extractHeader(resp, 'foo'), '')
Exemplo n.º 20
0
 def test_extract_header_defined(self):
     pusher = Pusher()
     resp = self._create_mocked_response()
     self.assertEqual(pusher._extractHeader(resp, 'X-NotificationStatus'),
                      'Received')
Exemplo n.º 21
0
 def test_process_response_queue_full(self):
     pusher = Pusher()
     response = self._create_mocked_response(notification='QueueFull')
     with self.assertRaises(QueueFullError):
         pusher._processResponse(response)
Exemplo n.º 22
0
 def test_process_response_throttled(self):
     pusher = Pusher()
     response = self._create_mocked_response(code=406,
                                             notification='Dropped')
     with self.assertRaises(ThrottlingLimitError):
         pusher._processResponse(response)