aiohttpretty.register_json_uri

Here are the examples of the python api aiohttpretty.register_json_uri taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

75 Examples 7

Page 1 Selected Page 2

Example 1

Project: waterbutler
License: View license
Source File: test_provider.py
Function: test_project_delete
    async def test_project_delete(self, project_provider, list_project_articles, article_metadata):
        article_id = str(list_project_articles[0]['id'])

        list_articles_url = project_provider.build_url('projects', project_provider.project_id, 'articles')
        article_metadata_url = project_provider.build_url('articles', article_id)

        aiohttpretty.register_json_uri('GET', article_metadata_url, body=article_metadata)
        aiohttpretty.register_json_uri('GET', list_articles_url, body=list_project_articles)
        aiohttpretty.register_json_uri('DELETE', list_articles_url, body={'article_id': article_id})

        path = await project_provider.validate_path('/{}'.format(article_id))
        result = await project_provider.delete(path)

        assert result is None
        assert aiohttpretty.has_call(method='DELETE', uri=list_articles_url)

Example 2

Project: waterbutler
License: View license
Source File: test_provider.py
    async def test_project_article_upload(self, project_provider, list_project_articles, article_metadata, upload_metadata, file_content, file_stream):
        article_id = str(list_project_articles[0]['id'])
        list_articles_url = project_provider.build_url('projects', project_provider.project_id, 'articles')
        article_metadata_url = project_provider.build_url('articles', article_id)
        article_upload_url = project_provider.build_url('articles', article_id, 'files')
        aiohttpretty.register_json_uri('GET', list_articles_url, body=list_project_articles)
        aiohttpretty.register_json_uri('GET', article_metadata_url, body=article_metadata)
        aiohttpretty.register_json_uri('PUT', article_upload_url, body=upload_metadata)
        file_name = 'barricade.gif'
        path = await project_provider.validate_path('/{}/{}'.format(article_id, file_name))
        result, created = await project_provider.upload(file_stream, path)
        expected = metadata.FigshareFileMetadata(upload_metadata, parent=article_metadata['items'][0], child=True)
        assert aiohttpretty.has_call(method='PUT', uri=article_upload_url)
        assert result == expected

Example 3

Project: waterbutler
License: View license
Source File: test_provider.py
    async def test_delete_file(self, provider, native_dataset_metadata):
        path = '21'
        url = provider.build_url(dvs.EDIT_MEDIA_BASE_URL, 'file', path)
        aiohttpretty.register_json_uri('DELETE', url, status=204)
        draft_url = provider.build_url(dvs.JSON_BASE_URL.format(provider._id, 'latest'), key=provider.token)
        aiohttpretty.register_json_uri('GET', draft_url, status=200, body=native_dataset_metadata)
        published_url = provider.build_url(dvs.JSON_BASE_URL.format(provider._id, 'latest-published'), key=provider.token)
        aiohttpretty.register_json_uri('GET', published_url, status=200, body=native_dataset_metadata)

        path = await provider.validate_path(path)
        await provider.delete(path)

        assert aiohttpretty.has_call(method='DELETE', uri=url)

Example 4

Project: waterbutler
License: View license
Source File: test_provider.py
Function: test_returns_metadata
    async def test_returns_metadata(self, provider, repo_metadata, create_folder_response):
        path = await provider.validate_path('/i/like/trains/')
        url = provider.build_repo_url('contents', os.path.join(path.path, '.gitkeep'))

        aiohttpretty.register_json_uri('PUT', url, status=201, body=create_folder_response)

        metadata = await provider.create_folder(path)

        assert metadata.kind == 'folder'
        assert metadata.name == 'trains'
        assert metadata.path == '/i/like/trains/'

Example 5

Project: waterbutler
License: View license
Source File: test_provider.py
    async def test_metadata_doesnt_exist(self, provider, repo_metadata, repo_tree_metadata_root):
        ref = hashlib.sha1().hexdigest()
        path = await provider.validate_path('/file.txt')

        tree_url = provider.build_repo_url('git', 'trees', ref, recursive=1)
        commit_url = provider.build_repo_url('commits', path=path.path.lstrip('/'), sha=path.identifier[0])

        aiohttpretty.register_json_uri('GET', tree_url, body=repo_tree_metadata_root)
        aiohttpretty.register_json_uri('GET', commit_url, body=[])

        with pytest.raises(exceptions.NotFoundError):
            await provider.metadata(path)

Example 6

