Пример #1
0
    def test_get_info_cache_hit(self, mock_cache_get, mock_deepcopy):
        translator = GoogleTranslator()

        self.assertEqual(translator._get_info("test", "ru", "en"),
                         mock_deepcopy.return_value)
        mock_cache_get.assert_called_once_with("testruen")
        mock_deepcopy.assert_called_once_with(mock_cache_get.return_value)
Пример #2
0
    def test_get_info_invalid_request(self, mock_cache_get, mock_build_request,
                                      mock_try_make_request):
        translator = GoogleTranslator()

        mock_cache_get.return_value = None  # Simulate cache miss
        mock_try_make_request.return_value = None

        self.assertIsNone(translator._get_info("test", "ru", "en"))
        mock_cache_get.assert_called_once_with("testruen")
        mock_build_request.assert_called_once_with("test", "ru", "en")
        mock_try_make_request.assert_called_once_with(
            mock_build_request.return_value)
Пример #3
0
    def test_get_info_valid_request(self, mock_cache, mock_parse_reply,
                                    mock_deepcopy, mock_build_request,
                                    mock_try_make_request, mock_string_to_json,
                                    mock_extract_data):
        translator = GoogleTranslator()

        mock_cache.return_value.get.return_value = None  # Simulate cache miss
        self.assertEqual(translator._get_info("test", "ru", "en"),
                         mock_deepcopy.return_value)
        mock_cache.return_value.get.assert_called_once_with("testruen")
        mock_build_request.assert_called_once_with("test", "ru", "en")
        mock_try_make_request.assert_called_once_with(
            mock_build_request.return_value)
        mock_parse_reply.assert_called_once_with(
            mock_try_make_request.return_value, translator._encoding)
        mock_string_to_json.assert_called_once_with(
            mock_parse_reply.return_value)
        mock_extract_data.assert_called_once_with(
            mock_string_to_json.return_value)
        mock_deepcopy.assert_called_once_with(mock_extract_data.return_value)