def test_upload_create_nested(self, provider, file_stream): path = '/ed/sullivan/show.mp3' upload_id = '7' parts = path.split('/') urls, bodies = [], [] for idx, part in enumerate(parts[:-1]): query = provider._build_query(idx or provider.folder['id'], title=parts[idx + 1]) if part == 'sullivan': body = {'items': []} else: body = fixtures.generate_list(idx + 1) url = provider.build_url('files', q=query, alt='json') aiohttpretty.register_json_uri('GET', url, body=body) urls.append(url) bodies.append(body) item = fixtures.list_file['items'][0] 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_uri('POST', start_upload_url, headers={'LOCATION': 'http://waterbutler.io?upload_id={}'.format(upload_id)}) aiohttpretty.register_json_uri('PUT', finish_upload_url, body=item) result, created = yield from provider.upload(file_stream, path) assert aiohttpretty.has_call(method='POST', uri=start_upload_url) assert aiohttpretty.has_call(method='PUT', uri=finish_upload_url) assert created is True expected = GoogleDriveFileMetadata(item, '/ed/sullivan').serialized() assert result == expected
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)
def test_already_exists(self, provider): path = '/hugo/kim/pins/' parts = path.split('/') for idx, part in enumerate(parts[:-1]): query = provider._build_query(idx or provider.folder['id'], title=parts[idx + 1]) body = fixtures.generate_list(idx + 1) url = provider.build_url('files', q=query, alt='json') aiohttpretty.register_json_uri('GET', url, body=body) with pytest.raises(exceptions.FolderNamingConflict) as e: yield from provider.create_folder(path) assert e.value.code == 409 assert e.value.message == 'Cannot create folder "pins" because a file or folder already exists at path "/hugo/kim/pins/"'
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 = yield from provider.metadata(path) expected = GoogleDriveFileMetadata(item, path).serialized() assert result == expected assert aiohttpretty.has_call(method='GET', uri=url)
def test_metadata_folder_nested(self, provider): path = '/hugo/kim/pins/' parts = path.split('/') urls, bodies = [], [] for idx, part in enumerate(parts[:-1]): query = provider._build_query(idx or provider.folder['id'], title=parts[idx + 1]) body = fixtures.generate_list(idx + 1) url = provider.build_url('files', q=query, alt='json') aiohttpretty.register_json_uri('GET', url, body=body) urls.append(url) bodies.append(body) result = yield from provider.metadata(path) for url in urls: assert aiohttpretty.has_call(method='GET', uri=url) expected = GoogleDriveFileMetadata(bodies[-1]['items'][0], '/hugo/kim/pins').serialized() assert result == [expected]
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)
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)
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)