Skip to content

Commit

Permalink
Source FreshDesk: fix unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-yermilov-gl committed Feb 2, 2023
1 parent d930fbc commit d253fc0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import logging
from typing import Any, List, Mapping, Optional, Tuple

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

def check_connection(self, logger: logging.Logger, config: Mapping[str, Any]) -> Tuple[bool, Optional[Any]]:
stream = Settings(**self._get_stream_kwargs(config=config))
return stream.availability_strategy.check_availability(stream, logger, self)
try:
stream = Settings(**self._get_stream_kwargs(config=config))
return stream.availability_strategy.check_availability(stream, logger, self)
except requests.HTTPError as error:
body = error.response.json()
error_msg = f"{body.get('code')}: {body.get('message')}"
except Exception as error:
error_msg = repr(error)

return False, error_msg

def streams(self, config: Mapping[str, Any]) -> List[Stream]:
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_check_connection_invalid_config(config):
assert not ok and error_msg


def test_check_connection_exception(config):
def test_check_connection_exception(requests_mock, config):
ok, error_msg = SourceFreshdesk().check_connection(logger, config=config)

assert not ok and error_msg
Expand Down

0 comments on commit d253fc0

Please sign in to comment.