Skip to content

Commit

Permalink
🐛 Source Genesys: Use region specific API server (#25598)
Browse files Browse the repository at this point in the history
* use api url corresponding to region specified in the config

* update unit tests

* bump up version

* refactor
  • Loading branch information
Shishir-rmv authored Aug 1, 2023
1 parent 5cf912a commit c199724
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 23 deletions.
2 changes: 1 addition & 1 deletion airbyte-integrations/connectors/source-genesys/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ COPY source_genesys ./source_genesys
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]

LABEL io.airbyte.version=0.1.0
LABEL io.airbyte.version=0.1.1
LABEL io.airbyte.name=airbyte/source-genesys
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@


class GenesysStream(HttpStream, ABC):
url_base = "https://api.mypurecloud.com.au/api/v2/"
page_size = 500

def __init__(self, *args, **kwargs):
@property
def url_base(self):
if self._api_base_url is not None:
return self._api_base_url + "/api/v2/"
return None

def __init__(self, api_base_url, *args, **kwargs):
self._api_base_url = api_base_url
super().__init__(*args, **kwargs)

def backoff_time(self, response: requests.Response) -> Optional[int]:
Expand All @@ -29,7 +35,8 @@ def next_page_token(self, response: requests.Response) -> Optional[Mapping[str,
response_json = response.json()

if response_json.get("nextUri"):
next_query_string = urllib.parse.urlsplit(response_json.get("nextUri")).query
next_query_string = urllib.parse.urlsplit(
response_json.get("nextUri")).query
return dict(urllib.parse.parse_qsl(next_query_string))

def request_params(
Expand Down Expand Up @@ -254,21 +261,24 @@ def check_connection(self, logger, config) -> Tuple[bool, any]:

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

GENESYS_TENANT_ENDPOINT_MAP: Dict = {
"Americas (US East)": "https://login.mypurecloud.com",
"Americas (US East 2)": "https://login.use2.us-gov-pure.cloud",
"Americas (US West)": "https://login.usw2.pure.cloud",
"Americas (Canada)": "https://login.cac1.pure.cloud",
"Americas (São Paulo)": "https://login.sae1.pure.cloud",
"EMEA (Frankfurt)": "https://login.mypurecloud.de",
"EMEA (Dublin)": "https://login.mypurecloud.ie",
"EMEA (London)": "https://login.euw2.pure.cloud",
"Asia Pacific (Mumbai)": "https://login.aps1.pure.cloud",
"Asia Pacific (Seoul)": "https://login.apne2.pure.cloud",
"Asia Pacific (Sydney)": "https://login.mypurecloud.com.au",
GENESYS_REGION_DOMAIN_MAP: Dict[str, str] = {
"Americas (US East)": "mypurecloud.com",
"Americas (US East 2)": "use2.us-gov-pure.cloud",
"Americas (US West)": "usw2.pure.cloud",
"Americas (Canada)": "cac1.pure.cloud",
"Americas (São Paulo)": "sae1.pure.cloud",
"EMEA (Frankfurt)": "mypurecloud.de",
"EMEA (Dublin)": "mypurecloud.ie",
"EMEA (London)": "euw2.pure.cloud",
"Asia Pacific (Mumbai)": "aps1.pure.cloud",
"Asia Pacific (Seoul)": "apne2.pure.cloud",
"Asia Pacific (Sydney)": "mypurecloud.com.au",
}
base_url = GENESYS_TENANT_ENDPOINT_MAP.get(config["tenant_endpoint"])
args = {"authenticator": GenesysOAuthAuthenticator(base_url, config["client_id"], config["client_secret"])}
domain = GENESYS_REGION_DOMAIN_MAP.get(config["tenant_endpoint"])
base_url = f"https://login.{domain}"
api_base_url = f"https://api.{domain}"
args = {"api_base_url": api_base_url, "authenticator": GenesysOAuthAuthenticator(
base_url, config["client_id"], config["client_secret"])}

# response = self.get_connection_response(config)
# response.raise_for_status()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from unittest.mock import MagicMock

from source_genesys.source import SourceGenesys
import pytest


def test_check_connection(mocker):
Expand All @@ -21,3 +22,32 @@ def test_streams(mocker):
streams = source.streams(config_mock)
expected_streams_number = 16
assert len(streams) == expected_streams_number


@pytest.mark.parametrize(
("tenant_endpoint", "url_base"),
[
("Americas (US East)", "https://api.mypurecloud.com/api/v2/"),
("Americas (US East 2)", "https://api.use2.us-gov-pure.cloud/api/v2/"),
("Americas (US West)", "https://api.usw2.pure.cloud/api/v2/"),
("Americas (Canada)", "https://api.cac1.pure.cloud/api/v2/"),
("Americas (São Paulo)", "https://api.sae1.pure.cloud/api/v2/"),
("EMEA (Frankfurt)", "https://api.mypurecloud.de/api/v2/"),
("EMEA (Dublin)", "https://api.mypurecloud.ie/api/v2/"),
("EMEA (London)", "https://api.euw2.pure.cloud/api/v2/"),
("Asia Pacific (Mumbai)", "https://api.aps1.pure.cloud/api/v2/"),
("Asia Pacific (Seoul)", "https://api.apne2.pure.cloud/api/v2/"),
("Asia Pacific (Sydney)", "https://api.mypurecloud.com.au/api/v2/"),
],
)
def test_url_base(tenant_endpoint, url_base):
source = SourceGenesys()
config_mock = MagicMock()
config_mock.__getitem__.side_effect = lambda key: tenant_endpoint if key == "tenant_endpoint" else None
SourceGenesys.get_connection_response = MagicMock()
streams = source.streams(config_mock)
expected_streams_number = 16
assert len(streams) == expected_streams_number

for stream in streams:
assert stream.url_base == url_base
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ def patch_base_class(mocker):


def test_request_params(patch_base_class):
stream = GenesysStream()
stream = GenesysStream(api_base_url="https://dummy.url")
inputs = {"stream_slice": None, "stream_state": None, "next_page_token": None}
expected_params = {"pageSize": 500}
assert stream.request_params(**inputs) == expected_params


def test_request_headers(patch_base_class):
stream = GenesysStream()
stream = GenesysStream(api_base_url="https://dummy.url")
inputs = {"stream_slice": None, "stream_state": None, "next_page_token": None}
assert len(stream.request_headers(**inputs)) == 0


def test_http_method(patch_base_class):
stream = GenesysStream()
stream = GenesysStream(api_base_url="https://dummy.url")
expected_method = "GET"
assert stream.http_method == expected_method

Expand All @@ -48,12 +48,18 @@ def test_http_method(patch_base_class):
def test_should_retry(patch_base_class, http_status, should_retry):
response_mock = MagicMock()
response_mock.status_code = http_status
stream = GenesysStream()
stream = GenesysStream(api_base_url="https://dummy.url")
assert stream.should_retry(response_mock) == should_retry


def test_backoff_time(patch_base_class):
response_mock = MagicMock()
stream = GenesysStream()
stream = GenesysStream(api_base_url="https://dummy.url")
expected_backoff_time = 1
assert stream.backoff_time(response_mock) == expected_backoff_time

def test_url_base(patch_base_class):
api_base_url = "https://dummy.url"
stream = GenesysStream(api_base_url=api_base_url)
assert stream.url_base == api_base_url + "/api/v2/"

1 change: 1 addition & 0 deletions docs/integrations/sources/genesys.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ You can follow the documentation on [API credentials](https://developer.genesys.
## Changelog
| Version | Date | Pull Request | Subject |
| :------ | :--------- | :------------------------------------------------------- | :-------------------------- |
| 0.1.1 | 2023-04-27 | [25598](https://github.com/airbytehq/airbyte/pull/25598) | Use region specific API server |
| 0.1.0 | 2022-10-06 | [17559](https://github.com/airbytehq/airbyte/pull/17559) | The Genesys Source is created |

0 comments on commit c199724

Please sign in to comment.