Project: waterbutler
License: View license
Source File: test_provider.py
    async def test_validate_v1_path_folder(self, provider, folder_metadata):
        folder_path = 'Photos'

        metadata_url = provider.build_url('metadata', 'auto', folder_path)
        aiohttpretty.register_json_uri('GET', metadata_url, body=folder_metadata)

        try:
            wb_path_v1 = await provider.validate_v1_path('/' + folder_path + '/')
        except Exception as exc:
            pytest.fail(str(exc))

        with pytest.raises(exceptions.NotFoundError) as exc:
            await provider.validate_v1_path('/' + folder_path)

        assert exc.value.code == client.NOT_FOUND

        wb_path_v0 = await provider.validate_path('/' + folder_path + '/')

        assert wb_path_v1 == wb_path_v0

Example 7

Project: waterbutler
License: View license
Source File: test_provider.py
    async def test_metadata_no_files(self, provider, empty_native_dataset_metadata):
        url = provider.build_url(dvs.JSON_BASE_URL.format(provider._id, 'latest'), key=provider.token)
        aiohttpretty.register_json_uri('GET', url, status=200, body=empty_native_dataset_metadata)
        path = await provider.validate_path('/')
        result = await provider.metadata(path, version='latest')

        assert result == []

Example 8

Project: waterbutler
License: View license
Source File: test_provider.py
    async def test_upload_create(self, provider, file_stream):
        upload_id = '7'
        item = fixtures.list_file['items'][0]
        path = WaterButlerPath('/birdie.jpg', _ids=(provider.folder['id'], None))

        start_upload_url = provider._build_upload_url('files', uploadType='resumable')
        finish_upload_url = provider._build_upload_url('files', uploadType='resumable', upload_id=upload_id)

        aiohttpretty.register_json_uri('PUT', finish_upload_url, body=item)
        aiohttpretty.register_uri('POST', start_upload_url, headers={'LOCATION': 'http://waterbutler.io?upload_id={}'.format(upload_id)})

        result, created = await provider.upload(file_stream, path)

        expected = GoogleDriveFileMetadata(item, path)

        assert created is True
        assert result == expected
        assert aiohttpretty.has_call(method='PUT', uri=finish_upload_url)
        assert aiohttpretty.has_call(method='POST', uri=start_upload_url)

Example 9

Project: waterbutler
License: View license
Source File: test_provider.py
Function: test_forbidden
    async def test_forbidden(self, provider):
        path = WaterButlerPath('/newfolder/', prepend=provider.folder)
        url = provider.build_url('fileops', 'create_folder')
        params = build_folder_metadata_params(path)

        aiohttpretty.register_json_uri('POST', url, params=params, status=403, body={
            'error': 'because I hate you'
        })

        with pytest.raises(exceptions.CreateFolderError) as e:
            await provider.create_folder(path)

        assert e.value.code == 403
        assert e.value.data['error'] == 'because I hate you'

Example 10

Project: waterbutler
License: View license
Source File: test_provider.py
    async def test_metadata_file_nested(self, provider):
        path = GoogleDrivePath(
            '/hugo/kim/pins',
            _ids=[str(x) for x in range(4)]
        )

        item = fixtures.generate_list(3)['items'][0]
        url = provider.build_url('files', path.identifier)

        aiohttpretty.register_json_uri('GET', url, body=item)

        result = await provider.metadata(path)

        expected = GoogleDriveFileMetadata(item, path)
        assert result == expected
        assert aiohttpretty.has_call(method='GET', uri=url)

Example 11

Project: waterbutler
License: View license
Source File: test_provider.py
    async def test_get_revisions_no_revisions(self, provider):
        item = fixtures.list_file['items'][0]
        metadata_url = provider.build_url('files', item['id'])
        revisions_url = provider.build_url('files', item['id'], 'revisions')
        path = WaterButlerPath('/birdie.jpg', _ids=('doesntmatter', item['id']))

        aiohttpretty.register_json_uri('GET', metadata_url, body=item)
        aiohttpretty.register_json_uri('GET', revisions_url, body=fixtures.revisions_list_empty)

        result = await provider.revisions(path)

        expected = [
            GoogleDriveRevision({
                'modifiedDate': item['modifiedDate'],
                'id': fixtures.revisions_list_empty['etag'] + ds.DRIVE_IGNORE_VERSION,
            })
        ]
        assert result == expected

Example 12

Project: waterbutler
License: View license
Source File: test_provider.py
    async def test_project_article_delete(self, project_provider, list_project_articles, article_metadata, file_metadata):
        file_id = str(file_metadata['id'])
        article_id = str(list_project_articles[0]['id'])

        article_metadata_url = project_provider.build_url('articles', article_id)
        article_delete_url = project_provider.build_url('articles', article_id, 'files', file_id)
        list_articles_url = project_provider.build_url('projects', project_provider.project_id, 'articles')

        aiohttpretty.register_json_uri('GET', list_articles_url, body=list_project_articles)
        aiohttpretty.register_json_uri('GET', article_metadata_url, body=article_metadata)
        aiohttpretty.register_uri('DELETE', article_delete_url)

        path = await project_provider.validate_path('/{}/{}'.format(article_id, file_id))
        result = await project_provider.delete(path)

        assert result is None
        assert aiohttpretty.has_call(method='DELETE', uri=article_delete_url)

