Skip to content

Commit 8e03c85

Browse files
Source FreshDesk: fix unittests
1 parent e4ef4bd commit 8e03c85

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

airbyte-integrations/connectors/source-freshdesk/source_freshdesk/source.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import logging
66
from typing import Any, List, Mapping, Optional, Tuple
77

8+
import requests
89
from airbyte_cdk.sources import AbstractSource
910
from airbyte_cdk.sources.streams import Stream
1011
from requests.auth import HTTPBasicAuth
@@ -55,8 +56,16 @@ def _get_stream_kwargs(config: Mapping[str, Any]) -> dict:
5556
return {"authenticator": FreshdeskAuth(config["api_key"]), "config": config}
5657

5758
def check_connection(self, logger: logging.Logger, config: Mapping[str, Any]) -> Tuple[bool, Optional[Any]]:
58-
stream = Settings(**self._get_stream_kwargs(config=config))
59-
return stream.availability_strategy.check_availability(stream, logger, self)
59+
try:
60+
stream = Settings(**self._get_stream_kwargs(config=config))
61+
return stream.availability_strategy.check_availability(stream, logger, self)
62+
except requests.HTTPError as error:
63+
body = error.response.json()
64+
error_msg = f"{body.get('code')}: {body.get('message')}"
65+
except Exception as error:
66+
error_msg = repr(error)
67+
68+
return False, error_msg
6069

6170
def streams(self, config: Mapping[str, Any]) -> List[Stream]:
6271
return [

airbyte-integrations/connectors/source-freshdesk/unit_tests/test_source.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def test_check_connection_invalid_config(config):
4545
assert not ok and error_msg
4646

4747

48-
def test_check_connection_exception(config):
48+
def test_check_connection_exception(requests_mock, config):
4949
ok, error_msg = SourceFreshdesk().check_connection(logger, config=config)
5050

5151
assert not ok and error_msg

0 commit comments

Comments
 (0)