From 1e05bd53282d1963d3973f25b3dc92d24a1139cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cantoineeripret=E2=80=9D?= Date: Thu, 26 Mar 2026 23:16:43 +0100 Subject: [PATCH 1/6] update_named_range() method added --- gspread/worksheet.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/gspread/worksheet.py b/gspread/worksheet.py index ba9fde0a4..bab520eb5 100644 --- a/gspread/worksheet.py +++ b/gspread/worksheet.py @@ -2923,6 +2923,31 @@ def delete_named_range(self, named_range_id: str) -> JSONResponse: } return self.client.batch_update(self.spreadsheet_id, body) + @cast_to_a1_notation + def update_named_range(self, named_range_id: str, new_name: str) -> JSONResponse: + """ + :param str named_range_id: The ID of the named range to update. + Can be obtained with Spreadsheet.list_named_ranges() + :param str new_name: The new name to assign to the named range. + + :returns: the response body from the request + :rtype: dict + """ + body = { + "requests": [ + { + "updateNamedRange": { + "namedRange": { + "namedRangeId": named_range_id, + "name": new_name, + }, + "fields": "name", + } + } + ] + } + return self.client.batch_update(self.spreadsheet_id, body) + def _add_dimension_group( self, start: int, end: int, dimension: Dimension ) -> JSONResponse: From 826696d07d6711579a49e4c44a0e86eb31fc122a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cantoineeripret=E2=80=9D?= Date: Sun, 29 Mar 2026 22:30:45 +0200 Subject: [PATCH 2/6] update range & name for named ranges --- gspread/worksheet.py | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/gspread/worksheet.py b/gspread/worksheet.py index bab520eb5..7c17cea89 100644 --- a/gspread/worksheet.py +++ b/gspread/worksheet.py @@ -2923,25 +2923,46 @@ def delete_named_range(self, named_range_id: str) -> JSONResponse: } return self.client.batch_update(self.spreadsheet_id, body) - @cast_to_a1_notation - def update_named_range(self, named_range_id: str, new_name: str) -> JSONResponse: - """ + def update_named_range( + self, + named_range_id: str, + new_name: Optional[str] = None, + new_range: Optional[str] = None, + ) -> JSONResponse: + """Update the name and/or range of an existing named range. + + At least one of ``new_name`` or ``new_range`` must be provided. + :param str named_range_id: The ID of the named range to update. - Can be obtained with Spreadsheet.list_named_ranges() + Can be obtained with :meth:`~gspread.Spreadsheet.list_named_ranges`. :param str new_name: The new name to assign to the named range. + :param str new_range: The new cell range in A1 notation (e.g. ``"A1:B10"``). :returns: the response body from the request :rtype: dict + + :raises ValueError: if neither ``new_name`` nor ``new_range`` is provided. """ + if new_name is None and new_range is None: + raise ValueError("At least one of new_name or new_range must be provided.") + + named_range: dict = {"namedRangeId": named_range_id} + fields: list[str] = [] + + if new_name is not None: + named_range["name"] = new_name + fields.append("name") + + if new_range is not None: + named_range["range"] = a1_range_to_grid_range(new_range, self.id) + fields.append("range") + body = { "requests": [ { "updateNamedRange": { - "namedRange": { - "namedRangeId": named_range_id, - "name": new_name, - }, - "fields": "name", + "namedRange": named_range, + "fields": ",".join(fields), } } ] From 93e53b2021275c0a9d7ad817e91a34ea728f014b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cantoineeripret=E2=80=9D?= Date: Sun, 29 Mar 2026 22:31:08 +0200 Subject: [PATCH 3/6] update docs with named range --- docs/user-guide.rst | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/docs/user-guide.rst b/docs/user-guide.rst index 50b90971f..7061933e7 100644 --- a/docs/user-guide.rst +++ b/docs/user-guide.rst @@ -459,6 +459,33 @@ The second argument to :meth:`~gspread.models.Worksheet.format` is a dictionary for more complex formatting see :ref:`gspread-formating-label`. +Named Ranges +~~~~~~~~~~~~ + +List all named ranges in a spreadsheet: + +.. code:: python + + named_ranges = spreadsheet.list_named_ranges() + +Update an existing named range (rename it, change its range, or both): + +.. code:: python + + worksheet.update_named_range("named_range_id", new_name="new_name") + worksheet.update_named_range("named_range_id", new_range="A1:B10") + worksheet.update_named_range("named_range_id", new_name="new_name", new_range="A1:B10") + +Delete a named range: + +.. code:: python + + worksheet.delete_named_range("named_range_id") + +.. Note:: + The ``named_range_id`` can be obtained from :meth:`~gspread.Spreadsheet.list_named_ranges`. + + Using gspread with pandas ~~~~~~~~~~~~~~~~~~~~~~~~~ From d87e7dc5cd167f3a154b7b6efc4c928ef6360321 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cantoineeripret=E2=80=9D?= Date: Sun, 29 Mar 2026 22:39:10 +0200 Subject: [PATCH 4/6] Use List instead of list for compatibility with Python 3.8 --- gspread/worksheet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gspread/worksheet.py b/gspread/worksheet.py index 7c17cea89..5b131051b 100644 --- a/gspread/worksheet.py +++ b/gspread/worksheet.py @@ -2947,7 +2947,7 @@ def update_named_range( raise ValueError("At least one of new_name or new_range must be provided.") named_range: dict = {"namedRangeId": named_range_id} - fields: list[str] = [] + fields: List[str] = [] if new_name is not None: named_range["name"] = new_name From b2d51b44c0e31afc98bed166a2049ae711a989aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cantoineeripret=E2=80=9D?= Date: Tue, 31 Mar 2026 12:00:06 +0200 Subject: [PATCH 5/6] add tests for new method --- tests/cell_test.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/cell_test.py b/tests/cell_test.py index 41519baa0..396b5c8a4 100644 --- a/tests/cell_test.py +++ b/tests/cell_test.py @@ -193,3 +193,42 @@ def test_delete_named_range(self): # make sure that no ranges were returned self.assertEqual(named_range_dict, {}) + + @pytest.mark.vcr() + def test_update_named_range(self): + # define a named range + result = self.sheet.define_named_range("A1:B2", "TestUpdateNamedRange") + + named_range_id = result["replies"][0]["addNamedRange"]["namedRange"][ + "namedRangeId" + ] + + # update the name + self.sheet.update_named_range(named_range_id, new_name="UpdatedName") + + named_range_dict = self.spreadsheet.fetch_sheet_metadata( + params={"fields": "namedRanges"} + ) + self.assertIn("namedRanges", named_range_dict) + named_range = named_range_dict["namedRanges"][0] + self.assertEqual(named_range["name"], "UpdatedName") + + # update the range + self.sheet.update_named_range(named_range_id, new_range="C3:D4") + + named_range_dict = self.spreadsheet.fetch_sheet_metadata( + params={"fields": "namedRanges"} + ) + named_range = named_range_dict["namedRanges"][0] + self.assertEqual(named_range["range"]["startRowIndex"], 2) + self.assertEqual(named_range["range"]["endRowIndex"], 4) + self.assertEqual(named_range["range"]["startColumnIndex"], 2) + self.assertEqual(named_range["range"]["endColumnIndex"], 4) + + # clean up + self.sheet.delete_named_range(named_range_id) + + @pytest.mark.vcr() + def test_update_named_range_no_args(self): + with self.assertRaises(ValueError): + self.sheet.update_named_range("some_id") From 764b570c5d341a3336d3105089d43c2715f8cd2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cantoineeripret=E2=80=9D?= Date: Tue, 31 Mar 2026 12:00:20 +0200 Subject: [PATCH 6/6] added VCR for new implemented tests --- .../CellTest.test_update_named_range.json | 743 ++++++++++++++++++ ...lTest.test_update_named_range_no_args.json | 299 +++++++ 2 files changed, 1042 insertions(+) create mode 100644 tests/cassettes/CellTest.test_update_named_range.json create mode 100644 tests/cassettes/CellTest.test_update_named_range_no_args.json diff --git a/tests/cassettes/CellTest.test_update_named_range.json b/tests/cassettes/CellTest.test_update_named_range.json new file mode 100644 index 000000000..a5c966e8e --- /dev/null +++ b/tests/cassettes/CellTest.test_update_named_range.json @@ -0,0 +1,743 @@ +{ + "version": 1, + "interactions": [ + { + "request": { + "method": "POST", + "uri": "https://www.googleapis.com/drive/v3/files?supportsAllDrives=True", + "body": "{\"name\": \"Test CellTest test_update_named_range\", \"mimeType\": \"application/vnd.google-apps.spreadsheet\"}", + "headers": { + "User-Agent": [ + "python-requests/2.33.1" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Accept": [ + "*/*" + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "104" + ], + "Content-Type": [ + "application/json" + ], + "authorization": [ + "" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Vary": [ + "Origin, X-Origin" + ], + "Date": [ + "Tue, 31 Mar 2026 09:27:40 GMT" + ], + "Expires": [ + "Mon, 01 Jan 1990 00:00:00 GMT" + ], + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "Alt-Svc": [ + "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" + ], + "Pragma": [ + "no-cache" + ], + "Cache-Control": [ + "no-cache, no-store, max-age=0, must-revalidate" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Transfer-Encoding": [ + "chunked" + ], + "X-XSS-Protection": [ + "0" + ], + "Server": [ + "ESF" + ], + "content-length": [ + "191" + ] + }, + "body": { + "string": "{\n \"kind\": \"drive#file\",\n \"id\": \"1PCM2voiOZWzwb7gctVD0bT2UvIG7EKwmBbwsKw5zC3s\",\n \"name\": \"Test CellTest test_update_named_range\",\n \"mimeType\": \"application/vnd.google-apps.spreadsheet\"\n}\n" + } + } + }, + { + "request": { + "method": "GET", + "uri": "https://sheets.googleapis.com/v4/spreadsheets/1PCM2voiOZWzwb7gctVD0bT2UvIG7EKwmBbwsKw5zC3s?includeGridData=false", + "body": null, + "headers": { + "User-Agent": [ + "python-requests/2.33.1" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Accept": [ + "*/*" + ], + "Connection": [ + "keep-alive" + ], + "authorization": [ + "" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Vary": [ + "Origin", + "X-Origin", + "Referer" + ], + "Date": [ + "Tue, 31 Mar 2026 09:27:41 GMT" + ], + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "Alt-Svc": [ + "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" + ], + "x-l2-request-path": [ + "l2-managed-6" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Transfer-Encoding": [ + "chunked" + ], + "X-XSS-Protection": [ + "0" + ], + "Server": [ + "ESF" + ], + "content-length": [ + "3335" + ] + }, + "body": { + "string": "{\n \"spreadsheetId\": \"1PCM2voiOZWzwb7gctVD0bT2UvIG7EKwmBbwsKw5zC3s\",\n \"properties\": {\n \"title\": \"Test CellTest test_update_named_range\",\n \"locale\": \"en_US\",\n \"autoRecalc\": \"ON_CHANGE\",\n \"timeZone\": \"Etc/GMT\",\n \"defaultFormat\": {\n \"backgroundColor\": {\n \"red\": 1,\n \"green\": 1,\n \"blue\": 1\n },\n \"padding\": {\n \"top\": 2,\n \"right\": 3,\n \"bottom\": 2,\n \"left\": 3\n },\n \"verticalAlignment\": \"BOTTOM\",\n \"wrapStrategy\": \"OVERFLOW_CELL\",\n \"textFormat\": {\n \"foregroundColor\": {},\n \"fontFamily\": \"arial,sans,sans-serif\",\n \"fontSize\": 10,\n \"bold\": false,\n \"italic\": false,\n \"strikethrough\": false,\n \"underline\": false,\n \"foregroundColorStyle\": {\n \"rgbColor\": {}\n }\n },\n \"backgroundColorStyle\": {\n \"rgbColor\": {\n \"red\": 1,\n \"green\": 1,\n \"blue\": 1\n }\n }\n },\n \"spreadsheetTheme\": {\n \"primaryFontFamily\": \"Arial\",\n \"themeColors\": [\n {\n \"colorType\": \"TEXT\",\n \"color\": {\n \"rgbColor\": {}\n }\n },\n {\n \"colorType\": \"BACKGROUND\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 1,\n \"green\": 1,\n \"blue\": 1\n }\n }\n },\n {\n \"colorType\": \"ACCENT1\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.25882354,\n \"green\": 0.52156866,\n \"blue\": 0.95686275\n }\n }\n },\n {\n \"colorType\": \"ACCENT2\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.91764706,\n \"green\": 0.2627451,\n \"blue\": 0.20784314\n }\n }\n },\n {\n \"colorType\": \"ACCENT3\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.9843137,\n \"green\": 0.7372549,\n \"blue\": 0.015686275\n }\n }\n },\n {\n \"colorType\": \"ACCENT4\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.20392157,\n \"green\": 0.65882355,\n \"blue\": 0.3254902\n }\n }\n },\n {\n \"colorType\": \"ACCENT5\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 1,\n \"green\": 0.42745098,\n \"blue\": 0.003921569\n }\n }\n },\n {\n \"colorType\": \"ACCENT6\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.27450982,\n \"green\": 0.7411765,\n \"blue\": 0.7764706\n }\n }\n },\n {\n \"colorType\": \"LINK\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.06666667,\n \"green\": 0.33333334,\n \"blue\": 0.8\n }\n }\n }\n ]\n }\n },\n \"sheets\": [\n {\n \"properties\": {\n \"sheetId\": 0,\n \"title\": \"Sheet1\",\n \"index\": 0,\n \"sheetType\": \"GRID\",\n \"gridProperties\": {\n \"rowCount\": 1000,\n \"columnCount\": 26\n }\n }\n }\n ],\n \"spreadsheetUrl\": \"https://docs.google.com/spreadsheets/d/1PCM2voiOZWzwb7gctVD0bT2UvIG7EKwmBbwsKw5zC3s/edit\"\n}\n" + } + } + }, + { + "request": { + "method": "GET", + "uri": "https://sheets.googleapis.com/v4/spreadsheets/1PCM2voiOZWzwb7gctVD0bT2UvIG7EKwmBbwsKw5zC3s?includeGridData=false", + "body": null, + "headers": { + "User-Agent": [ + "python-requests/2.33.1" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Accept": [ + "*/*" + ], + "Connection": [ + "keep-alive" + ], + "authorization": [ + "" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Vary": [ + "Origin", + "X-Origin", + "Referer" + ], + "Date": [ + "Tue, 31 Mar 2026 09:27:42 GMT" + ], + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "Alt-Svc": [ + "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" + ], + "x-l2-request-path": [ + "l2-managed-6" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Transfer-Encoding": [ + "chunked" + ], + "X-XSS-Protection": [ + "0" + ], + "Server": [ + "ESF" + ], + "content-length": [ + "3335" + ] + }, + "body": { + "string": "{\n \"spreadsheetId\": \"1PCM2voiOZWzwb7gctVD0bT2UvIG7EKwmBbwsKw5zC3s\",\n \"properties\": {\n \"title\": \"Test CellTest test_update_named_range\",\n \"locale\": \"en_US\",\n \"autoRecalc\": \"ON_CHANGE\",\n \"timeZone\": \"Etc/GMT\",\n \"defaultFormat\": {\n \"backgroundColor\": {\n \"red\": 1,\n \"green\": 1,\n \"blue\": 1\n },\n \"padding\": {\n \"top\": 2,\n \"right\": 3,\n \"bottom\": 2,\n \"left\": 3\n },\n \"verticalAlignment\": \"BOTTOM\",\n \"wrapStrategy\": \"OVERFLOW_CELL\",\n \"textFormat\": {\n \"foregroundColor\": {},\n \"fontFamily\": \"arial,sans,sans-serif\",\n \"fontSize\": 10,\n \"bold\": false,\n \"italic\": false,\n \"strikethrough\": false,\n \"underline\": false,\n \"foregroundColorStyle\": {\n \"rgbColor\": {}\n }\n },\n \"backgroundColorStyle\": {\n \"rgbColor\": {\n \"red\": 1,\n \"green\": 1,\n \"blue\": 1\n }\n }\n },\n \"spreadsheetTheme\": {\n \"primaryFontFamily\": \"Arial\",\n \"themeColors\": [\n {\n \"colorType\": \"TEXT\",\n \"color\": {\n \"rgbColor\": {}\n }\n },\n {\n \"colorType\": \"BACKGROUND\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 1,\n \"green\": 1,\n \"blue\": 1\n }\n }\n },\n {\n \"colorType\": \"ACCENT1\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.25882354,\n \"green\": 0.52156866,\n \"blue\": 0.95686275\n }\n }\n },\n {\n \"colorType\": \"ACCENT2\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.91764706,\n \"green\": 0.2627451,\n \"blue\": 0.20784314\n }\n }\n },\n {\n \"colorType\": \"ACCENT3\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.9843137,\n \"green\": 0.7372549,\n \"blue\": 0.015686275\n }\n }\n },\n {\n \"colorType\": \"ACCENT4\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.20392157,\n \"green\": 0.65882355,\n \"blue\": 0.3254902\n }\n }\n },\n {\n \"colorType\": \"ACCENT5\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 1,\n \"green\": 0.42745098,\n \"blue\": 0.003921569\n }\n }\n },\n {\n \"colorType\": \"ACCENT6\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.27450982,\n \"green\": 0.7411765,\n \"blue\": 0.7764706\n }\n }\n },\n {\n \"colorType\": \"LINK\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.06666667,\n \"green\": 0.33333334,\n \"blue\": 0.8\n }\n }\n }\n ]\n }\n },\n \"sheets\": [\n {\n \"properties\": {\n \"sheetId\": 0,\n \"title\": \"Sheet1\",\n \"index\": 0,\n \"sheetType\": \"GRID\",\n \"gridProperties\": {\n \"rowCount\": 1000,\n \"columnCount\": 26\n }\n }\n }\n ],\n \"spreadsheetUrl\": \"https://docs.google.com/spreadsheets/d/1PCM2voiOZWzwb7gctVD0bT2UvIG7EKwmBbwsKw5zC3s/edit\"\n}\n" + } + } + }, + { + "request": { + "method": "POST", + "uri": "https://sheets.googleapis.com/v4/spreadsheets/1PCM2voiOZWzwb7gctVD0bT2UvIG7EKwmBbwsKw5zC3s:batchUpdate", + "body": "{\"requests\": [{\"addNamedRange\": {\"namedRange\": {\"name\": \"TestUpdateNamedRange\", \"range\": {\"startRowIndex\": 0, \"endRowIndex\": 2, \"startColumnIndex\": 0, \"endColumnIndex\": 2, \"sheetId\": 0}}}}]}", + "headers": { + "User-Agent": [ + "python-requests/2.33.1" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Accept": [ + "*/*" + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "190" + ], + "Content-Type": [ + "application/json" + ], + "authorization": [ + "" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Vary": [ + "Origin", + "X-Origin", + "Referer" + ], + "Date": [ + "Tue, 31 Mar 2026 09:27:43 GMT" + ], + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "Alt-Svc": [ + "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" + ], + "x-l2-request-path": [ + "l2-managed-6" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Transfer-Encoding": [ + "chunked" + ], + "X-XSS-Protection": [ + "0" + ], + "Server": [ + "ESF" + ], + "content-length": [ + "413" + ] + }, + "body": { + "string": "{\n \"spreadsheetId\": \"1PCM2voiOZWzwb7gctVD0bT2UvIG7EKwmBbwsKw5zC3s\",\n \"replies\": [\n {\n \"addNamedRange\": {\n \"namedRange\": {\n \"namedRangeId\": \"1450817762\",\n \"name\": \"TestUpdateNamedRange\",\n \"range\": {\n \"startRowIndex\": 0,\n \"endRowIndex\": 2,\n \"startColumnIndex\": 0,\n \"endColumnIndex\": 2\n }\n }\n }\n }\n ]\n}\n" + } + } + }, + { + "request": { + "method": "POST", + "uri": "https://sheets.googleapis.com/v4/spreadsheets/1PCM2voiOZWzwb7gctVD0bT2UvIG7EKwmBbwsKw5zC3s:batchUpdate", + "body": "{\"requests\": [{\"updateNamedRange\": {\"namedRange\": {\"namedRangeId\": \"1450817762\", \"name\": \"UpdatedName\"}, \"fields\": \"name\"}}]}", + "headers": { + "User-Agent": [ + "python-requests/2.33.1" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Accept": [ + "*/*" + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "125" + ], + "Content-Type": [ + "application/json" + ], + "authorization": [ + "" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Vary": [ + "Origin", + "X-Origin", + "Referer" + ], + "Date": [ + "Tue, 31 Mar 2026 09:27:44 GMT" + ], + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "Alt-Svc": [ + "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" + ], + "x-l2-request-path": [ + "l2-managed-6" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Transfer-Encoding": [ + "chunked" + ], + "X-XSS-Protection": [ + "0" + ], + "Server": [ + "ESF" + ], + "content-length": [ + "97" + ] + }, + "body": { + "string": "{\n \"spreadsheetId\": \"1PCM2voiOZWzwb7gctVD0bT2UvIG7EKwmBbwsKw5zC3s\",\n \"replies\": [\n {}\n ]\n}\n" + } + } + }, + { + "request": { + "method": "GET", + "uri": "https://sheets.googleapis.com/v4/spreadsheets/1PCM2voiOZWzwb7gctVD0bT2UvIG7EKwmBbwsKw5zC3s?fields=namedRanges", + "body": null, + "headers": { + "User-Agent": [ + "python-requests/2.33.1" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Accept": [ + "*/*" + ], + "Connection": [ + "keep-alive" + ], + "authorization": [ + "" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Vary": [ + "Origin", + "X-Origin", + "Referer" + ], + "Date": [ + "Tue, 31 Mar 2026 09:27:44 GMT" + ], + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "Alt-Svc": [ + "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" + ], + "x-l2-request-path": [ + "l2-managed-6" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Transfer-Encoding": [ + "chunked" + ], + "X-XSS-Protection": [ + "0" + ], + "Server": [ + "ESF" + ], + "content-length": [ + "242" + ] + }, + "body": { + "string": "{\n \"namedRanges\": [\n {\n \"namedRangeId\": \"1450817762\",\n \"name\": \"UpdatedName\",\n \"range\": {\n \"startRowIndex\": 0,\n \"endRowIndex\": 2,\n \"startColumnIndex\": 0,\n \"endColumnIndex\": 2\n }\n }\n ]\n}\n" + } + } + }, + { + "request": { + "method": "POST", + "uri": "https://sheets.googleapis.com/v4/spreadsheets/1PCM2voiOZWzwb7gctVD0bT2UvIG7EKwmBbwsKw5zC3s:batchUpdate", + "body": "{\"requests\": [{\"updateNamedRange\": {\"namedRange\": {\"namedRangeId\": \"1450817762\", \"range\": {\"startRowIndex\": 2, \"endRowIndex\": 4, \"startColumnIndex\": 2, \"endColumnIndex\": 4, \"sheetId\": 0}}, \"fields\": \"range\"}}]}", + "headers": { + "User-Agent": [ + "python-requests/2.33.1" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Accept": [ + "*/*" + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "210" + ], + "Content-Type": [ + "application/json" + ], + "authorization": [ + "" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Vary": [ + "Origin", + "X-Origin", + "Referer" + ], + "Date": [ + "Tue, 31 Mar 2026 09:27:45 GMT" + ], + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "Alt-Svc": [ + "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" + ], + "x-l2-request-path": [ + "l2-managed-6" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Transfer-Encoding": [ + "chunked" + ], + "X-XSS-Protection": [ + "0" + ], + "Server": [ + "ESF" + ], + "content-length": [ + "97" + ] + }, + "body": { + "string": "{\n \"spreadsheetId\": \"1PCM2voiOZWzwb7gctVD0bT2UvIG7EKwmBbwsKw5zC3s\",\n \"replies\": [\n {}\n ]\n}\n" + } + } + }, + { + "request": { + "method": "GET", + "uri": "https://sheets.googleapis.com/v4/spreadsheets/1PCM2voiOZWzwb7gctVD0bT2UvIG7EKwmBbwsKw5zC3s?fields=namedRanges", + "body": null, + "headers": { + "User-Agent": [ + "python-requests/2.33.1" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Accept": [ + "*/*" + ], + "Connection": [ + "keep-alive" + ], + "authorization": [ + "" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Vary": [ + "Origin", + "X-Origin", + "Referer" + ], + "Date": [ + "Tue, 31 Mar 2026 09:27:46 GMT" + ], + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "Alt-Svc": [ + "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" + ], + "x-l2-request-path": [ + "l2-managed-6" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Transfer-Encoding": [ + "chunked" + ], + "X-XSS-Protection": [ + "0" + ], + "Server": [ + "ESF" + ], + "content-length": [ + "242" + ] + }, + "body": { + "string": "{\n \"namedRanges\": [\n {\n \"namedRangeId\": \"1450817762\",\n \"name\": \"UpdatedName\",\n \"range\": {\n \"startRowIndex\": 2,\n \"endRowIndex\": 4,\n \"startColumnIndex\": 2,\n \"endColumnIndex\": 4\n }\n }\n ]\n}\n" + } + } + }, + { + "request": { + "method": "POST", + "uri": "https://sheets.googleapis.com/v4/spreadsheets/1PCM2voiOZWzwb7gctVD0bT2UvIG7EKwmBbwsKw5zC3s:batchUpdate", + "body": "{\"requests\": [{\"deleteNamedRange\": {\"namedRangeId\": \"1450817762\"}}]}", + "headers": { + "User-Agent": [ + "python-requests/2.33.1" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Accept": [ + "*/*" + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "68" + ], + "Content-Type": [ + "application/json" + ], + "authorization": [ + "" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Vary": [ + "Origin", + "X-Origin", + "Referer" + ], + "Date": [ + "Tue, 31 Mar 2026 09:27:46 GMT" + ], + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "Alt-Svc": [ + "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" + ], + "x-l2-request-path": [ + "l2-managed-6" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Transfer-Encoding": [ + "chunked" + ], + "X-XSS-Protection": [ + "0" + ], + "Server": [ + "ESF" + ], + "content-length": [ + "97" + ] + }, + "body": { + "string": "{\n \"spreadsheetId\": \"1PCM2voiOZWzwb7gctVD0bT2UvIG7EKwmBbwsKw5zC3s\",\n \"replies\": [\n {}\n ]\n}\n" + } + } + }, + { + "request": { + "method": "DELETE", + "uri": "https://www.googleapis.com/drive/v3/files/1PCM2voiOZWzwb7gctVD0bT2UvIG7EKwmBbwsKw5zC3s?supportsAllDrives=True", + "body": null, + "headers": { + "User-Agent": [ + "python-requests/2.33.1" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Accept": [ + "*/*" + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "0" + ], + "authorization": [ + "" + ] + } + }, + "response": { + "status": { + "code": 204, + "message": "No Content" + }, + "headers": { + "Vary": [ + "Origin, X-Origin" + ], + "Date": [ + "Tue, 31 Mar 2026 09:27:47 GMT" + ], + "Expires": [ + "Mon, 01 Jan 1990 00:00:00 GMT" + ], + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "Alt-Svc": [ + "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" + ], + "Pragma": [ + "no-cache" + ], + "Content-Length": [ + "0" + ], + "Cache-Control": [ + "no-cache, no-store, max-age=0, must-revalidate" + ], + "Content-Type": [ + "text/html" + ], + "X-XSS-Protection": [ + "0" + ], + "Server": [ + "ESF" + ] + }, + "body": { + "string": "" + } + } + } + ] +} diff --git a/tests/cassettes/CellTest.test_update_named_range_no_args.json b/tests/cassettes/CellTest.test_update_named_range_no_args.json new file mode 100644 index 000000000..a03e2e8bd --- /dev/null +++ b/tests/cassettes/CellTest.test_update_named_range_no_args.json @@ -0,0 +1,299 @@ +{ + "version": 1, + "interactions": [ + { + "request": { + "method": "POST", + "uri": "https://www.googleapis.com/drive/v3/files?supportsAllDrives=True", + "body": "{\"name\": \"Test CellTest test_update_named_range_no_args\", \"mimeType\": \"application/vnd.google-apps.spreadsheet\"}", + "headers": { + "User-Agent": [ + "python-requests/2.33.1" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Accept": [ + "*/*" + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "112" + ], + "Content-Type": [ + "application/json" + ], + "authorization": [ + "" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "Alt-Svc": [ + "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "Date": [ + "Tue, 31 Mar 2026 09:57:48 GMT" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Server": [ + "ESF" + ], + "Vary": [ + "Origin, X-Origin" + ], + "Expires": [ + "Mon, 01 Jan 1990 00:00:00 GMT" + ], + "Transfer-Encoding": [ + "chunked" + ], + "Cache-Control": [ + "no-cache, no-store, max-age=0, must-revalidate" + ], + "X-XSS-Protection": [ + "0" + ], + "Pragma": [ + "no-cache" + ], + "content-length": [ + "199" + ] + }, + "body": { + "string": "{\n \"kind\": \"drive#file\",\n \"id\": \"10QwUfnZCUaEjipfQkXKcvWTojMVGiC89wAzpf6ZMXzo\",\n \"name\": \"Test CellTest test_update_named_range_no_args\",\n \"mimeType\": \"application/vnd.google-apps.spreadsheet\"\n}\n" + } + } + }, + { + "request": { + "method": "GET", + "uri": "https://sheets.googleapis.com/v4/spreadsheets/10QwUfnZCUaEjipfQkXKcvWTojMVGiC89wAzpf6ZMXzo?includeGridData=false", + "body": null, + "headers": { + "User-Agent": [ + "python-requests/2.33.1" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Accept": [ + "*/*" + ], + "Connection": [ + "keep-alive" + ], + "authorization": [ + "" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "Alt-Svc": [ + "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "Date": [ + "Tue, 31 Mar 2026 09:57:49 GMT" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Vary": [ + "Origin", + "X-Origin", + "Referer" + ], + "Transfer-Encoding": [ + "chunked" + ], + "Server": [ + "ESF" + ], + "X-XSS-Protection": [ + "0" + ], + "x-l2-request-path": [ + "l2-managed-6" + ], + "content-length": [ + "3343" + ] + }, + "body": { + "string": "{\n \"spreadsheetId\": \"10QwUfnZCUaEjipfQkXKcvWTojMVGiC89wAzpf6ZMXzo\",\n \"properties\": {\n \"title\": \"Test CellTest test_update_named_range_no_args\",\n \"locale\": \"en_US\",\n \"autoRecalc\": \"ON_CHANGE\",\n \"timeZone\": \"Etc/GMT\",\n \"defaultFormat\": {\n \"backgroundColor\": {\n \"red\": 1,\n \"green\": 1,\n \"blue\": 1\n },\n \"padding\": {\n \"top\": 2,\n \"right\": 3,\n \"bottom\": 2,\n \"left\": 3\n },\n \"verticalAlignment\": \"BOTTOM\",\n \"wrapStrategy\": \"OVERFLOW_CELL\",\n \"textFormat\": {\n \"foregroundColor\": {},\n \"fontFamily\": \"arial,sans,sans-serif\",\n \"fontSize\": 10,\n \"bold\": false,\n \"italic\": false,\n \"strikethrough\": false,\n \"underline\": false,\n \"foregroundColorStyle\": {\n \"rgbColor\": {}\n }\n },\n \"backgroundColorStyle\": {\n \"rgbColor\": {\n \"red\": 1,\n \"green\": 1,\n \"blue\": 1\n }\n }\n },\n \"spreadsheetTheme\": {\n \"primaryFontFamily\": \"Arial\",\n \"themeColors\": [\n {\n \"colorType\": \"TEXT\",\n \"color\": {\n \"rgbColor\": {}\n }\n },\n {\n \"colorType\": \"BACKGROUND\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 1,\n \"green\": 1,\n \"blue\": 1\n }\n }\n },\n {\n \"colorType\": \"ACCENT1\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.25882354,\n \"green\": 0.52156866,\n \"blue\": 0.95686275\n }\n }\n },\n {\n \"colorType\": \"ACCENT2\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.91764706,\n \"green\": 0.2627451,\n \"blue\": 0.20784314\n }\n }\n },\n {\n \"colorType\": \"ACCENT3\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.9843137,\n \"green\": 0.7372549,\n \"blue\": 0.015686275\n }\n }\n },\n {\n \"colorType\": \"ACCENT4\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.20392157,\n \"green\": 0.65882355,\n \"blue\": 0.3254902\n }\n }\n },\n {\n \"colorType\": \"ACCENT5\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 1,\n \"green\": 0.42745098,\n \"blue\": 0.003921569\n }\n }\n },\n {\n \"colorType\": \"ACCENT6\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.27450982,\n \"green\": 0.7411765,\n \"blue\": 0.7764706\n }\n }\n },\n {\n \"colorType\": \"LINK\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.06666667,\n \"green\": 0.33333334,\n \"blue\": 0.8\n }\n }\n }\n ]\n }\n },\n \"sheets\": [\n {\n \"properties\": {\n \"sheetId\": 0,\n \"title\": \"Sheet1\",\n \"index\": 0,\n \"sheetType\": \"GRID\",\n \"gridProperties\": {\n \"rowCount\": 1000,\n \"columnCount\": 26\n }\n }\n }\n ],\n \"spreadsheetUrl\": \"https://docs.google.com/spreadsheets/d/10QwUfnZCUaEjipfQkXKcvWTojMVGiC89wAzpf6ZMXzo/edit\"\n}\n" + } + } + }, + { + "request": { + "method": "GET", + "uri": "https://sheets.googleapis.com/v4/spreadsheets/10QwUfnZCUaEjipfQkXKcvWTojMVGiC89wAzpf6ZMXzo?includeGridData=false", + "body": null, + "headers": { + "User-Agent": [ + "python-requests/2.33.1" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Accept": [ + "*/*" + ], + "Connection": [ + "keep-alive" + ], + "authorization": [ + "" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "Alt-Svc": [ + "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "Date": [ + "Tue, 31 Mar 2026 09:57:50 GMT" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Vary": [ + "Origin", + "X-Origin", + "Referer" + ], + "Transfer-Encoding": [ + "chunked" + ], + "Server": [ + "ESF" + ], + "X-XSS-Protection": [ + "0" + ], + "x-l2-request-path": [ + "l2-managed-6" + ], + "content-length": [ + "3343" + ] + }, + "body": { + "string": "{\n \"spreadsheetId\": \"10QwUfnZCUaEjipfQkXKcvWTojMVGiC89wAzpf6ZMXzo\",\n \"properties\": {\n \"title\": \"Test CellTest test_update_named_range_no_args\",\n \"locale\": \"en_US\",\n \"autoRecalc\": \"ON_CHANGE\",\n \"timeZone\": \"Etc/GMT\",\n \"defaultFormat\": {\n \"backgroundColor\": {\n \"red\": 1,\n \"green\": 1,\n \"blue\": 1\n },\n \"padding\": {\n \"top\": 2,\n \"right\": 3,\n \"bottom\": 2,\n \"left\": 3\n },\n \"verticalAlignment\": \"BOTTOM\",\n \"wrapStrategy\": \"OVERFLOW_CELL\",\n \"textFormat\": {\n \"foregroundColor\": {},\n \"fontFamily\": \"arial,sans,sans-serif\",\n \"fontSize\": 10,\n \"bold\": false,\n \"italic\": false,\n \"strikethrough\": false,\n \"underline\": false,\n \"foregroundColorStyle\": {\n \"rgbColor\": {}\n }\n },\n \"backgroundColorStyle\": {\n \"rgbColor\": {\n \"red\": 1,\n \"green\": 1,\n \"blue\": 1\n }\n }\n },\n \"spreadsheetTheme\": {\n \"primaryFontFamily\": \"Arial\",\n \"themeColors\": [\n {\n \"colorType\": \"TEXT\",\n \"color\": {\n \"rgbColor\": {}\n }\n },\n {\n \"colorType\": \"BACKGROUND\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 1,\n \"green\": 1,\n \"blue\": 1\n }\n }\n },\n {\n \"colorType\": \"ACCENT1\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.25882354,\n \"green\": 0.52156866,\n \"blue\": 0.95686275\n }\n }\n },\n {\n \"colorType\": \"ACCENT2\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.91764706,\n \"green\": 0.2627451,\n \"blue\": 0.20784314\n }\n }\n },\n {\n \"colorType\": \"ACCENT3\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.9843137,\n \"green\": 0.7372549,\n \"blue\": 0.015686275\n }\n }\n },\n {\n \"colorType\": \"ACCENT4\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.20392157,\n \"green\": 0.65882355,\n \"blue\": 0.3254902\n }\n }\n },\n {\n \"colorType\": \"ACCENT5\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 1,\n \"green\": 0.42745098,\n \"blue\": 0.003921569\n }\n }\n },\n {\n \"colorType\": \"ACCENT6\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.27450982,\n \"green\": 0.7411765,\n \"blue\": 0.7764706\n }\n }\n },\n {\n \"colorType\": \"LINK\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.06666667,\n \"green\": 0.33333334,\n \"blue\": 0.8\n }\n }\n }\n ]\n }\n },\n \"sheets\": [\n {\n \"properties\": {\n \"sheetId\": 0,\n \"title\": \"Sheet1\",\n \"index\": 0,\n \"sheetType\": \"GRID\",\n \"gridProperties\": {\n \"rowCount\": 1000,\n \"columnCount\": 26\n }\n }\n }\n ],\n \"spreadsheetUrl\": \"https://docs.google.com/spreadsheets/d/10QwUfnZCUaEjipfQkXKcvWTojMVGiC89wAzpf6ZMXzo/edit\"\n}\n" + } + } + }, + { + "request": { + "method": "DELETE", + "uri": "https://www.googleapis.com/drive/v3/files/10QwUfnZCUaEjipfQkXKcvWTojMVGiC89wAzpf6ZMXzo?supportsAllDrives=True", + "body": null, + "headers": { + "User-Agent": [ + "python-requests/2.33.1" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Accept": [ + "*/*" + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "0" + ], + "authorization": [ + "" + ] + } + }, + "response": { + "status": { + "code": 204, + "message": "No Content" + }, + "headers": { + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "Alt-Svc": [ + "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "Date": [ + "Tue, 31 Mar 2026 09:57:50 GMT" + ], + "Content-Type": [ + "text/html" + ], + "Server": [ + "ESF" + ], + "Vary": [ + "Origin, X-Origin" + ], + "Content-Length": [ + "0" + ], + "Expires": [ + "Mon, 01 Jan 1990 00:00:00 GMT" + ], + "Cache-Control": [ + "no-cache, no-store, max-age=0, must-revalidate" + ], + "X-XSS-Protection": [ + "0" + ], + "Pragma": [ + "no-cache" + ] + }, + "body": { + "string": "" + } + } + } + ] +}