1
0
mirror of synced 2026-01-05 03:04:38 -05:00
Files
airbyte/airbyte-integrations/connectors/source-google-sheets/unit_tests/test_stream.py
Artem Inzhyyants 0eefa33bcb Source Google Sheets: handle config errors (#26097)
* Source Google Sheets: handle config errors

* Source Google Sheets: update docs

* Source Google Sheets: fix test

* Source Google Sheets: add unit tests

* auto-bump connector version

* Automated Change

---------

Co-authored-by: Octavia Squidington III <octavia-squidington-iii@users.noreply.github.com>
Co-authored-by: artem1205 <artem1205@users.noreply.github.com>
2023-05-17 00:14:26 +02:00

31 lines
1.3 KiB
Python

#
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
#
import pytest
import requests
from airbyte_cdk.utils import AirbyteTracedException
from apiclient import errors
from source_google_sheets import SourceGoogleSheets
from source_google_sheets.client import GoogleSheetsClient
from source_google_sheets.helpers import SCOPES
def test_invalid_credentials_error_message(invalid_config):
source = SourceGoogleSheets()
with pytest.raises(AirbyteTracedException) as e:
source.check(logger=None, config=invalid_config)
assert e.value.args[0] == 'Access to the spreadsheet expired or was revoked. Re-authenticate to restore access.'
def test_invalid_link_error_message(mocker, invalid_config):
source = SourceGoogleSheets()
resp = requests.Response()
resp.status = 404
mocker.patch.object(GoogleSheetsClient, "__init__", lambda s, credentials, scopes=SCOPES: None)
mocker.patch.object(GoogleSheetsClient, "get", side_effect=errors.HttpError(resp=resp, content=b''))
with pytest.raises(AirbyteTracedException) as e:
source.check(logger=None, config=invalid_config)
expected_message = 'Config error: The spreadsheet link is not valid. Enter the URL of the Google spreadsheet you want to sync.'
assert e.value.args[0] == expected_message