33 lines
1.2 KiB
Python
33 lines
1.2 KiB
Python
#
|
|
# Copyright (c) 2022 Airbyte, Inc., all rights reserved.
|
|
#
|
|
|
|
from unittest.mock import MagicMock
|
|
|
|
import pytest
|
|
import requests
|
|
from airbyte_cdk.logger import AirbyteLogger
|
|
from source_sendgrid.source import SourceSendgrid
|
|
from source_sendgrid.streams import SendgridStream
|
|
|
|
|
|
@pytest.fixture(name="sendgrid_stream")
|
|
def sendgrid_stream_fixture(mocker) -> SendgridStream:
|
|
# Wipe the internal list of abstract methods to allow instantiating the abstract class without implementing its abstract methods
|
|
mocker.patch("source_sendgrid.streams.SendgridStream.__abstractmethods__", set())
|
|
# Mypy yells at us because we're init'ing an abstract class
|
|
return SendgridStream() # type: ignore
|
|
|
|
|
|
def test_parse_response_gracefully_handles_nulls(mocker, sendgrid_stream: SendgridStream):
|
|
response = requests.Response()
|
|
mocker.patch.object(response, "json", return_value=None)
|
|
mocker.patch.object(response, "request", return_value=MagicMock())
|
|
assert [] == list(sendgrid_stream.parse_response(response))
|
|
|
|
|
|
def test_source_wrong_credentials():
|
|
source = SourceSendgrid()
|
|
status, error = source.check_connection(logger=AirbyteLogger(), config={"apikey": "wrong.api.key123"})
|
|
assert not status
|