def gcp_route_file(bucket_name, bucket_file_path, local_path): """Route file to either GCP bucket or local filesystem.""" if os.path.isdir(bucket_name): copy_to_local_dir(bucket_name, local_path, bucket_file_path,) else: upload_to_gcp_storage(bucket_name, bucket_file_path, local_path)
def test_gcp_upload_fail_no_credentials(self): """Test upload_to_s3 method with mock s3.""" bucket_name = fake.slug() local_path = fake.file_path() remote_path = fake.file_path() uploaded = upload_to_gcp_storage(bucket_name, local_path, remote_path) self.assertFalse(uploaded)
def test_gcp_upload_error(self, mock_storage): """Test upload_to_s3 method with mock s3.""" gcp_client = mock_storage.return_value gcp_client.get_bucket.side_effect = GoogleCloudError("GCP Error") bucket_name = fake.slug() local_path = fake.file_path() remote_path = fake.file_path() uploaded = upload_to_gcp_storage(bucket_name, local_path, remote_path) self.assertFalse(uploaded)
def test_gcp_upload_success(self, mock_storage): """Test upload_to_s3 method with mock s3.""" bucket_name = fake.slug() local_path = fake.file_path() remote_path = fake.file_path() uploaded = upload_to_gcp_storage(bucket_name, local_path, remote_path) mock_client = mock_storage.Client.return_value mock_client.get_bucket.assert_called_with(bucket_name) mock_bucket = mock_client.get_bucket.return_value mock_bucket.blob.assert_called_with(remote_path) mock_blob = mock_bucket.blob.return_value mock_blob.upload_from_filename.assert_called_with(local_path) self.assertTrue(uploaded)