def test_remote_exists(monkeypatch, mock_client): client = GCloudStorageClient('my-bucket-name', parent='backup', path_to_project_root='.') client._remote_exists('a') mock_client().bucket().blob('backup/a').exists.assert_called_once_with()
def test_remote_exists_directory(monkeypatch, mock_client): client = GCloudStorageClient('my-bucket-name', parent='backup', path_to_project_root='.') bucket = mock_client().bucket() # simulate file does not exist bucket.blob('backup/a').exists.return_value = False # but directory does bucket.client.list_blobs.return_value = ['file', 'another'] client._remote_exists('a') bucket.blob('backup/a').exists.assert_called_once_with() bucket.client.list_blobs.assert_called_once_with('my-bucket-name', prefix='backup/a')