Example 13

Project: waterbutler
License: View license
Source File: test_provider.py
    async def test_metadata_never_published_raises_errors(self, provider, native_dataset_metadata):
        published_url = provider.build_url(dvs.JSON_BASE_URL.format(provider._id, 'latest-published'), key=provider.token)
        aiohttpretty.register_json_uri('GET', published_url, status=400)

        path = await provider.validate_path('/')
        with pytest.raises(exceptions.MetadataError) as e:
            result = await provider.metadata(path)

        assert e.value.code == 400

Example 14

Project: waterbutler
License: View license
Source File: test_provider.py
Function: test_already_exists
    async def test_already_exists(self, provider, repo_metadata):
        path = await provider.validate_path('/Imarealboy/')
        url = provider.build_repo_url('contents', os.path.join(path.path, '.gitkeep'))

        aiohttpretty.register_json_uri('PUT', url, status=422, body={
            'message': 'Invalid request.\n\n"sha" wasn\'t supplied.'
        })

        with pytest.raises(exceptions.FolderNamingConflict) as e:
            await provider.create_folder(path)

        assert e.value.code == 409
        assert e.value.message == 'Cannot create folder "Imarealboy" because a file or folder already exists at path "/Imarealboy/"'

Example 15

Project: waterbutler
License: View license
Source File: test_provider.py
    async def test_raises_other_422(self, provider, repo_metadata):
        path = await provider.validate_path('/Imarealboy/')
        url = provider.build_repo_url('contents', os.path.join(path.path, '.gitkeep'))

        aiohttpretty.register_json_uri('PUT', url, status=422, body={
            'message': 'github no likey'
        })

        with pytest.raises(exceptions.CreateFolderError) as e:
            await provider.create_folder(path)

        assert e.value.code == 422
        assert e.value.data == {'message': 'github no likey'}

Example 16

Project: waterbutler
License: View license
Source File: test_provider.py
    async def test_download_drive_revision(self, provider):
        revision = 'oldest'
        body = b'we love you conrad'
        item = fixtures.list_file['items'][0]
        path = WaterButlerPath('/birdie.jpg', _ids=(provider.folder['id'], item['id']))

        download_file_url = item['downloadUrl']
        metadata_url = provider.build_url('files', path.identifier)
        revision_url = provider.build_url('files', item['id'], 'revisions', revision)

        aiohttpretty.register_json_uri('GET', revision_url, body=item)
        aiohttpretty.register_json_uri('GET', metadata_url, body=item)
        aiohttpretty.register_uri('GET', download_file_url, body=body, auto_length=True)

        result = await provider.download(path, revision=revision)
        content = await result.read()

        assert content == body

Example 17

Project: waterbutler
License: View license
Source File: test_provider.py
    async def test_metadata_root_file(self, provider, file_metadata):
        path = WaterButlerPath('/pfile', prepend=provider.folder)
        url = provider.build_url('metadata', 'auto', path.full_path)
        aiohttpretty.register_json_uri('GET', url, body=file_metadata)
        result = await provider.metadata(path)

        assert isinstance(result, metadata.BaseMetadata)
        assert result.kind == 'file'
        assert result.name == 'Getting_Started.pdf'
        assert result.path == '/Getting_Started.pdf'

Example 18

Project: waterbutler
License: View license
Source File: test_provider.py
    async def test_upload_update(self, provider, file_stream):
        upload_id = '7'
        item = fixtures.list_file['items'][0]
        path = WaterButlerPath('/birdie.jpg', _ids=(provider.folder['id'], item['id']))

        start_upload_url = provider._build_upload_url('files', path.identifier, uploadType='resumable')
        finish_upload_url = provider._build_upload_url('files', path.identifier, uploadType='resumable', upload_id=upload_id)

        aiohttpretty.register_json_uri('PUT', finish_upload_url, body=item)
        aiohttpretty.register_uri('PUT', start_upload_url, headers={'LOCATION': 'http://waterbutler.io?upload_id={}'.format(upload_id)})
        result, created = await provider.upload(file_stream, path)

        assert aiohttpretty.has_call(method='PUT', uri=start_upload_url)
        assert aiohttpretty.has_call(method='PUT', uri=finish_upload_url)
        assert created is False
        expected = GoogleDriveFileMetadata(item, path)
        assert result == expected

