Модульное тестирование Python Google Sheet
Как мне протестировать эту часть кода?:
creds = Credentials.from_service_account_info(
json.loads(json.loads(creds_service_account)), scopes=scope
)
class GoogleSheet:
def __init__(
self
):
self.authenticate()
def authenticate(self):
scope = [
"https://spreadsheets.google.com/feeds",
"https://www.googleapis.com/auth/drive",
]
# b64 decode, then utf decode, then jsonload. Super straightforward
decoded = base64.b64decode(settings.PAYMENT_GOOGLE_SHEET_CREDS)
creds_service_account = decoded.decode("utf8")
creds = Credentials.from_service_account_info(
json.loads(json.loads(creds_service_account)), scopes=scope
)
client = gspread.authorize(creds)
# self.sheet = client.open(GOOGLE_SHEET_TITLE).sheet1
self.sheet = client.open(GOOGLE_SHEET_TITLE).worksheet(
GOOGLE_SHEET_WORKSHEET_NAME
)
Я попробовал это, но, возможно, я сбился с пути, так как это не работает, он все еще хочет правильный json.loads(json.loads(creds_service_account)), scopes=scope:
with patch('google.oauth2.service_account.Credentials.from_service_account_info', new=Mock(return_value=True)):