def test_revision_metadata(self, revision_fixtures): item = revision_fixtures['revisions_list_metadata']['entries'][0] data = BoxRevision(item) assert data.version == '25065971851' assert data.version_identifier == 'revision' assert data.modified == '2015-02-24T09:26:02-08:00' assert data.modified_utc == '2015-02-24T17:26:02+00:00' assert data.serialized() == { 'extra': {}, 'version': '25065971851', 'modified': '2015-02-24T09:26:02-08:00', 'modified_utc': '2015-02-24T17:26:02+00:00', 'versionIdentifier': 'revision' } assert data.json_api_serialized() == { 'id': '25065971851', 'type': 'file_versions', 'attributes': { 'extra': {}, 'version': '25065971851', 'modified': '2015-02-24T09:26:02-08:00', 'modified_utc': '2015-02-24T17:26:02+00:00', 'versionIdentifier': 'revision' } } assert data.extra == {}
def test_get_revisions(self, provider, file_metadata, revisions_list_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=revisions_list_metadata) result = yield from provider.revisions(path) expected = [ BoxRevision(each) for each in [item] + revisions_list_metadata['entries'] ] assert result == expected assert aiohttpretty.has_call(method='GET', uri=file_url) assert aiohttpretty.has_call(method='GET', uri=revisions_url)
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 = yield from provider.revisions(path) expected = [BoxRevision(item).serialized()] assert result == expected assert aiohttpretty.has_call(method='GET', uri=file_url) assert aiohttpretty.has_call(method='GET', uri=revisions_url)
def revisions(self, path, **kwargs): # from https://developers.box.com/docs/#files-view-versions-of-a-file : # Alert: Versions are only tracked for Box users with premium accounts. # Few users will have a premium account, return only current if not curr = yield from self.metadata(path, raw=True) response = yield from self.make_request( 'GET', self.build_url('files', path.identifier, 'versions'), expects=(200, 403), throws=exceptions.RevisionsError, ) data = yield from response.json() revisions = data['entries'] if response.status == http.client.OK else [] return [BoxRevision(each) for each in [curr] + revisions]
async def revisions(self, path: wb_path.WaterButlerPath, **kwargs) -> typing.List[BoxRevision]: # from https://developers.box.com/docs/#files-view-versions-of-a-file : # Alert: Versions are only tracked for Box users with premium accounts. # Few users will have a premium account, return only current if not curr = await self.metadata(path, raw=True) async with self.request( 'GET', self.build_url('files', path.identifier, 'versions'), expects=(200, 403), throws=exceptions.RevisionsError, ) as response: data = await response.json() revisions = data['entries'] if response.status == HTTPStatus.OK else [] return [BoxRevision(each) for each in [curr] + revisions]