def test_extract_id_from_url(self): url_id_list = [ # New-style url ( 'https://docs.google.com/spreadsheets/d/' '1qpyC0X3A0MwQoFDE8p-Bll4hps/edit#gid=0', '1qpyC0X3A0MwQoFDE8p-Bll4hps', ), ( 'https://docs.google.com/spreadsheets/d/' '1qpyC0X3A0MwQoFDE8p-Bll4hps/edit', '1qpyC0X3A0MwQoFDE8p-Bll4hps', ), ( 'https://docs.google.com/spreadsheets/d/' '1qpyC0X3A0MwQoFDE8p-Bll4hps', '1qpyC0X3A0MwQoFDE8p-Bll4hps', ), # Old-style url ( 'https://docs.google.com/spreadsheet/' 'ccc?key=1qpyC0X3A0MwQoFDE8p-Bll4hps&usp=drive_web#gid=0', '1qpyC0X3A0MwQoFDE8p-Bll4hps', ), ] for url, id in url_id_list: self.assertEqual(id, utils.extract_id_from_url(url))
async def open_by_url(self, url): """Opens a Google Spreadsheet from a URL. Wraps :meth:`gspread.Client.open_by_url`. Feel free to call this method often, even in a loop, as it caches the underlying spreadsheet object. :param url: URL to a Google Spreadsheet :type url: str :returns: :class:`~gspread_asyncio.AsyncioGspreadSpreadsheet` """ ss_id = extract_id_from_url(url) return await self.open_by_key(ss_id)