Example 19

Project: waterbutler
License: View license
Source File: test_provider.py
    async def test_get_revisions_free_account(self, provider, file_metadata):
        item = file_metadata['entries'][0]
        path = WaterButlerPath('/name.txt', _ids=(provider, item['id']))

        file_url = provider.build_url('files', path.identifier)
        revisions_url = provider.build_url('files', path.identifier, 'versions')

        aiohttpretty.register_json_uri('GET', file_url, body=item)
        aiohttpretty.register_json_uri('GET', revisions_url, body={}, status=403)

        result = await provider.revisions(path)
        expected = [BoxRevision(item)]
        assert result == expected
        assert aiohttpretty.has_call(method='GET', uri=file_url)
        assert aiohttpretty.has_call(method='GET', uri=revisions_url)

Example 20

Project: waterbutler
License: View license
Source File: test_provider.py
Function: test_get_revisions
    async def test_get_revisions(self, provider):
        item = fixtures.list_file['items'][0]
        path = WaterButlerPath('/birdie.jpg', _ids=('doesntmatter', item['id']))

        revisions_url = provider.build_url('files', item['id'], 'revisions')
        aiohttpretty.register_json_uri('GET', revisions_url, body=fixtures.revisions_list)

        result = await provider.revisions(path)

        expected = [
            GoogleDriveRevision(each)
            for each in fixtures.revisions_list['items']
        ]
        assert result == expected

Example 21

Project: waterbutler
License: View license
Source File: test_provider.py
Function: test_returns_metadata
    async def test_returns_metadata(self, provider, file_metadata):
        file_metadata['path'] = '/newfolder'
        path = WaterButlerPath('/newfolder/', prepend=provider.folder)
        url = provider.build_url('fileops', 'create_folder')
        params = build_folder_metadata_params(path)

        aiohttpretty.register_json_uri('POST', url, params=params, status=200, body=file_metadata)

        resp = await provider.create_folder(path)

        assert resp.kind == 'folder'
        assert resp.name == 'newfolder'

Example 22

Project: waterbutler
License: View license
Source File: test_provider.py
Function: test_returns_metadata
    async def test_returns_metadata(self, provider, folder_object_metadata):
        url = provider.build_url('folders')
        folder_object_metadata['name'] = '50 shades of nope'
        path = WaterButlerPath('/50 shades of nope/', _ids=(provider.folder, None))

        aiohttpretty.register_json_uri('POST', url, status=201, body=folder_object_metadata)

        resp = await provider.create_folder(path)

        assert resp.kind == 'folder'
        assert resp.name == '50 shades of nope'
        assert resp.path == '/{}/'.format(folder_object_metadata['id'])
        assert isinstance(resp, BoxFolderMetadata)
        assert path.identifier_path == '/' + folder_object_metadata['id'] + '/'

Example 23

Project: waterbutler
License: View license
Source File: test_provider.py
    async def test_project_contents(self, project_provider, list_project_articles, article_metadata):
        list_articles_url = project_provider.build_url('projects', project_provider.project_id, 'articles')
        article_metadata_url = project_provider.build_url('articles', str(list_project_articles[0]['id']))
        aiohttpretty.register_json_uri('GET', list_articles_url, body=list_project_articles)
        aiohttpretty.register_json_uri('GET', article_metadata_url, body=article_metadata)
        path = await project_provider.validate_path('/')
        result = await project_provider.metadata(path)
        assert aiohttpretty.has_call(method='GET', uri=list_articles_url)
        assert aiohttpretty.has_call(method='GET', uri=article_metadata_url)
        article_provider = await project_provider._make_article_provider(list_project_articles[0]['id'], check_parent=False)
        expected = [
            article_provider._serialize_item(
                article_metadata['items'][0],
                parent=article_metadata['items'][0],
            ),
        ]
        assert result == expected

Example 24

Project: waterbutler
License: View license
Source File: test_provider.py
    async def test_metadata_published_no_files(self, provider, empty_native_dataset_metadata):
        url = provider.build_url(dvs.JSON_BASE_URL.format(provider._id, 'latest-published'), key=provider.token)
        aiohttpretty.register_json_uri('GET', url, status=200, body=empty_native_dataset_metadata)

        path = await provider.validate_path('/')
        result = await provider.metadata(path, version='latest-published')

        assert result == []

Example 25

