diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index f96822ff0..af5518fe7 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -7,7 +7,7 @@ on: jobs: - build: + release: runs-on: ubuntu-latest permissions: contents: write @@ -38,7 +38,7 @@ jobs: with: user: __token__ password: ${{ secrets.TEST_PYPI_API_TOKEN }} - repository_url: https://test.pypi.org/legacy/ + repository-url: https://test.pypi.org/legacy/ - name: Publish to PyPi uses: pypa/gh-action-pypi-publish@release/v1 with: diff --git a/HISTORY.rst b/HISTORY.rst index d8b77a328..3eeb5b5e4 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -1,6 +1,16 @@ Release History =============== +5.12.0 (2023-10-22) +------------------- + +* feature -- adding `worksheet.get_records` to get specific row ranges by @AndrewBasem1 in https://github.com/burnash/gspread/pull/1301 +* Fix list_spreadsheet_files return value by @mephinet in https://github.com/burnash/gspread/pull/1308 +* Fix warning message for `worksheet.update` method by @ksj20 in https://github.com/burnash/gspread/pull/1312 +* change lambda function to dict (fix pyupgrade issue) by @alifeee in https://github.com/burnash/gspread/pull/1319 +* allows users to silence deprecation warnings by @lavigne958 in https://github.com/burnash/gspread/pull/1324 +* Add `maintain_size` to keep asked for size in `get`, `get_values` by @alifeee in https://github.com/burnash/gspread/pull/1305 + 5.11.3 (2023-09-29) ------------------- diff --git a/README.md b/README.md index f5a759cab..7a539360c 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ # Google Spreadsheets Python API v4 ![main workflow](https://img.shields.io/github/actions/workflow/status/burnash/gspread/main.yaml?logo=github) -![github license](https://img.shields.io/pypi/l/gspread?logo=github) -![latest download](https://img.shields.io/github/downloads-pre/burnash/gspread/latest/total?logo=github) +![GitHub licence](https://img.shields.io/pypi/l/gspread?logo=github) +![GitHub downloads](https://img.shields.io/github/downloads-pre/burnash/gspread/latest/total?logo=github) ![documentation](https://img.shields.io/readthedocs/gspread?logo=readthedocs) -![pypi download](https://img.shields.io/pypi/dm/gspread?logo=pypi) -![pypi version](https://img.shields.io/pypi/v/gspread?logo=pypi) +![PyPi download](https://img.shields.io/pypi/dm/gspread?logo=pypi) +![PyPi version](https://img.shields.io/pypi/v/gspread?logo=pypi) ![python version](https://img.shields.io/pypi/pyversions/gspread?style=pypi) Simple interface for working with Google Sheets. @@ -29,7 +29,7 @@ Requirements: Python 3.8+. 1. [Create credentials in Google API Console](http://gspread.readthedocs.org/en/latest/oauth2.html) -2. Start using gspread: +2. Start using gspread ```python import gspread @@ -49,6 +49,45 @@ wks.update('B42', "it's down there somewhere, let me take another look.") wks.format('A1:B1', {'textFormat': {'bold': True}}) ``` +## v5.12 to v6.0 Migration Guide + +### Upgrade from Python 3.7 + +Python 3.7 is [end-of-life](https://devguide.python.org/versions/). gspread v6 requires a minimum of Python 3.8. + +### Change `Worksheet.update` arguments + +The first two arguments (`values` & `range_name`) have swapped (to `range_name` & `values`). Either swap them (works in v6 only), or use named arguments (works in v5 & v6). + +As well, `values` can no longer be a list, and must be a 2D array. + +```diff +- file.sheet1.update(["54"], "B2") ++ file.sheet1.update(range_name="I7", values=[["54"]]) +``` + +### Change colors from dictionary to text + +v6 uses hexadecimal color representation. Change all colors to hex. You can use the compatibility function `gspread.utils.convert_colors_to_hex_value()` to convert a dictionary to a hex string. + +```diff +- tab_color = {"red": 1, "green": 0.5, "blue": 1} ++ tab_color = "#FF7FFF" +file.sheet1.update_tab_color(tab_color) +``` + +### Switch lastUpdateTime from property to method + +```diff +- age = spreadsheet.lastUpdateTime ++ age = spreadsheet.get_lastUpdateTime() +``` + +### Silence warnings + +In version 5 there are many warnings to mark deprecated feature/functions/methods. +They can be silenced by setting the `GSPREAD_SILENCE_WARNINGS` environment variable to `1` + ## More Examples ### Opening a Spreadsheet @@ -135,6 +174,22 @@ values_list = worksheet.col_values(1) list_of_lists = worksheet.get_values() ``` +### Getting a range of values + +Receive only the cells with a value in them +```python +>>> worksheet.get_values("A1:B4") +[['A1', 'B1'], ['A2']] +``` + +Receive a lists of lists matching the requested size +regardless if values are empty or not + +```python +>>> worksheet.get_values("A1:B4", maintain_size=True) +[['A1', 'B1'], ['A2', ''], ['', ''], ['', '']] +``` + ### Finding a Cell ```python diff --git a/gspread/utils.py b/gspread/utils.py index 32a5a52c6..e4a32b79f 100644 --- a/gspread/utils.py +++ b/gspread/utils.py @@ -41,6 +41,7 @@ MAGIC_NUMBER = 64 CELL_ADDR_RE = re.compile(r"([A-Za-z]+)([1-9]\d*)") A1_ADDR_ROW_COL_RE = re.compile(r"([A-Za-z]+)?([1-9]\d*)?$") +A1_ADDR_FULL_RE = re.compile(r"[A-Za-z]+\d+:[A-Za-z]+\d+") # e.g. A1:B2 not A1:B URL_KEY_V1_RE = re.compile(r"key=([^&#]+)") URL_KEY_V2_RE = re.compile(r"/spreadsheets/d/([a-zA-Z0-9-_]+)") @@ -818,6 +819,65 @@ def to_hex(value: float) -> str: return f"#{to_hex(red)}{to_hex(green)}{to_hex(blue)}" +def is_full_a1_notation(range_name: str) -> bool: + """Check if the range name is a full A1 notation. + "A1:B2", "Sheet1!A1:B2" are full A1 notations + "A1:B", "A1" are not + + Args: + range_name (str): The range name to check. + + Returns: + bool: True if the range name is a full A1 notation, False otherwise. + + Examples: + + >>> is_full_a1_notation("A1:B2") + True + + >>> is_full_a1_notation("A1:B") + False + """ + return A1_ADDR_FULL_RE.search(range_name) is not None + + +def get_a1_from_absolute_range(range_name: str) -> str: + """Get the A1 notation from an absolute range name. + "Sheet1!A1:B2" -> "A1:B2" + "A1:B2" -> "A1:B2" + + Args: + range_name (str): The range name to check. + + Returns: + str: The A1 notation of the range name stripped of the sheet. + """ + if "!" in range_name: + return range_name.split("!")[1] + return range_name + + +# SHOULD NOT BE NEEDED UNTIL NEXT MAJOR VERSION +# def deprecation_warning(version: str, msg: str) -> None: +# """Emit a deprecation warning. + +# ..note:: + +# This warning can be silenced by setting the environment variable: +# GSPREAD_SILENCE_WARNINGS=1 +# """ + +# # do not emit warning if env variable is set specifically to 1 +# if os.getenv(SILENCE_WARNINGS_ENV_KEY, "0") == "1": +# return + +# warnings.warn( +# DEPRECATION_WARNING_TEMPLATE.format(v_deprecated=version, msg_deprecated=msg), +# DeprecationWarning, +# 4, # showd the 4th stack: [1]:current->[2]:deprecation_warning->[3]:->[4]: +# ) + + if __name__ == "__main__": import doctest diff --git a/gspread/worksheet.py b/gspread/worksheet.py index d4f678136..e5a4db273 100644 --- a/gspread/worksheet.py +++ b/gspread/worksheet.py @@ -48,6 +48,8 @@ convert_hex_to_colors_dict, fill_gaps, finditem, + get_a1_from_absolute_range, + is_full_a1_notation, numericise_all, rowcol_to_a1, ) @@ -394,6 +396,7 @@ def get_values( major_dimension: Optional[Dimension] = None, value_render_option: Optional[ValueRenderOption] = None, date_time_render_option: Optional[DateTimeOption] = None, + maintain_size: bool = False, ) -> List[List[Any]]: """Returns a list of lists containing all values from specified range. @@ -470,6 +473,25 @@ def get_values( Empty trailing rows and columns will not be included. + :param bool maintain_size: (optional) Returns a matrix of values matching the size of the requested range. + + .. warning:: + + This can only work if the requested range is a complete bounded A1 notation. + Example: ``A1:D4``: OK, ``C3:F``: Not OK, we don't know the end size of the requested range. + + This does not work with ``named_range`` either. + + Examples:: + + # Works + >>> worksheet.get("A1:B2", maintain_size=True) + [['A1', 'B1'], ['A2', '']] + + # Does NOT maintain the requested size + >>> worksheet.get("A1:B", maintain_size=True) + [['A1', 'B1'], ['A2'], [], ['A4', 'B4'], ['A5']] + Examples:: # Return all values from the sheet @@ -497,6 +519,7 @@ def get_values( major_dimension=major_dimension, value_render_option=value_render_option, date_time_render_option=date_time_render_option, + maintain_size=maintain_size, ) ) if combine_merged_cells is True: @@ -954,6 +977,7 @@ def get( major_dimension: Optional[Dimension] = None, value_render_option: Optional[ValueRenderOption] = None, date_time_render_option: Optional[DateTimeOption] = None, + maintain_size: bool = False, ) -> ValueRange: """Reads values of a single range or a cell of a sheet. @@ -1042,6 +1066,19 @@ def get( self.spreadsheet_id, range_name, params=params ) + values = response.get("values", []) + + # range_name must be a full grid range so that we can guarantee + # startRowIndex and endRowIndex properties + if maintain_size is True and is_full_a1_notation(range_name): + a1_range = get_a1_from_absolute_range(range_name) + grid_range = a1_range_to_grid_range(a1_range) + rows = grid_range["endRowIndex"] - grid_range["startRowIndex"] + cols = grid_range["endColumnIndex"] - grid_range["startColumnIndex"] + values = fill_gaps(values, rows=rows, cols=cols) + + response["values"] = values + return ValueRange.from_json(response) def batch_get( diff --git a/tests/cassettes/WorksheetTest.test_get_values_and_maintain_size.json b/tests/cassettes/WorksheetTest.test_get_values_and_maintain_size.json new file mode 100644 index 000000000..35828dbd6 --- /dev/null +++ b/tests/cassettes/WorksheetTest.test_get_values_and_maintain_size.json @@ -0,0 +1,597 @@ +{ + "version": 1, + "interactions": [ + { + "request": { + "method": "POST", + "uri": "https://www.googleapis.com/drive/v3/files?supportsAllDrives=True", + "body": "{\"name\": \"Test WorksheetTest test_get_values_and_maintain_size\", \"mimeType\": \"application/vnd.google-apps.spreadsheet\"}", + "headers": { + "User-Agent": [ + "python-requests/2.31.0" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Accept": [ + "*/*" + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "119" + ], + "Content-Type": [ + "application/json" + ], + "authorization": [ + "" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Vary": [ + "Origin, X-Origin" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "Expires": [ + "Mon, 01 Jan 1990 00:00:00 GMT" + ], + "Pragma": [ + "no-cache" + ], + "Server": [ + "ESF" + ], + "Cache-Control": [ + "no-cache, no-store, max-age=0, must-revalidate" + ], + "Date": [ + "Sat, 28 Oct 2023 11:31:13 GMT" + ], + "Alt-Svc": [ + "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" + ], + "X-XSS-Protection": [ + "0" + ], + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Transfer-Encoding": [ + "chunked" + ], + "content-length": [ + "206" + ] + }, + "body": { + "string": "{\n \"kind\": \"drive#file\",\n \"id\": \"1Tn0-7iJtUVsziRcJ_CwZrokLZNNBsGb0rukA4vKtOW8\",\n \"name\": \"Test WorksheetTest test_get_values_and_maintain_size\",\n \"mimeType\": \"application/vnd.google-apps.spreadsheet\"\n}\n" + } + } + }, + { + "request": { + "method": "GET", + "uri": "https://sheets.googleapis.com/v4/spreadsheets/1Tn0-7iJtUVsziRcJ_CwZrokLZNNBsGb0rukA4vKtOW8?includeGridData=false", + "body": null, + "headers": { + "User-Agent": [ + "python-requests/2.31.0" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Accept": [ + "*/*" + ], + "Connection": [ + "keep-alive" + ], + "authorization": [ + "" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Vary": [ + "Origin", + "X-Origin", + "Referer" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "Server": [ + "ESF" + ], + "Cache-Control": [ + "private" + ], + "Date": [ + "Sat, 28 Oct 2023 11:31:14 GMT" + ], + "Alt-Svc": [ + "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" + ], + "X-XSS-Protection": [ + "0" + ], + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Transfer-Encoding": [ + "chunked" + ], + "content-length": [ + "3350" + ] + }, + "body": { + "string": "{\n \"spreadsheetId\": \"1Tn0-7iJtUVsziRcJ_CwZrokLZNNBsGb0rukA4vKtOW8\",\n \"properties\": {\n \"title\": \"Test WorksheetTest test_get_values_and_maintain_size\",\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/1Tn0-7iJtUVsziRcJ_CwZrokLZNNBsGb0rukA4vKtOW8/edit\"\n}\n" + } + } + }, + { + "request": { + "method": "GET", + "uri": "https://sheets.googleapis.com/v4/spreadsheets/1Tn0-7iJtUVsziRcJ_CwZrokLZNNBsGb0rukA4vKtOW8?includeGridData=false", + "body": null, + "headers": { + "User-Agent": [ + "python-requests/2.31.0" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Accept": [ + "*/*" + ], + "Connection": [ + "keep-alive" + ], + "authorization": [ + "" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Vary": [ + "Origin", + "X-Origin", + "Referer" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "Server": [ + "ESF" + ], + "Cache-Control": [ + "private" + ], + "Date": [ + "Sat, 28 Oct 2023 11:31:14 GMT" + ], + "Alt-Svc": [ + "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" + ], + "X-XSS-Protection": [ + "0" + ], + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Transfer-Encoding": [ + "chunked" + ], + "content-length": [ + "3350" + ] + }, + "body": { + "string": "{\n \"spreadsheetId\": \"1Tn0-7iJtUVsziRcJ_CwZrokLZNNBsGb0rukA4vKtOW8\",\n \"properties\": {\n \"title\": \"Test WorksheetTest test_get_values_and_maintain_size\",\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/1Tn0-7iJtUVsziRcJ_CwZrokLZNNBsGb0rukA4vKtOW8/edit\"\n}\n" + } + } + }, + { + "request": { + "method": "POST", + "uri": "https://sheets.googleapis.com/v4/spreadsheets/1Tn0-7iJtUVsziRcJ_CwZrokLZNNBsGb0rukA4vKtOW8/values/%27Sheet1%27:clear", + "body": null, + "headers": { + "User-Agent": [ + "python-requests/2.31.0" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Accept": [ + "*/*" + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "0" + ], + "authorization": [ + "" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Vary": [ + "Origin", + "X-Origin", + "Referer" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "Server": [ + "ESF" + ], + "Cache-Control": [ + "private" + ], + "Date": [ + "Sat, 28 Oct 2023 11:31:14 GMT" + ], + "Alt-Svc": [ + "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" + ], + "X-XSS-Protection": [ + "0" + ], + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Transfer-Encoding": [ + "chunked" + ], + "content-length": [ + "107" + ] + }, + "body": { + "string": "{\n \"spreadsheetId\": \"1Tn0-7iJtUVsziRcJ_CwZrokLZNNBsGb0rukA4vKtOW8\",\n \"clearedRange\": \"Sheet1!A1:Z1000\"\n}\n" + } + } + }, + { + "request": { + "method": "POST", + "uri": "https://sheets.googleapis.com/v4/spreadsheets/1Tn0-7iJtUVsziRcJ_CwZrokLZNNBsGb0rukA4vKtOW8:batchUpdate", + "body": "{\"requests\": [{\"updateSheetProperties\": {\"properties\": {\"sheetId\": 0, \"gridProperties\": {\"rowCount\": 5, \"columnCount\": 5}}, \"fields\": \"gridProperties/rowCount,gridProperties/columnCount\"}}]}", + "headers": { + "User-Agent": [ + "python-requests/2.31.0" + ], + "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" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "x-l2-request-path": [ + "l2-managed-6" + ], + "Server": [ + "ESF" + ], + "Cache-Control": [ + "private" + ], + "Date": [ + "Sat, 28 Oct 2023 11:31:15 GMT" + ], + "Alt-Svc": [ + "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" + ], + "X-XSS-Protection": [ + "0" + ], + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Transfer-Encoding": [ + "chunked" + ], + "content-length": [ + "97" + ] + }, + "body": { + "string": "{\n \"spreadsheetId\": \"1Tn0-7iJtUVsziRcJ_CwZrokLZNNBsGb0rukA4vKtOW8\",\n \"replies\": [\n {}\n ]\n}\n" + } + } + }, + { + "request": { + "method": "PUT", + "uri": "https://sheets.googleapis.com/v4/spreadsheets/1Tn0-7iJtUVsziRcJ_CwZrokLZNNBsGb0rukA4vKtOW8/values/%27Sheet1%27%21A1%3AE5?valueInputOption=RAW", + "body": "{\"values\": [[\"1\", \"2\", \"\", \"\", \"\"], [\"3\", \"4\", \"\", \"\", \"\"], [\"5\", \"6\", \"\", \"\", \"\"], [\"\", \"\", \"\", \"\", \"\"], [\"\", \"\", \"\", \"\", \"\"]], \"majorDimension\": null}", + "headers": { + "User-Agent": [ + "python-requests/2.31.0" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Accept": [ + "*/*" + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "152" + ], + "Content-Type": [ + "application/json" + ], + "authorization": [ + "" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Vary": [ + "Origin", + "X-Origin", + "Referer" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "Server": [ + "ESF" + ], + "Cache-Control": [ + "private" + ], + "Date": [ + "Sat, 28 Oct 2023 11:31:15 GMT" + ], + "Alt-Svc": [ + "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" + ], + "X-XSS-Protection": [ + "0" + ], + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Transfer-Encoding": [ + "chunked" + ], + "content-length": [ + "169" + ] + }, + "body": { + "string": "{\n \"spreadsheetId\": \"1Tn0-7iJtUVsziRcJ_CwZrokLZNNBsGb0rukA4vKtOW8\",\n \"updatedRange\": \"Sheet1!A1:E5\",\n \"updatedRows\": 5,\n \"updatedColumns\": 5,\n \"updatedCells\": 25\n}\n" + } + } + }, + { + "request": { + "method": "GET", + "uri": "https://sheets.googleapis.com/v4/spreadsheets/1Tn0-7iJtUVsziRcJ_CwZrokLZNNBsGb0rukA4vKtOW8/values/%27Sheet1%27%21A1%3AD4", + "body": null, + "headers": { + "User-Agent": [ + "python-requests/2.31.0" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Accept": [ + "*/*" + ], + "Connection": [ + "keep-alive" + ], + "authorization": [ + "" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Vary": [ + "Origin", + "X-Origin", + "Referer" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "Server": [ + "ESF" + ], + "Cache-Control": [ + "private" + ], + "Date": [ + "Sat, 28 Oct 2023 11:31:15 GMT" + ], + "Alt-Svc": [ + "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" + ], + "X-XSS-Protection": [ + "0" + ], + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Transfer-Encoding": [ + "chunked" + ], + "content-length": [ + "178" + ] + }, + "body": { + "string": "{\n \"range\": \"Sheet1!A1:D4\",\n \"majorDimension\": \"ROWS\",\n \"values\": [\n [\n \"1\",\n \"2\"\n ],\n [\n \"3\",\n \"4\"\n ],\n [\n \"5\",\n \"6\"\n ]\n ]\n}\n" + } + } + }, + { + "request": { + "method": "DELETE", + "uri": "https://www.googleapis.com/drive/v3/files/1Tn0-7iJtUVsziRcJ_CwZrokLZNNBsGb0rukA4vKtOW8?supportsAllDrives=True", + "body": null, + "headers": { + "User-Agent": [ + "python-requests/2.31.0" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Accept": [ + "*/*" + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "0" + ], + "authorization": [ + "" + ] + } + }, + "response": { + "status": { + "code": 204, + "message": "No Content" + }, + "headers": { + "Vary": [ + "Origin, X-Origin" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "Expires": [ + "Mon, 01 Jan 1990 00:00:00 GMT" + ], + "Pragma": [ + "no-cache" + ], + "Server": [ + "ESF" + ], + "Content-Length": [ + "0" + ], + "Cache-Control": [ + "no-cache, no-store, max-age=0, must-revalidate" + ], + "Date": [ + "Sat, 28 Oct 2023 11:31:16 GMT" + ], + "Alt-Svc": [ + "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" + ], + "X-XSS-Protection": [ + "0" + ], + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "Content-Type": [ + "text/html" + ] + }, + "body": { + "string": "" + } + } + } + ] +} diff --git a/tests/cassettes/WorksheetTest.test_update_acell.json b/tests/cassettes/WorksheetTest.test_update_acell.json index 643474460..748b9bf00 100644 --- a/tests/cassettes/WorksheetTest.test_update_acell.json +++ b/tests/cassettes/WorksheetTest.test_update_acell.json @@ -1154,6 +1154,534 @@ "string": "" } } + }, + { + "request": { + "method": "POST", + "uri": "https://www.googleapis.com/drive/v3/files?supportsAllDrives=True", + "body": "{\"name\": \"Test WorksheetTest test_update_acell\", \"mimeType\": \"application/vnd.google-apps.spreadsheet\"}", + "headers": { + "User-Agent": [ + "python-requests/2.31.0" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Accept": [ + "*/*" + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "103" + ], + "Content-Type": [ + "application/json" + ], + "authorization": [ + "" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Expires": [ + "Mon, 01 Jan 1990 00:00:00 GMT" + ], + "Server": [ + "ESF" + ], + "Cache-Control": [ + "no-cache, no-store, max-age=0, must-revalidate" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Date": [ + "Thu, 28 Sep 2023 22:04:11 GMT" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "Pragma": [ + "no-cache" + ], + "Transfer-Encoding": [ + "chunked" + ], + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "Alt-Svc": [ + "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" + ], + "Vary": [ + "Origin, X-Origin" + ], + "X-XSS-Protection": [ + "0" + ], + "content-length": [ + "190" + ] + }, + "body": { + "string": "{\n \"kind\": \"drive#file\",\n \"id\": \"1kTy39ZPF4F8obHLb3mLWKeBbdeFNOH6ckIdCASAHfPo\",\n \"name\": \"Test WorksheetTest test_update_acell\",\n \"mimeType\": \"application/vnd.google-apps.spreadsheet\"\n}\n" + } + } + }, + { + "request": { + "method": "GET", + "uri": "https://sheets.googleapis.com/v4/spreadsheets/1kTy39ZPF4F8obHLb3mLWKeBbdeFNOH6ckIdCASAHfPo?includeGridData=false", + "body": null, + "headers": { + "User-Agent": [ + "python-requests/2.31.0" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Accept": [ + "*/*" + ], + "Connection": [ + "keep-alive" + ], + "authorization": [ + "" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Server": [ + "ESF" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Cache-Control": [ + "private" + ], + "Date": [ + "Thu, 28 Sep 2023 22:04:12 GMT" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "Transfer-Encoding": [ + "chunked" + ], + "x-l2-request-path": [ + "l2-managed-6" + ], + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "Alt-Svc": [ + "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" + ], + "Vary": [ + "Origin", + "X-Origin", + "Referer" + ], + "X-XSS-Protection": [ + "0" + ], + "content-length": [ + "3334" + ] + }, + "body": { + "string": "{\n \"spreadsheetId\": \"1kTy39ZPF4F8obHLb3mLWKeBbdeFNOH6ckIdCASAHfPo\",\n \"properties\": {\n \"title\": \"Test WorksheetTest test_update_acell\",\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/1kTy39ZPF4F8obHLb3mLWKeBbdeFNOH6ckIdCASAHfPo/edit\"\n}\n" + } + } + }, + { + "request": { + "method": "GET", + "uri": "https://sheets.googleapis.com/v4/spreadsheets/1kTy39ZPF4F8obHLb3mLWKeBbdeFNOH6ckIdCASAHfPo?includeGridData=false", + "body": null, + "headers": { + "User-Agent": [ + "python-requests/2.31.0" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Accept": [ + "*/*" + ], + "Connection": [ + "keep-alive" + ], + "authorization": [ + "" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Server": [ + "ESF" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Cache-Control": [ + "private" + ], + "Date": [ + "Thu, 28 Sep 2023 22:04:12 GMT" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "Transfer-Encoding": [ + "chunked" + ], + "x-l2-request-path": [ + "l2-managed-6" + ], + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "Alt-Svc": [ + "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" + ], + "Vary": [ + "Origin", + "X-Origin", + "Referer" + ], + "X-XSS-Protection": [ + "0" + ], + "content-length": [ + "3334" + ] + }, + "body": { + "string": "{\n \"spreadsheetId\": \"1kTy39ZPF4F8obHLb3mLWKeBbdeFNOH6ckIdCASAHfPo\",\n \"properties\": {\n \"title\": \"Test WorksheetTest test_update_acell\",\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/1kTy39ZPF4F8obHLb3mLWKeBbdeFNOH6ckIdCASAHfPo/edit\"\n}\n" + } + } + }, + { + "request": { + "method": "POST", + "uri": "https://sheets.googleapis.com/v4/spreadsheets/1kTy39ZPF4F8obHLb3mLWKeBbdeFNOH6ckIdCASAHfPo/values/%27Sheet1%27:clear", + "body": null, + "headers": { + "User-Agent": [ + "python-requests/2.31.0" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Accept": [ + "*/*" + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "0" + ], + "authorization": [ + "" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Server": [ + "ESF" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Cache-Control": [ + "private" + ], + "Date": [ + "Thu, 28 Sep 2023 22:04:13 GMT" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "Transfer-Encoding": [ + "chunked" + ], + "x-l2-request-path": [ + "l2-managed-6" + ], + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "Alt-Svc": [ + "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" + ], + "Vary": [ + "Origin", + "X-Origin", + "Referer" + ], + "X-XSS-Protection": [ + "0" + ], + "content-length": [ + "107" + ] + }, + "body": { + "string": "{\n \"spreadsheetId\": \"1kTy39ZPF4F8obHLb3mLWKeBbdeFNOH6ckIdCASAHfPo\",\n \"clearedRange\": \"Sheet1!A1:Z1000\"\n}\n" + } + } + }, + { + "request": { + "method": "PUT", + "uri": "https://sheets.googleapis.com/v4/spreadsheets/1kTy39ZPF4F8obHLb3mLWKeBbdeFNOH6ckIdCASAHfPo/values/%27Sheet1%27%21A2?valueInputOption=USER_ENTERED", + "body": "{\"values\": [[\"test_update_acell 1\"]]}", + "headers": { + "User-Agent": [ + "python-requests/2.31.0" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Accept": [ + "*/*" + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "37" + ], + "Content-Type": [ + "application/json" + ], + "authorization": [ + "" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Server": [ + "ESF" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Cache-Control": [ + "private" + ], + "Date": [ + "Thu, 28 Sep 2023 22:04:13 GMT" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "Transfer-Encoding": [ + "chunked" + ], + "x-l2-request-path": [ + "l2-managed-6" + ], + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "Alt-Svc": [ + "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" + ], + "Vary": [ + "Origin", + "X-Origin", + "Referer" + ], + "X-XSS-Protection": [ + "0" + ], + "content-length": [ + "165" + ] + }, + "body": { + "string": "{\n \"spreadsheetId\": \"1kTy39ZPF4F8obHLb3mLWKeBbdeFNOH6ckIdCASAHfPo\",\n \"updatedRange\": \"Sheet1!A2\",\n \"updatedRows\": 1,\n \"updatedColumns\": 1,\n \"updatedCells\": 1\n}\n" + } + } + }, + { + "request": { + "method": "GET", + "uri": "https://sheets.googleapis.com/v4/spreadsheets/1kTy39ZPF4F8obHLb3mLWKeBbdeFNOH6ckIdCASAHfPo/values/%27Sheet1%27%21A2?valueRenderOption=FORMATTED_VALUE", + "body": null, + "headers": { + "User-Agent": [ + "python-requests/2.31.0" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Accept": [ + "*/*" + ], + "Connection": [ + "keep-alive" + ], + "authorization": [ + "" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Server": [ + "ESF" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Cache-Control": [ + "private" + ], + "Date": [ + "Thu, 28 Sep 2023 22:04:13 GMT" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "Transfer-Encoding": [ + "chunked" + ], + "x-l2-request-path": [ + "l2-managed-6" + ], + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "Alt-Svc": [ + "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" + ], + "Vary": [ + "Origin", + "X-Origin", + "Referer" + ], + "X-XSS-Protection": [ + "0" + ], + "content-length": [ + "114" + ] + }, + "body": { + "string": "{\n \"range\": \"Sheet1!A2\",\n \"majorDimension\": \"ROWS\",\n \"values\": [\n [\n \"test_update_acell 1\"\n ]\n ]\n}\n" + } + } + }, + { + "request": { + "method": "DELETE", + "uri": "https://www.googleapis.com/drive/v3/files/1kTy39ZPF4F8obHLb3mLWKeBbdeFNOH6ckIdCASAHfPo?supportsAllDrives=True", + "body": null, + "headers": { + "User-Agent": [ + "python-requests/2.31.0" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Accept": [ + "*/*" + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "0" + ], + "authorization": [ + "" + ] + } + }, + "response": { + "status": { + "code": 204, + "message": "No Content" + }, + "headers": { + "Expires": [ + "Mon, 01 Jan 1990 00:00:00 GMT" + ], + "Server": [ + "ESF" + ], + "Cache-Control": [ + "no-cache, no-store, max-age=0, must-revalidate" + ], + "Content-Type": [ + "text/html" + ], + "Date": [ + "Thu, 28 Sep 2023 22:04:14 GMT" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "Content-Length": [ + "0" + ], + "Pragma": [ + "no-cache" + ], + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "Alt-Svc": [ + "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" + ], + "Vary": [ + "Origin, X-Origin" + ], + "X-XSS-Protection": [ + "0" + ] + }, + "body": { + "string": "" + } + } } ] } diff --git a/tests/utils_test.py b/tests/utils_test.py index ca079a4a8..b077b4e0c 100644 --- a/tests/utils_test.py +++ b/tests/utils_test.py @@ -374,3 +374,28 @@ def test_fill_gaps_with_value(self): actual = utils.fill_gaps(matrix, 3, 6, 3) self.assertEqual(actual, expected) + + def test_is_full_a1_notation(self): + """test is_full_a1_notation function""" + self.assertTrue(utils.is_full_a1_notation("A1:B2")) + self.assertTrue(utils.is_full_a1_notation("Sheet1!A1:B2")) + self.assertTrue(utils.is_full_a1_notation("AZ1:BBY2")) + self.assertTrue(utils.is_full_a1_notation("AZ142:BBY122")) + + self.assertFalse(utils.is_full_a1_notation("Sheet1")) + self.assertFalse(utils.is_full_a1_notation("A:B")) + self.assertFalse(utils.is_full_a1_notation("1:2")) + self.assertFalse(utils.is_full_a1_notation("1:")) + self.assertFalse(utils.is_full_a1_notation("A1")) + self.assertFalse(utils.is_full_a1_notation("A")) + self.assertFalse(utils.is_full_a1_notation("1")) + self.assertFalse(utils.is_full_a1_notation("")) + + def test_get_a1_from_absolute_range(self): + """test get_a1_from_absolute_range function""" + self.assertEqual(utils.get_a1_from_absolute_range("'Sheet1'!A1:B2"), "A1:B2") + self.assertEqual(utils.get_a1_from_absolute_range("'Sheet1'!A1:B"), "A1:B") + self.assertEqual(utils.get_a1_from_absolute_range("Sheet1!A1:B2"), "A1:B2") + self.assertEqual(utils.get_a1_from_absolute_range("A1:B2"), "A1:B2") + self.assertEqual(utils.get_a1_from_absolute_range("A1:B"), "A1:B") + self.assertEqual(utils.get_a1_from_absolute_range("2"), "2") diff --git a/tests/worksheet_test.py b/tests/worksheet_test.py index 4b0925d9c..67ccf0bfe 100644 --- a/tests/worksheet_test.py +++ b/tests/worksheet_test.py @@ -171,6 +171,31 @@ def test_get_values_merge_cells_outside_of_range(self): ) self.assertEqual(values_with_merged, expected_values) + @pytest.mark.vcr() + def test_get_values_and_maintain_size(self): + """test get_values with maintain_size=True""" + self.sheet.resize(5, 5) + sheet_data = [ + ["1", "2", "", "", ""], + ["3", "4", "", "", ""], + ["5", "6", "", "", ""], + ["", "", "", "", ""], + ["", "", "", "", ""], + ] + request_range = "A1:D4" + expected_values = [ + ["1", "2", "", ""], + ["3", "4", "", ""], + ["5", "6", "", ""], + ["", "", "", ""], + ] + + self.sheet.update(sheet_data, "A1:E5") + + values = self.sheet.get_values(request_range, maintain_size=True) + + self.assertEqual(values, expected_values) + @pytest.mark.vcr() def test_update_acell(self): sg = self._sequence_generator()