Пример #1
0
    def test_invalid_object_path(self, mock_parent_init):
        # This is just the path of a bucket hence invalid filename
        file_name = 'gs://test-bucket'
        mock_parent_init.return_value = None

        gcs_bucket_helper = GoogleCloudBucketHelper()
        gcs_bucket_helper._gcs_hook = mock.Mock()

        with self.assertRaises(Exception) as context:
            gcs_bucket_helper.google_cloud_to_local(file_name)

        self.assertEqual(
            'Invalid Google Cloud Storage (GCS) object path: {}'.format(file_name),
            str(context.exception))
Пример #2
0
    def test_valid_object(self, mock_parent_init):
        file_name = 'gs://test-bucket/path/to/obj.jar'
        mock_parent_init.return_value = None

        gcs_bucket_helper = GoogleCloudBucketHelper()
        gcs_bucket_helper._gcs_hook = mock.Mock()

        # pylint: disable=redefined-builtin,unused-argument
        def _mock_download(bucket, object, filename=None):
            text_file_contents = 'text file contents'
            with open(filename, 'w') as text_file:
                text_file.write(text_file_contents)
            return text_file_contents

        gcs_bucket_helper._gcs_hook.download.side_effect = _mock_download

        local_file = gcs_bucket_helper.google_cloud_to_local(file_name)
        self.assertIn('obj.jar', local_file)
Пример #3
0
    def test_empty_object(self, mock_parent_init):
        file_name = 'gs://test-bucket/path/to/obj.jar'
        mock_parent_init.return_value = None

        gcs_bucket_helper = GoogleCloudBucketHelper()
        gcs_bucket_helper._gcs_hook = mock.Mock()

        # pylint: disable=redefined-builtin,unused-argument
        def _mock_download(bucket, object, filename=None):
            text_file_contents = ''
            with open(filename, 'w') as text_file:
                text_file.write(text_file_contents)
            return text_file_contents

        gcs_bucket_helper._gcs_hook.download.side_effect = _mock_download

        with self.assertRaises(Exception) as context:
            gcs_bucket_helper.google_cloud_to_local(file_name)

        self.assertEqual(
            'Failed to download Google Cloud Storage (GCS) object: {}'.format(file_name),
            str(context.exception))