Project: waterbutler
License: View license
Source File: test_provider.py
    async def test_project_article_contents(self, project_provider, list_project_articles, article_metadata):
        list_articles_url = project_provider.build_url('projects', project_provider.project_id, 'articles')
        article_metadata_url = project_provider.build_url('articles', str(list_project_articles[0]['id']))
        aiohttpretty.register_json_uri('GET', list_articles_url, body=list_project_articles)
        aiohttpretty.register_json_uri('GET', article_metadata_url, body=article_metadata)
        article_id = list_project_articles[0]['id']
        path = await project_provider.validate_path('/{}/'.format(article_id))
        result = await project_provider.metadata(path)
        assert aiohttpretty.has_call(method='GET', uri=list_articles_url)
        assert aiohttpretty.has_call(method='GET', uri=article_metadata_url)
        article_provider = await project_provider._make_article_provider(list_project_articles[0]['id'], check_parent=False)
        expected = [
            article_provider._serialize_item(
                article_metadata['items'][0]['files'][0],
                parent=article_metadata['items'][0],
            ),
        ]
        assert result == expected

Example 26

Project: waterbutler
License: View license
Source File: test_provider.py
    async def test_project_article_contents_not_in_project(self, project_provider, list_project_articles, article_metadata):
        list_articles_url = project_provider.build_url('projects', project_provider.project_id, 'articles')
        article_metadata_url = project_provider.build_url('articles', str(list_project_articles[0]['id']))
        aiohttpretty.register_json_uri('GET', list_articles_url, body=[])
        aiohttpretty.register_json_uri('GET', article_metadata_url, body=article_metadata)
        article_id = list_project_articles[0]['id']
        path = await project_provider.validate_path('/{}/'.format(article_id))
        with pytest.raises(exceptions.ProviderError) as exc:
            await project_provider.metadata(path)
        assert exc.value.code == 404
        assert aiohttpretty.has_call(method='GET', uri=list_articles_url)
        assert not aiohttpretty.has_call(method='GET', uri=article_metadata_url)

Example 27

Project: waterbutler
License: View license
Source File: test_provider.py
    async def test_metadata_never_published(self, provider, native_dataset_metadata):
        published_url = provider.build_url(dvs.JSON_BASE_URL.format(provider._id, 'latest-published'), key=provider.token)
        aiohttpretty.register_json_uri('GET', published_url, status=404)
        draft_url = provider.build_url(dvs.JSON_BASE_URL.format(provider._id, 'latest'), key=provider.token)
        aiohttpretty.register_json_uri('GET', draft_url, status=200, body=native_dataset_metadata)

        path = await provider.validate_path('/')
        result = await provider.metadata(path)

        assert len(result) == 3

Example 28

Project: waterbutler
License: View license
Source File: test_provider.py
    async def test_draft_metadata_missing(self, provider):
        url = provider.build_url(dvs.JSON_BASE_URL.format(provider._id, 'latest'), key=provider.token)
        aiohttpretty.register_json_uri('GET', url, status=404)

        path = await provider.validate_path('/')

        with pytest.raises(exceptions.MetadataError):
            await provider.metadata(path, version='latest')

Example 29

Project: waterbutler
License: View license
Source File: test_provider.py
    async def test_project_article_file(self, project_provider, list_project_articles, article_metadata, file_metadata):
        file_id = file_metadata['id']
        article_id = str(list_project_articles[0]['id'])

        article_metadata_url = project_provider.build_url('articles', article_id)
        list_articles_url = project_provider.build_url('projects', project_provider.project_id, 'articles')

        aiohttpretty.register_json_uri('GET', list_articles_url, body=list_project_articles)
        aiohttpretty.register_json_uri('GET', article_metadata_url, body=article_metadata)

        path = await project_provider.validate_path('/{}/{}'.format(article_id, file_id))
        result = await project_provider.metadata(path)

        expected = metadata.FigshareFileMetadata(file_metadata, parent=article_metadata['items'][0], child=True)
        assert result == expected

Example 30

Project: waterbutler
License: View license
Source File: test_provider.py
    async def test_revalidate_path(self, project_provider, list_project_articles, article_metadata, file_metadata):
        article_id = str(list_project_articles[0]['id'])
        list_project_articles[0]['title'] = 'fantine.mp3'

        article_metadata_url = project_provider.build_url('articles', article_id)
        list_articles_url = project_provider.build_url('projects', project_provider.project_id, 'articles')

        aiohttpretty.register_json_uri('GET', list_articles_url, body=list_project_articles)
        aiohttpretty.register_json_uri('GET', article_metadata_url, body=article_metadata)

        path = await project_provider.validate_path('/')

        result = await project_provider.revalidate_path(path, '/{}'.format(list_project_articles[0]['title']), folder=False)

        assert result.is_dir is False
        assert result.name == 'fantine.mp3'
        assert result.identifier == article_id

Example 31

