Ejemplo n.º 1
0
def test_create_existing_folder():
    folder = Folder({})
    new_folder_url = ('https://files.osf.io/v1/resources/9zpcy/providers/' +
                      'osfstorage/foo123/?kind=folder')
    folder._new_folder_url = new_folder_url
    folder._put = MagicMock(return_value=FakeResponse(409, None))

    with pytest.raises(FolderExistsException):
        folder.create_folder('foobar')

    folder._put.assert_called_once_with(new_folder_url,
                                        params={'name': 'foobar'})
Ejemplo n.º 2
0
def test_create_new_folder():
    folder = Folder({})
    new_folder_url = ('https://files.osf.io/v1/resources/9zpcy/providers/' +
                      'osfstorage/foo123/?kind=folder')
    folder._new_folder_url = new_folder_url
    # use an empty response as we won't do anything with the returned instance
    folder._put = MagicMock(return_value=FakeResponse(201, {'data': {}}))

    new_folder = folder.create_folder('foobar')

    assert isinstance(new_folder, _WaterButlerFolder)

    folder._put.assert_called_once_with(new_folder_url,
                                        params={'name': 'foobar'})
Ejemplo n.º 3
0
def test_create_existing_folder_exist_ok():
    folder = Folder({})
    new_folder_url = ('https://files.osf.io/v1/resources/9zpcy/providers/' +
                      'osfstorage/foo123/?kind=folder')
    folder._new_folder_url = new_folder_url
    folder._put = MagicMock(return_value=FakeResponse(409, None))

    with patch.object(Folder, 'folders',
                      new_callable=PropertyMock) as mock_folder:
        mock_folder.return_value = [MockFolder('foobar'), MockFolder('fudge')]
        existing_folder = folder.create_folder('foobar', exist_ok=True)

    assert existing_folder.name == 'foobar'

    folder._put.assert_called_once_with(new_folder_url,
                                        params={'name': 'foobar'})