def test_RemovePrefix(self): # Create BytesIO. file_obj = BytesIO(u'\ufeffabc'.encode('utf8')) original_length = len(file_obj.getvalue()) char_to_remove = u'\ufeff'.encode('utf8') # Insert the prefix. GoogleDriveFile._RemovePrefix(file_obj, char_to_remove) modified_length = len(file_obj.getvalue()) self.assertLess(modified_length, original_length) self.assertEqual(file_obj.getvalue(), 'abc'.encode('utf8'))
def test_InsertPrefix(self): # Create BytesIO. file_obj = BytesIO('abc'.encode('utf8')) original_length = len(file_obj.getvalue()) char_to_insert = u'\ufeff'.encode('utf8') # Insert the prefix. GoogleDriveFile._InsertPrefix(file_obj, char_to_insert) modified_length = len(file_obj.getvalue()) self.assertGreater(modified_length, original_length) self.assertEqual(file_obj.getvalue(), u'\ufeffabc'.encode('utf8'))
def test_RemovePrefixLarge(self): # Create BytesIO. test_content = u'\ufeff' + u'abc' * 800 file_obj = BytesIO(test_content.encode('utf8')) original_length = len(file_obj.getvalue()) char_to_remove = u'\ufeff'.encode('utf8') # Insert the prefix. GoogleDriveFile._RemovePrefix(file_obj, char_to_remove) modified_length = len(file_obj.getvalue()) self.assertLess(modified_length, original_length) self.assertEqual(file_obj.getvalue(), test_content[1:].encode('utf8'))
def test_InsertPrefixLarge(self): # Create BytesIO. test_content = 'abc' * 800 file_obj = BytesIO(test_content.encode('utf-8')) original_length = len(file_obj.getvalue()) char_to_insert = u'\ufeff'.encode('utf8') # Insert the prefix. GoogleDriveFile._InsertPrefix(file_obj, char_to_insert) modified_length = len(file_obj.getvalue()) self.assertGreater(modified_length, original_length) expected_content = u'\ufeff' + test_content self.assertEqual(file_obj.getvalue(), expected_content.encode('utf8'))
def _to_id(self, file_: GoogleDriveFile): """Return the id of the object unless it is a shortcut, then find the true id. """ if file_["mimeType"] == "application/vnd.google-apps.shortcut": file_.FetchMetadata(fields="shortcutDetails") return file_["shortcutDetails"]["targetId"] else: return file_["id"]