Project: waterbutler
License: View license
Source File: test_provider.py
    async def test_download_invalid_path(self, provider, native_dataset_metadata):
        path = '/50'
        draft_url = provider.build_url(dvs.JSON_BASE_URL.format(provider._id, 'latest'), key=provider.token)
        aiohttpretty.register_json_uri('GET', draft_url, status=200, body=native_dataset_metadata)
        published_url = provider.build_url(dvs.JSON_BASE_URL.format(provider._id, 'latest-published'), key=provider.token)
        aiohttpretty.register_json_uri('GET', published_url, status=200, body=native_dataset_metadata)

        path = await provider.validate_path(path)

        with pytest.raises(exceptions.NotFoundError):
            await provider.download(path)

Example 32

Project: waterbutler
License: View license
Source File: test_provider.py
Function: test_metadata_folder_root
    async def test_metadata_folder_root(self, provider, repo_metadata, content_repo_metadata_root):
        path = await provider.validate_path('/')

        url = provider.build_repo_url('contents', path.path, ref=provider.default_branch)
        aiohttpretty.register_json_uri('GET', url, body=content_repo_metadata_root)

        result = await provider.metadata(path)

        ret = []
        for item in content_repo_metadata_root:
            if item['type'] == 'dir':
                ret.append(GitHubFolderContentMetadata(item, ref=provider.default_branch))
            else:
                ret.append(GitHubFileContentMetadata(item, web_view=item['html_url'], ref=provider.default_branch))

        assert result == ret

Example 33

Project: waterbutler
License: View license
Source File: test_provider.py
    async def test_validate_v1_path_file(self, provider, file_metadata):
        file_path = 'Photos/Getting_Started.pdf'

        metadata_url = provider.build_url('metadata', 'auto', file_path)
        aiohttpretty.register_json_uri('GET', metadata_url, body=file_metadata)

        try:
            wb_path_v1 = await provider.validate_v1_path('/' + file_path)
        except Exception as exc:
            pytest.fail(str(exc))

        with pytest.raises(exceptions.NotFoundError) as exc:
            await provider.validate_v1_path('/' + file_path + '/')

        assert exc.value.code == client.NOT_FOUND

        wb_path_v0 = await provider.validate_path('/' + file_path)

        assert wb_path_v1 == wb_path_v0

Example 34

Project: waterbutler
License: View license
Source File: test_provider.py
    async def test_metadata_nested(self, provider, file_metadata):
        item = file_metadata['entries'][0]
        path = WaterButlerPath('/name.txt', _ids=(provider, item['id']))

        file_url = provider.build_url('files', path.identifier)
        aiohttpretty.register_json_uri('GET', file_url, body=item)

        result = await provider.metadata(path)

        expected = BoxFileMetadata(item, path)
        assert result == expected
        assert aiohttpretty.has_call(method='GET', uri=file_url)

Example 35

Project: waterbutler
License: View license
Source File: test_provider.py
    async def test_download_drive(self, provider):
        body = b'we love you conrad'
        item = fixtures.list_file['items'][0]
        path = WaterButlerPath('/birdie.jpg', _ids=(provider.folder['id'], item['id']))

        download_file_url = item['downloadUrl']
        metadata_url = provider.build_url('files', path.identifier)

        aiohttpretty.register_json_uri('GET', metadata_url, body=item)
        aiohttpretty.register_uri('GET', download_file_url, body=body, auto_length=True)

        result = await provider.download(path)

        content = await result.read()
        assert content == body

Example 36

Project: waterbutler
License: View license
Source File: test_provider.py
Function: test_meta_data
    async def test_metadata(self, provider, folder_metadata):
        path = await provider.validate_path('/')
        url = provider.build_url('metadata', 'auto', path.full_path)
        aiohttpretty.register_json_uri('GET', url, body=folder_metadata)
        result = await provider.metadata(path)

        assert isinstance(result, list)
        assert len(result) == 1
        assert result[0].kind == 'file'
        assert result[0].name == 'flower.jpg'
        assert result[0].path == '/flower.jpg'

Example 37

Project: waterbutler
License: View license
Source File: test_provider.py
    async def test_download_docs(self, provider):
        body = b'we love you conrad'
        item = fixtures.docs_file_metadata
        path = WaterButlerPath('/birdie.jpg', _ids=(provider.folder['id'], item['id']))

        metadata_url = provider.build_url('files', path.identifier)
        revisions_url = provider.build_url('files', item['id'], 'revisions')
        download_file_url = item['exportLinks']['application/vnd.openxmlformats-officedocuement.wordprocessingml.docuement']

        aiohttpretty.register_json_uri('GET', metadata_url, body=item)
        aiohttpretty.register_uri('GET', download_file_url, body=body, auto_length=True)
        aiohttpretty.register_json_uri('GET', revisions_url, body={'items': [{'id': 'foo'}]})

        result = await provider.download(path)
        assert result.name == 'version-test.docx'

        content = await result.read()
        assert content == body

