Beispiel #1
0
 def test_get_download_uri(self):
     mock_api = MagicMock()
     datalake_file = DatalakeFile(mock_api, uri=self.uri, type=type)
     datalake_file._api._connection.api_request.return_value = self.file_info
     download_uri = datalake_file._get_download_uri()
     self.assertEqual(download_uri, self.file_info['download_uri'])
     datalake_file._api._connection.api_request.assert_called_once()
Beispiel #2
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)
Beispiel #3
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()