def mock_client_call(spreadsheetId, includeGridData, ranges=None): if spreadsheetId != spreadsheet_id: return None # the spreadsheet only contains sheet1 elif not includeGridData and ranges is None: mocked_return = Spreadsheet( spreadsheetId=spreadsheet_id, sheets=[Sheet(properties=SheetProperties(title=sheet1))]) elif includeGridData and ranges == f"{sheet1}!1:1": mocked_return = Spreadsheet( spreadsheetId=spreadsheet_id, sheets=[ Sheet(data=[ GridData(rowData=[ RowData(values=[ CellData(formattedValue=v) for v in sheet1_first_row ]) ]) ]) ], ) m = Mock() m.execute.return_value = mocked_return return m
def test_get_sheets_in_spreadsheet(self): spreadsheet_id = "id1" expected_sheets = ["s1", "s2"] client = Mock() client.get.return_value.execute.return_value = Spreadsheet( spreadsheetId=spreadsheet_id, sheets=[Sheet(properties=SheetProperties(title=t)) for t in expected_sheets] ) with patch.object(GoogleSheetsClient, "__init__", lambda s, credentials, scopes: None): sheet_client = GoogleSheetsClient({"fake": "credentials"}, ["auth_scopes"]) sheet_client.client = client actual_sheets = Helpers.get_sheets_in_spreadsheet(sheet_client, spreadsheet_id) self.assertEqual(expected_sheets, actual_sheets) client.get.assert_called_with(spreadsheetId=spreadsheet_id, includeGridData=False)
def test_get_sheets_in_spreadsheet(self): spreadsheet_id = "id1" expected_sheets = ["s1", "s2"] client = Mock() client.get.return_value.execute.return_value = Spreadsheet( spreadsheetId=spreadsheet_id, sheets=[ Sheet(properties=SheetProperties(title=t)) for t in expected_sheets ]) actual_sheets = Helpers.get_sheets_in_spreadsheet( client, spreadsheet_id) self.assertEqual(expected_sheets, actual_sheets) client.get.assert_called_with(spreadsheetId=spreadsheet_id, includeGridData=False)