Example 38

Project: waterbutler
License: View license
Source File: test_provider.py
    async def test_metadata(self, provider, native_dataset_metadata):
        url = provider.build_url(dvs.JSON_BASE_URL.format(provider._id, 'latest'), key=provider.token)
        aiohttpretty.register_json_uri('GET', url, status=200, body=native_dataset_metadata)

        path = await provider.validate_path('/')
        result = await provider.metadata(path, version='latest')

        assert len(result) == 3
        assert result[0].provider == 'dataverse'
        assert result[0].kind == 'file'
        assert result[0].name == 'UnZip.java'
        assert result[0].path == '/19'
        assert result[0].extra['fileId'] == '19'
        assert result[0].materialized_path == '/UnZip.java'

Example 39

Project: waterbutler
License: View license
Source File: test_provider.py
    async def test_upload_doesnt_unquote(self, provider, file_stream):
        upload_id = '7'
        item = fixtures.list_file['items'][0]
        path = GoogleDrivePath('/birdie%2F %20".jpg', _ids=(provider.folder['id'], None))

        start_upload_url = provider._build_upload_url('files', uploadType='resumable')
        finish_upload_url = provider._build_upload_url('files', uploadType='resumable', upload_id=upload_id)

        aiohttpretty.register_json_uri('PUT', finish_upload_url, body=item)
        aiohttpretty.register_uri('POST', start_upload_url, headers={'LOCATION': 'http://waterbutler.io?upload_id={}'.format(upload_id)})

        result, created = await provider.upload(file_stream, path)

        expected = GoogleDriveFileMetadata(item, path)

        assert created is True
        assert result == expected
        assert aiohttpretty.has_call(method='POST', uri=start_upload_url)
        assert aiohttpretty.has_call(method='PUT', uri=finish_upload_url)

Example 40

Project: waterbutler
License: View license
Source File: test_provider.py
Function: test_already_exists
    async def test_already_exists(self, provider):
        path = WaterButlerPath('/newfolder/', prepend=provider.folder)
        url = provider.build_url('fileops', 'create_folder')
        params = build_folder_metadata_params(path)

        aiohttpretty.register_json_uri('POST', url, params=params, status=403, body={
            'error': 'because a file or folder already exists at path'
        })

        with pytest.raises(exceptions.FolderNamingConflict) as e:
            await provider.create_folder(path)

        assert e.value.code == 409
        assert e.value.message == 'Cannot create folder "newfolder" because a file or folder already exists at path "/newfolder/"'

Example 41

Project: waterbutler
License: View license
Source File: test_provider.py
    async def test_metadata_file_root(self, provider):
        path = WaterButlerPath('/birdie.jpg', _ids=(provider.folder['id'], fixtures.list_file['items'][0]['id']))

        list_file_url = provider.build_url('files', path.identifier)
        aiohttpretty.register_json_uri('GET', list_file_url, body=fixtures.list_file['items'][0])

        result = await provider.metadata(path)

        expected = GoogleDriveFileMetadata(fixtures.list_file['items'][0], path)
        assert result == expected

Example 42

Project: waterbutler
License: View license
Source File: test_provider.py
Function: test_upload_create
    async def test_upload_create(self, provider, folder_object_metadata, folder_list_metadata, file_metadata, file_stream, settings):
        path = WaterButlerPath('/newfile', _ids=(provider.folder, None))

        upload_url = provider._build_upload_url('files', 'content')
        folder_object_url = provider.build_url('folders', path.parent.identifier)
        folder_list_url = provider.build_url('folders', path.parent.identifier, 'items')

        aiohttpretty.register_json_uri('POST', upload_url, status=201, body=file_metadata)

        metadata, created = await provider.upload(file_stream, path)

        expected = BoxFileMetadata(file_metadata['entries'][0], path).serialized()

        assert metadata.serialized() == expected
        assert created is True
        assert path.identifier_path == metadata.path
        assert aiohttpretty.has_call(method='POST', uri=upload_url)

Example 43

Project: waterbutler
License: View license
Source File: test_provider.py
    async def test_metadata_root_folder(self, provider):
        path = await provider.validate_path('/')
        query = provider._build_query(provider.folder['id'])
        list_file_url = provider.build_url('files', q=query, alt='json', maxResults=1000)
        aiohttpretty.register_json_uri('GET', list_file_url, body=fixtures.list_file)

        result = await provider.metadata(path)

        expected = GoogleDriveFileMetadata(
            fixtures.list_file['items'][0],
            path.child(fixtures.list_file['items'][0]['title'])
        )
        assert result == [expected]

