Esempio n. 1
0
    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)
Esempio n. 2
0
    async def test_metadata_folder_nested(self, provider):
        path = GoogleDrivePath('/hugo/kim/pins/',
                               _ids=[str(x) for x in range(4)])

        body = fixtures.generate_list(3)
        item = body['items'][0]

        query = provider._build_query(path.identifier)
        url = provider.build_url('files', q=query, alt='json', maxResults=1000)

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

        result = await provider.metadata(path)

        expected = GoogleDriveFileMetadata(item, path.child(item['title']))

        assert result == [expected]
        assert aiohttpretty.has_call(method='GET', uri=url)
Esempio n. 3
0
    def test_folder_metadata(self, provider):
        path = GoogleDrivePath('/hugo/kim/pins/',
                               _ids=[str(x) for x in range(4)])

        body = fixtures.generate_list(3, **fixtures.folder_metadata)
        item = body['items'][0]

        query = provider._build_query(path.identifier)
        url = provider.build_url('files', q=query, alt='json')

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

        result = yield from provider.metadata(path)

        expected = GoogleDriveFolderMetadata(
            item, path.child(item['title'], folder=True)).serialized()

        assert result == [expected]
        assert aiohttpretty.has_call(method='GET', uri=url)
Esempio n. 4
0
    def test_folder_metadata(self, provider):
        path = GoogleDrivePath(
            '/hugo/kim/pins/',
            _ids=[str(x) for x in range(4)]
        )

        body = fixtures.generate_list(3, **fixtures.folder_metadata)
        item = body['items'][0]

        query = provider._build_query(path.identifier)
        url = provider.build_url('files', q=query, alt='json')

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

        result = yield from provider.metadata(path)

        expected = GoogleDriveFolderMetadata(item, path.child(item['title'], folder=True)).serialized()

        assert result == [expected]
        assert aiohttpretty.has_call(method='GET', uri=url)
    async def test_metadata_folder_nested(self, provider):
        path = GoogleDrivePath(
            '/hugo/kim/pins/',
            _ids=[str(x) for x in range(4)]
        )

        body = fixtures.generate_list(3)
        item = body['items'][0]

        query = provider._build_query(path.identifier)
        url = provider.build_url('files', q=query, alt='json', maxResults=1000)

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

        result = await provider.metadata(path)

        expected = GoogleDriveFileMetadata(item, path.child(item['title']))

        assert result == [expected]
        assert aiohttpretty.has_call(method='GET', uri=url)
Esempio n. 6
0
def test_folder_metadata_slash():
    item = fixtures.folder_metadata_forward_slash
    path = GoogleDrivePath('/we/love/you/conrad').child(item['title'],
                                                        folder=True)
    parsed = GoogleDriveFolderMetadata(item, path)

    assert parsed.provider == 'googledrive'
    assert parsed.id == item['id']
    assert parsed.name == item['title']
    assert parsed.extra == {'revisionId': item['version']}
    assert parsed.path == '/' + os.path.join(*[x.raw
                                               for x in path.parts]) + '/'
    assert parsed.materialized_path == str(path)
Esempio n. 7
0
    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)
Esempio n. 8
0
def basepath():
    return GoogleDrivePath('/conrad')