def test_get_empty_file(self): returned_f = FileUtils.get_empty_file() self.assertEqual(returned_f, { 'version': FileUtils.LAST_FILE_VERSION, 'content': '', 'currentVideo': None, 'videos': {}, 'syncNotesVideo': True })
def test_get_empty_file(self): returned_f = FileUtils.get_empty_file() self.assertEqual( returned_f, { 'version': FileUtils.LAST_FILE_VERSION, 'content': '', 'currentVideo': None, 'videos': {}, 'syncNotesVideo': True })
def get_file(self, file_id): service = self.CreateDrive() if service is None: return # Requests are expected to pass the file_id query parameter. logging.info('Get file %s', file_id) if file_id: # Fetch the file metadata by making the service.files().get method of # the Drive API. f = service.files().get(fileId=file_id).execute() downloadUrl = f.get('downloadUrl') # If a download URL is provided in the file metadata, use it to make an # authorized request to fetch the file ontent. Set this content in the # data to return as the 'content' field. If there is no downloadUrl, # just set empty content. if downloadUrl: logging.debug('Downloading the file from %s', downloadUrl) resp, raw_content = service._http.request(downloadUrl) logging.debug('Response status : %s', resp.status) logging.debug('Raw content : %s', raw_content) if resp and resp.status == int(200) and raw_content: try: json_content = json.loads(raw_content) f.update(json_content) except ValueError: logging.info( "ValueError when decoding raw content in JSON") f.update(FileUtils.get_empty_file()) else: logging.debug("No content or error response") f.update(FileUtils.get_empty_file()) else: logging.debug('No download URL') f.update(FileUtils.get_empty_file()) else: f = None # Generate a JSON response with the file data and return to the client. return f
def get_file(self, file_id): service = self.CreateDrive() if service is None: return # Requests are expected to pass the file_id query parameter. logging.info('Get file %s', file_id) if file_id: # Fetch the file metadata by making the service.files().get method of # the Drive API. f = service.files().get(fileId=file_id).execute() downloadUrl = f.get('downloadUrl') # If a download URL is provided in the file metadata, use it to make an # authorized request to fetch the file ontent. Set this content in the # data to return as the 'content' field. If there is no downloadUrl, # just set empty content. if downloadUrl: logging.debug('Downloading the file from %s', downloadUrl) resp, raw_content = service._http.request(downloadUrl) logging.debug('Response status : %s', resp.status) logging.debug('Raw content : %s', raw_content) if resp and resp.status == int(200) and raw_content: try: json_content = json.loads(raw_content) f.update(json_content) except ValueError: logging.info("ValueError when decoding raw content in JSON") f.update(FileUtils.get_empty_file()) else: logging.debug("No content or error response") f.update(FileUtils.get_empty_file()) else: logging.debug('No download URL') f.update(FileUtils.get_empty_file()) else: f = None # Generate a JSON response with the file data and return to the client. return f