Example 44

Project: waterbutler
License: View license
Source File: test_provider.py
    async def test_raises_on_errors(self, provider):
        path = WaterButlerPath('/newfolder/', prepend=provider.folder)
        url = provider.build_url('fileops', 'create_folder')
        params = build_folder_metadata_params(path)

        aiohttpretty.register_json_uri('POST', url, params=params, status=418, body={})

        with pytest.raises(exceptions.CreateFolderError) as e:
            await provider.create_folder(path)

        assert e.value.code == 418

Example 45

Project: waterbutler
License: View license
Source File: test_provider.py
    async def test_metadata_published(self, provider, native_dataset_metadata):
        url = provider.build_url(dvs.JSON_BASE_URL.format(provider._id, 'latest-published'), key=provider.token)
        aiohttpretty.register_json_uri('GET', url, status=200, body=native_dataset_metadata)

        path = await provider.validate_path('/')
        result = await provider.metadata(path, version='latest-published')

        assert len(result) == 3
        assert result[0].provider == 'dataverse'
        assert result[0].kind == 'file'
        assert result[0].name == 'UnZip.java'
        assert result[0].path == '/19'
        assert result[0].extra['fileId'] == '19'

Example 46

Project: waterbutler
License: View license
Source File: test_provider.py
Function: test_download
    async def test_download(self, provider, file_metadata):
        item = file_metadata['entries'][0]
        path = WaterButlerPath('/triangles.txt', _ids=(provider.folder, item['id']))

        metadata_url = provider.build_url('files', item['id'])
        content_url = provider.build_url('files', item['id'], 'content')

        aiohttpretty.register_json_uri('GET', metadata_url, body=item)
        aiohttpretty.register_uri('GET', content_url, body=b'better', auto_length=True)

        result = await provider.download(path)
        content = await result.read()

        assert content == b'better'

Example 47

Project: waterbutler
License: View license
Source File: test_provider.py
Function: test_upload_update
    async def test_upload_update(self, provider, folder_object_metadata, folder_list_metadata, file_metadata, file_stream, settings):
        item = folder_list_metadata['entries'][0]
        path = WaterButlerPath('/newfile', _ids=(provider.folder, item['id']))
        upload_url = provider._build_upload_url('files', item['id'], 'content')
        aiohttpretty.register_json_uri('POST', upload_url, status=201, body=file_metadata)

        metadata, created = await provider.upload(file_stream, path)

        expected = BoxFileMetadata(file_metadata['entries'][0], path).serialized()

        assert metadata.serialized() == expected
        assert created is False
        assert aiohttpretty.has_call(method='POST', uri=upload_url)

Example 48

Project: waterbutler
License: View license
Source File: test_provider.py
@pytest.fixture
def mock_auth(auth_json):
    aiohttpretty.register_json_uri(
        'POST',
        settings.AUTH_URL,
        body=auth_json,
    )

Example 49

Project: waterbutler
License: View license
Source File: test_provider.py
    async def test_draft_metadata_no_state_catches_all(self, provider, native_dataset_metadata):
        draft_url = provider.build_url(dvs.JSON_BASE_URL.format(provider._id, 'latest'), key=provider.token)
        aiohttpretty.register_json_uri('GET', draft_url, status=200, body=native_dataset_metadata)
        published_url = provider.build_url(dvs.JSON_BASE_URL.format(provider._id, 'latest-published'), key=provider.token)
        aiohttpretty.register_json_uri('GET', published_url, status=200, body=native_dataset_metadata)

        path = await provider.validate_path('/')
        result = await provider.metadata(path)

        assert isinstance(result, list)
        assert len(result) == 6

Example 50

Project: waterbutler
License: View license
Source File: test_provider.py
    async def test_project_article_download_not_found(self, project_provider, list_project_articles, article_metadata, file_metadata):
        file_id = str(file_metadata['id'])[::-1]
        article_id = str(list_project_articles[0]['id'])

        article_metadata_url = project_provider.build_url('articles', article_id)
        list_articles_url = project_provider.build_url('projects', project_provider.project_id, 'articles')

        aiohttpretty.register_json_uri('GET', list_articles_url, body=list_project_articles)
        aiohttpretty.register_json_uri('GET', article_metadata_url, body=article_metadata)

        path = await project_provider.validate_path('/{}/{}'.format(article_id, file_id))
        with pytest.raises(exceptions.NotFoundError) as exc:
            await project_provider.download(path)
        assert exc.value.code == 404
See More Examples - Go to Next Page
Page 1 Selected Page 2