From da707bf6fc2ead452f1ab5b66e01999c719e8877 Mon Sep 17 00:00:00 2001 From: Robert Jambrecic Date: Wed, 26 Jun 2024 15:41:30 +0200 Subject: [PATCH] Update tests --- google_sheets/app.py | 6 ++-- tests/app/test_app.py | 65 +++++++++++++++++++++++++++++++++++++++---- 2 files changed, 63 insertions(+), 8 deletions(-) diff --git a/google_sheets/app.py b/google_sheets/app.py index c5b407c..2088496 100644 --- a/google_sheets/app.py +++ b/google_sheets/app.py @@ -131,14 +131,14 @@ async def get_sheet( spreadsheet_id: Annotated[ str, Query(description="ID of the Google Sheet to fetch data from") ], - range: Annotated[ + title: Annotated[ str, - Query(description="The range of cells to fetch data from. E.g. 'Sheet1!A1:B2'"), + Query(description="The title of the sheet to fetch data from"), ], ) -> Union[str, List[List[str]]]: service = await build_service(user_id=user_id, service_name="sheets", version="v4") values = await get_sheet_f( - service=service, spreadsheet_id=spreadsheet_id, range=range + service=service, spreadsheet_id=spreadsheet_id, range=title ) if not values: diff --git a/tests/app/test_app.py b/tests/app/test_app.py index 268e2ea..96d982c 100644 --- a/tests/app/test_app.py +++ b/tests/app/test_app.py @@ -27,7 +27,7 @@ def test_get_sheet(self) -> None: "google_sheets.app.get_sheet_f", return_value=excepted ) as mock_get_sheet: response = client.get( - "/get-sheet?user_id=123&spreadsheet_id=abc&range=Sheet1" + "/get-sheet?user_id=123&spreadsheet_id=abc&title=Sheet1" ) mock_load_user_credentials.assert_called_once() mock_get_sheet.assert_called_once() @@ -308,15 +308,15 @@ def test_openapi(self) -> None: "description": "ID of the Google Sheet to fetch data from", }, { - "name": "range", + "name": "title", "in": "query", "required": True, "schema": { "type": "string", - "description": "The range of cells to fetch data from. E.g. 'Sheet1!A1:B2'", - "title": "Range", + "description": "The title of the sheet to fetch data from", + "title": "Title", }, - "description": "The range of cells to fetch data from. E.g. 'Sheet1!A1:B2'", + "description": "The title of the sheet to fetch data from", }, ], "responses": { @@ -523,6 +523,61 @@ def test_openapi(self) -> None: }, } }, + "/get-all-sheet-titles": { + "get": { + "summary": "Get All Sheet Titles", + "description": "Get all sheet titles within a Google Spreadsheet", + "operationId": "get_all_sheet_titles_get_all_sheet_titles_get", + "parameters": [ + { + "name": "user_id", + "in": "query", + "required": True, + "schema": { + "type": "integer", + "description": "The user ID for which the data is requested", + "title": "User Id", + }, + "description": "The user ID for which the data is requested", + }, + { + "name": "spreadsheet_id", + "in": "query", + "required": True, + "schema": { + "type": "string", + "description": "ID of the Google Sheet to fetch data from", + "title": "Spreadsheet Id", + }, + "description": "ID of the Google Sheet to fetch data from", + }, + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": {"type": "string"}, + "title": "Response Get All Sheet Titles Get All Sheet Titles Get", + } + } + }, + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + }, + }, + }, + } + }, }, "components": { "schemas": {