From 2e354c87f86e70581dc8d34f3dd8721144efb573 Mon Sep 17 00:00:00 2001 From: Serhii Date: Thu, 24 Mar 2022 19:32:10 +0200 Subject: [PATCH 01/11] Increased unit test coverage to 90 --- .../source-intercom/source_intercom/source.py | 2 +- .../source-intercom/unit_tests/conftest.py | 15 +++ .../source-intercom/unit_tests/unit_test.py | 118 +++++++++++++++++- docs/integrations/sources/intercom.md | 1 - 4 files changed, 133 insertions(+), 3 deletions(-) create mode 100644 airbyte-integrations/connectors/source-intercom/unit_tests/conftest.py diff --git a/airbyte-integrations/connectors/source-intercom/source_intercom/source.py b/airbyte-integrations/connectors/source-intercom/source_intercom/source.py index 94c49285ae99..05700e4dc7bc 100755 --- a/airbyte-integrations/connectors/source-intercom/source_intercom/source.py +++ b/airbyte-integrations/connectors/source-intercom/source_intercom/source.py @@ -6,7 +6,7 @@ from datetime import datetime from enum import Enum from typing import Any, Iterable, List, Mapping, MutableMapping, Optional, Tuple -from urllib.parse import parse_qsl, urlparse, urljoin +from urllib.parse import parse_qsl, urljoin, urlparse import requests from airbyte_cdk.logger import AirbyteLogger diff --git a/airbyte-integrations/connectors/source-intercom/unit_tests/conftest.py b/airbyte-integrations/connectors/source-intercom/unit_tests/conftest.py new file mode 100644 index 000000000000..8e4976a2430b --- /dev/null +++ b/airbyte-integrations/connectors/source-intercom/unit_tests/conftest.py @@ -0,0 +1,15 @@ +# +# Copyright (c) 2021 Airbyte, Inc., all rights reserved. +# + +from pytest import fixture + + +@fixture(name="config") +def config_fixture(): + config = { + "access_token": "TOKEN", + "start_date": "2022-03-20T00:00:00Z", + } + + return config diff --git a/airbyte-integrations/connectors/source-intercom/unit_tests/unit_test.py b/airbyte-integrations/connectors/source-intercom/unit_tests/unit_test.py index 40b0cfc2eb91..920ca5f27744 100644 --- a/airbyte-integrations/connectors/source-intercom/unit_tests/unit_test.py +++ b/airbyte-integrations/connectors/source-intercom/unit_tests/unit_test.py @@ -5,9 +5,27 @@ import pytest import requests +from airbyte_cdk.logger import AirbyteLogger from airbyte_cdk.models import SyncMode from airbyte_cdk.sources.streams.http.auth import NoAuth -from source_intercom.source import Companies, Contacts, IntercomStream +from source_intercom.source import ( + Admins, + Companies, + CompanyAttributes, + CompanySegments, + ContactAttributes, + Contacts, + ConversationParts, + Conversations, + IntercomStream, + Segments, + SourceIntercom, + Tags, + Teams, +) + +logger = AirbyteLogger() + test_data = [ ( @@ -76,3 +94,101 @@ def test_switch_to_standard_endpoint_if_scroll_expired(requests_mock): records += list(stream1.read_records(sync_mode=SyncMode, stream_slice=slice)) assert stream1._endpoint_type == Companies.EndpointType.standard + + +def test_check_connection_ok(config, requests_mock): + url = "https://api.intercom.io/tags" + requests_mock.get(url, json={}) + ok, error_msg = SourceIntercom().check_connection(logger, config=config) + + assert ok + assert not error_msg + + +def test_check_connection_empty_config(config): + config = {} + + with pytest.raises(KeyError): + SourceIntercom().check_connection(logger, config=config) + + +def test_check_connection_invalid_config(config): + config.pop("start_date") + ok, error_msg = SourceIntercom().check_connection(logger, config=config) + + assert not ok + assert error_msg + + +def test_check_connection_exception(config): + ok, error_msg = SourceIntercom().check_connection(logger, config=config) + + assert not ok + assert error_msg + + +def test_streams(config): + streams = SourceIntercom().streams(config) + + assert len(streams) == 11 + + +@pytest.mark.parametrize( + "stream, endpoint, response, expected", + [ + (Admins, "/admins", {"type": "admin.list", "admins": [{"type": "admin", "id": "id"}]}, [{"id": "id", "type": "admin"}]), + ( + Companies, + "/companies/scroll", + {"type": "company.list", "data": [{"type": "company", "id": "id"}]}, + [{"id": "id", "type": "company"}], + ), + ( + CompanySegments, + "/companies/id/segments", + {"type": "list", "data": [{"type": "segment", "id": "id"}]}, + [{"id": "id", "type": "segment"}], + ), + (Contacts, "/contacts", {"type": "list", "data": [{"type": "contact", "id": "id"}]}, [{"id": "id", "type": "contact"}]), + ( + Conversations, + "/conversations", + {"type": "conversation.list", "conversations": [{"type": "conversation", "id": "id"}]}, + [{"id": "id", "type": "conversation"}], + ), + ( + ConversationParts, + "/conversations/id", + {"id": "id", "conversation_parts": {"conversation_parts": [{"type": "conversation_part", "id": "id"}]}}, + [{"id": "id", "type": "conversation_part"}], + ), + ( + CompanyAttributes, + "/data_attributes", + {"type": "list", "data": [{"type": "data_attribute", "id": "id"}]}, + [{"id": "id", "type": "data_attribute"}], + ), + ( + ContactAttributes, + "/data_attributes", + {"type": "list", "data": [{"type": "data_attribute", "id": "id"}]}, + [{"id": "id", "type": "data_attribute"}], + ), + (Segments, "/segments", {"type": "segment.list", "segments": [{"type": "segment", "id": "id"}]}, [{"id": "id", "type": "segment"}]), + (Tags, "/tags", {"type": "list", "data": [{"type": "tag", "id": "id"}]}, [{"id": "id", "type": "tag"}]), + (Teams, "/teams", {"teams": [{"type": "team", "id": "id"}]}, [{"id": "id", "type": "team"}]), + ], +) +def test_read(stream, endpoint, response, expected, config, requests_mock): + requests_mock.get("/conversations", json=response) + requests_mock.get("/companies/scroll", json=response) + requests_mock.get(endpoint, json=response) + + stream = stream(authenticator=NoAuth()) + + records = [] + + for slice in stream.stream_slices(sync_mode=SyncMode.full_refresh): + records += list(stream.read_records(sync_mode=SyncMode, stream_slice=slice)) + + assert records == expected diff --git a/docs/integrations/sources/intercom.md b/docs/integrations/sources/intercom.md index 7f3232262ad8..ca28a8ae0ae6 100644 --- a/docs/integrations/sources/intercom.md +++ b/docs/integrations/sources/intercom.md @@ -31,7 +31,6 @@ If there are more endpoints you'd like Airbyte to support, please [create an iss | :--- | :--- | | Full Refresh Sync | Yes | | Incremental - Append Sync | Yes | -| Replicate Incremental Deletes | Coming soon | | SSL connection | Yes | | Namespaces | No | From 6e828715b073c309d1a478185b74606f1c487437 Mon Sep 17 00:00:00 2001 From: Serhii Date: Thu, 24 Mar 2022 19:39:43 +0200 Subject: [PATCH 02/11] Updated doc for OAuth --- docs/integrations/sources/intercom.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/integrations/sources/intercom.md b/docs/integrations/sources/intercom.md index ca28a8ae0ae6..db3130920404 100644 --- a/docs/integrations/sources/intercom.md +++ b/docs/integrations/sources/intercom.md @@ -42,9 +42,13 @@ The Intercom connector should not run into Intercom API limitations under normal ## Getting started -### Requirements +###Authentication Types + +To access the Intercom API, you'll need an access token. How you get this token depends on if your app is for your own usage or for the public's usage. + +* [Access Token](https://developers.intercom.com/building-apps/docs/authentication-types#section-access-tokens) +* [OAuth](https://developers.intercom.com/building-apps/docs/authentication-types#section-o-auth) -* Intercom Access Token ### Setup guide From 9b421c35a278299b6c858b7225825ecb67d5f9d0 Mon Sep 17 00:00:00 2001 From: Serhii Date: Thu, 24 Mar 2022 19:40:53 +0200 Subject: [PATCH 03/11] Fix typo --- docs/integrations/sources/intercom.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/integrations/sources/intercom.md b/docs/integrations/sources/intercom.md index db3130920404..dff81f031a90 100644 --- a/docs/integrations/sources/intercom.md +++ b/docs/integrations/sources/intercom.md @@ -42,7 +42,7 @@ The Intercom connector should not run into Intercom API limitations under normal ## Getting started -###Authentication Types +### Authentication Types To access the Intercom API, you'll need an access token. How you get this token depends on if your app is for your own usage or for the public's usage. From d7eefaaedbb42e8ba1fa94fee72489ccaf21208b Mon Sep 17 00:00:00 2001 From: Serhii Date: Thu, 24 Mar 2022 20:01:29 +0200 Subject: [PATCH 04/11] Updated doc to review --- docs/integrations/sources/intercom.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/docs/integrations/sources/intercom.md b/docs/integrations/sources/intercom.md index dff81f031a90..f4c798c48d2c 100644 --- a/docs/integrations/sources/intercom.md +++ b/docs/integrations/sources/intercom.md @@ -40,15 +40,13 @@ The connector is restricted by normal Intercom [requests limitation](https://dev The Intercom connector should not run into Intercom API limitations under normal usage. Please [create an issue](https://github.com/airbytehq/airbyte/issues) if you see any rate limit issues that are not automatically retried successfully. -## Getting started +## Getting Started (Airbyte Cloud) -### Authentication Types - -To access the Intercom API, you'll need an access token. How you get this token depends on if your app is for your own usage or for the public's usage. +### Setup guide -* [Access Token](https://developers.intercom.com/building-apps/docs/authentication-types#section-access-tokens) -* [OAuth](https://developers.intercom.com/building-apps/docs/authentication-types#section-o-auth) +Please read [How authenticate with OAuth](https://developers.intercom.com/building-apps/docs/authentication-types#section-o-auth) +## Getting started (Airbyte OSS) ### Setup guide From 66cbf14f867028d41b81519709de1ba84bec39b5 Mon Sep 17 00:00:00 2001 From: Serhii Date: Thu, 24 Mar 2022 20:16:11 +0200 Subject: [PATCH 05/11] Updated doc to review --- docs/integrations/sources/intercom.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/integrations/sources/intercom.md b/docs/integrations/sources/intercom.md index f4c798c48d2c..e17e7c7cef9c 100644 --- a/docs/integrations/sources/intercom.md +++ b/docs/integrations/sources/intercom.md @@ -44,7 +44,12 @@ The Intercom connector should not run into Intercom API limitations under normal ### Setup guide -Please read [How authenticate with OAuth](https://developers.intercom.com/building-apps/docs/authentication-types#section-o-auth) +How configuring the connector in the Airbyte UI: + +1. Click Authenticate your account to sign in with Intercom and authorize your account. +2. Approve authorize access. +3. Fill in the `start date` field. +4. You should be ready to sync data. ## Getting started (Airbyte OSS) From e14cc6d4e1d6316e3047d66cafee9afe291ce098 Mon Sep 17 00:00:00 2001 From: Serhii Lazebnyi <53845333+lazebnyi@users.noreply.github.com> Date: Mon, 28 Mar 2022 13:39:23 +0300 Subject: [PATCH 06/11] Update docs/integrations/sources/intercom.md Co-authored-by: Sherif A. Nada --- docs/integrations/sources/intercom.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/integrations/sources/intercom.md b/docs/integrations/sources/intercom.md index e17e7c7cef9c..ab19772dafe6 100644 --- a/docs/integrations/sources/intercom.md +++ b/docs/integrations/sources/intercom.md @@ -47,7 +47,6 @@ The Intercom connector should not run into Intercom API limitations under normal How configuring the connector in the Airbyte UI: 1. Click Authenticate your account to sign in with Intercom and authorize your account. -2. Approve authorize access. 3. Fill in the `start date` field. 4. You should be ready to sync data. From 65c7ef95a947623033d7bb36c31f089201c97c69 Mon Sep 17 00:00:00 2001 From: Serhii Lazebnyi <53845333+lazebnyi@users.noreply.github.com> Date: Mon, 28 Mar 2022 13:39:29 +0300 Subject: [PATCH 07/11] Update docs/integrations/sources/intercom.md Co-authored-by: Sherif A. Nada --- docs/integrations/sources/intercom.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/integrations/sources/intercom.md b/docs/integrations/sources/intercom.md index ab19772dafe6..4fbd300082a4 100644 --- a/docs/integrations/sources/intercom.md +++ b/docs/integrations/sources/intercom.md @@ -47,7 +47,7 @@ The Intercom connector should not run into Intercom API limitations under normal How configuring the connector in the Airbyte UI: 1. Click Authenticate your account to sign in with Intercom and authorize your account. -3. Fill in the `start date` field. +2. Fill in the `start date` field. 4. You should be ready to sync data. ## Getting started (Airbyte OSS) From ecb79df7eae6a6e855adc49bd1aeaf21840d5bf5 Mon Sep 17 00:00:00 2001 From: Serhii Lazebnyi <53845333+lazebnyi@users.noreply.github.com> Date: Mon, 28 Mar 2022 13:39:34 +0300 Subject: [PATCH 08/11] Update docs/integrations/sources/intercom.md Co-authored-by: Sherif A. Nada --- docs/integrations/sources/intercom.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/integrations/sources/intercom.md b/docs/integrations/sources/intercom.md index 4fbd300082a4..716f41e06f31 100644 --- a/docs/integrations/sources/intercom.md +++ b/docs/integrations/sources/intercom.md @@ -44,7 +44,7 @@ The Intercom connector should not run into Intercom API limitations under normal ### Setup guide -How configuring the connector in the Airbyte UI: +How to configure the connector in the Airbyte UI: 1. Click Authenticate your account to sign in with Intercom and authorize your account. 2. Fill in the `start date` field. From ee84ad8d7c10c1c60fd1aa547b57d6340e343005 Mon Sep 17 00:00:00 2001 From: Serhii Lazebnyi <53845333+lazebnyi@users.noreply.github.com> Date: Mon, 28 Mar 2022 13:39:38 +0300 Subject: [PATCH 09/11] Update docs/integrations/sources/intercom.md Co-authored-by: Sherif A. Nada --- docs/integrations/sources/intercom.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/integrations/sources/intercom.md b/docs/integrations/sources/intercom.md index 716f41e06f31..dd8e1297832f 100644 --- a/docs/integrations/sources/intercom.md +++ b/docs/integrations/sources/intercom.md @@ -48,7 +48,7 @@ How to configure the connector in the Airbyte UI: 1. Click Authenticate your account to sign in with Intercom and authorize your account. 2. Fill in the `start date` field. -4. You should be ready to sync data. +3. You should be ready to sync data. ## Getting started (Airbyte OSS) From a15c135d835b9e8917ddc871fe007d8ae35bb5f5 Mon Sep 17 00:00:00 2001 From: Serhii Date: Mon, 28 Mar 2022 13:48:41 +0300 Subject: [PATCH 10/11] Fix unit test --- .../connectors/source-intercom/unit_tests/unit_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/airbyte-integrations/connectors/source-intercom/unit_tests/unit_test.py b/airbyte-integrations/connectors/source-intercom/unit_tests/unit_test.py index 9a07134a9e49..5157c3dd408f 100644 --- a/airbyte-integrations/connectors/source-intercom/unit_tests/unit_test.py +++ b/airbyte-integrations/connectors/source-intercom/unit_tests/unit_test.py @@ -160,7 +160,7 @@ def test_streams(config): ConversationParts, "/conversations/id", {"id": "id", "conversation_parts": {"conversation_parts": [{"type": "conversation_part", "id": "id"}]}}, - [{"id": "id", "type": "conversation_part"}], + [{"conversation_id": "id", "id": "id", "type": "conversation_part"}], ), ( CompanyAttributes, From e97cdf94047b1fc1d5681598f18c15ab8742888c Mon Sep 17 00:00:00 2001 From: Serhii Date: Mon, 28 Mar 2022 13:53:23 +0300 Subject: [PATCH 11/11] Fix to linter --- .../connectors/source-intercom/unit_tests/unit_test.py | 1 - 1 file changed, 1 deletion(-) diff --git a/airbyte-integrations/connectors/source-intercom/unit_tests/unit_test.py b/airbyte-integrations/connectors/source-intercom/unit_tests/unit_test.py index 5157c3dd408f..7173f5959475 100644 --- a/airbyte-integrations/connectors/source-intercom/unit_tests/unit_test.py +++ b/airbyte-integrations/connectors/source-intercom/unit_tests/unit_test.py @@ -224,4 +224,3 @@ def test_conversation_part_has_conversation_id(requests_mock): record_count += 1 assert record_count == 2 -