예제 #1
0
    def test_do_download(self):
        mock_api = MagicMock()
        datalake_file = DatalakeFile(mock_api, uri=self.uri, type=type)
        dummy_url = 'dummy url'
        datalake_file._get_download_uri = MagicMock(return_value=dummy_url)
        data = datalake_file._api._connection.request.return_value = self.text_data
        datalake_file._do_download()

        self.assertEqual(data, self.text_data)
        datalake_file._get_download_uri.assert_called_once()
        datalake_file._api._connection.request.assert_called_with('GET',
                                                                  dummy_url,
                                                                  stream=False)
예제 #2
0
    def test_do_download_error_handling(self):
        mock_api = MagicMock()
        datalake_file = DatalakeFile(mock_api, uri=self.uri, type=type)
        dummy_url = 'dummy url'
        datalake_file._get_download_uri = MagicMock(return_value=dummy_url)

        http_error = requests.exceptions.HTTPError()
        res = requests.models.Response()
        res.status_code = 400
        res._content = 'test error'.encode('utf-8')
        http_error.response = res
        datalake_file._api._connection.request.side_effect = http_error

        with self.assertRaises(BadRequest):
            datalake_file._do_download()
예제 #3
0
 def test_get_json_from_remote(self):
     datalake_file = DatalakeFile(None, uri=self.uri, type=type)
     mock_response = self._build_json_response()
     datalake_file._do_download = MagicMock(return_value=mock_response)
     data = datalake_file._get_json_from_remote()
     self.assertEqual(data, self.json_data)
예제 #4
0
 def test_get_content_from_remote(self):
     datalake_file = DatalakeFile(None, uri=self.uri, type=type)
     mock_response = self._build_content_response()
     datalake_file._do_download = MagicMock(return_value=mock_response)
     content = datalake_file._get_content_from_remote()
     self.assertEqual(content, self.binary_data)