Пример #1
0
 def test_make_request(self, mock_post):
     handler = SmsHandler(self.gate)
     data = {
         'test': 1
     }
     handler._make_request(data)
     mock_post.assert_called_with(self.gate.url, json=data)
Пример #2
0
    def test_send_raises(self, mock_logger, mock_request):
        logger = MagicMock()
        mock_logger.return_value = logger

        handler = SmsHandler(self.gate)
        handler.send(self.data)

        logger.log_error.assert_called_with('test_error')
        self.assertFalse(logger.log_response.called)
        self.assertEquals(handler._error, 'test_error')
Пример #3
0
    def test_send_good_response(self, mock_logger, mock_request):
        response_ok = {
            'status': 'ok'
        }
        mock_request.return_value = response_ok
        logger = MagicMock()
        mock_logger.return_value = logger

        handler = SmsHandler(self.gate)
        handler.send(self.data)

        logger.log_sending.assert_called_with(self.data)
        logger.log_response.assert_called_with(response_ok)
        self.assertIsNone(handler._error)
Пример #4
0
    def test_send_error_response(self, mock_logger, mock_request):
        response_error = {
            'status': 'error',
            'error_msg': 'test_error'
        }
        mock_request.return_value = response_error
        logger = MagicMock()
        mock_logger.return_value = logger

        handler = SmsHandler(self.gate)
        handler.send(self.data)

        logger.log_response.assert_called_with(response_error)
        logger.log_error.assert_called_with(response_error['error_msg'])
        self.assertEquals(handler._error, response_error['error_msg'])