Hi I want to unit test the below code by mocking the api calls .
def get_data_from_google_sheets(spreadsheet_id, google_creds):
"""
Pupose:
"""
scopes = ['https://www.googleapis.com/auth/sqlservice.admin','https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
range_name = 'A1:AA1000'
credentials = service_account.Credentials.from_service_account_info(google_creds, scopes = scopes)
service = build('sheets', 'v4', credentials = credentials)
sheet = service.spreadsheets()
result_from_sheet = sheet.values().get(spreadsheetId = spreadsheet_id,range = range_name).execute()
rows = result_from_sheet['values'][1:]
return rows
I have tried using the below code
def test_get_data(mocker):
sheet_id = "123"
creds = {"b":"d"}
mocker.patch.object(
google.oauth2.service_account.Credentials,'from_service_account_info',
return_value = ""
)
mocker.patch.object(
googleapiclient.discovery.build.return_value.spreadsheets.return_value.values.return_value.get.return_value,'execute',
return_value = []
)
result = get_data_from_google_sheets(sheet_id, creds)
assert len(result) == 0
Getting error - AttributeError: 'function' object has no attribute 'return_value'