def test_upload_file(self, mock_boto): minio_provider = Minio(AuthData('MINIO', self.MINIO_CREDS)) # Mock file management mopen = mock.mock_open() with mock.patch('builtins.open', mopen, create=True): minio_provider.upload_file('/tmp/output/processed.jpg', 'processed.jpg', 'minio_bucket') # Check file reading call mopen.assert_called_once_with('/tmp/output/processed.jpg', 'rb') # Check boto client upload call self.assertEqual(mock_boto.mock_calls[1], call().upload_fileobj(mopen.return_value, 'minio_bucket', 'processed.jpg'))
def test_get_client_default_endpoint(self, mock_boto): Minio(AuthData('MINIO', self.MINIO_CREDS)) mock_boto.assert_called_once_with('s3', endpoint_url='http://minio-service.minio:9000', region_name=None, verify=True, aws_access_key_id='test_minio_access', aws_secret_access_key='test_minio_secret')
def test_get_client_custom_endpoint(self, mock_boto): Minio(AuthData('MINIO', {**self.MINIO_CREDS, 'endpoint': 'https://test.endpoint'})) mock_boto.assert_called_once_with('s3', endpoint_url='https://test.endpoint', region_name=None, verify=True, aws_access_key_id='test_minio_access', aws_secret_access_key='test_minio_secret')
def test_download_file(self, mock_boto): minio_provider = Minio(AuthData('MINIO', self.MINIO_CREDS)) # Mock file management mopen = mock.mock_open() with mock.patch('builtins.open', mopen, create=True): # Create mock event and event properties event = mock.Mock(spec=MinioEvent) type(event).bucket_name = mock.PropertyMock(return_value='minio_bucket') type(event).file_name = mock.PropertyMock(return_value='minio_file') type(event).object_key = mock.PropertyMock(return_value='minio_file') file_path = minio_provider.download_file(event, '/tmp/input') # Check returned file path self.assertEqual(file_path, '/tmp/input/minio_file') # Check file writing call mopen.assert_called_once_with('/tmp/input/minio_file', 'wb') # Check boto client download call self.assertEqual(mock_boto.mock_calls[1], call().download_fileobj('minio_bucket', 'minio_file', mopen.return_value))
def create_provider(storage_auth, storage_path=None): """Returns the storage provider needed based on the authentication type defined. If not storage auth provided, use local storage.""" if not storage_auth: provider = Local(storage_auth, storage_path) elif storage_auth.type == 'MINIO': provider = Minio(storage_auth, storage_path) elif storage_auth.type == 'ONEDATA': provider = Onedata(storage_auth, storage_path) elif storage_auth.type == 'S3': provider = S3(storage_auth, storage_path) else: raise InvalidStorageProviderError(storage_type=storage_auth.type) return provider
def _get_minio_class_and_auth(self): auth = mock.Mock(spec=AuthData) auth.get_credential.return_value = 'test' return (Minio(auth, 'minio_path'), auth)