diff --git a/airbyte-integrations/connectors/source-commcare/Dockerfile b/airbyte-integrations/connectors/source-commcare/Dockerfile index 75fee2efa69c..ec8b25b68051 100644 --- a/airbyte-integrations/connectors/source-commcare/Dockerfile +++ b/airbyte-integrations/connectors/source-commcare/Dockerfile @@ -35,5 +35,5 @@ COPY source_commcare ./source_commcare 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-commcare diff --git a/airbyte-integrations/connectors/source-commcare/metadata.yaml b/airbyte-integrations/connectors/source-commcare/metadata.yaml index e1bc67ca7ec8..973903f93f22 100644 --- a/airbyte-integrations/connectors/source-commcare/metadata.yaml +++ b/airbyte-integrations/connectors/source-commcare/metadata.yaml @@ -2,7 +2,7 @@ data: connectorSubtype: api connectorType: source definitionId: f39208dc-7e1c-48b8-919b-5006360cc27f - dockerImageTag: 0.1.0 + dockerImageTag: 0.1.1 dockerRepository: airbyte/source-commcare githubIssueLabel: source-commcare license: MIT diff --git a/airbyte-integrations/connectors/source-commcare/source_commcare/source.py b/airbyte-integrations/connectors/source-commcare/source_commcare/source.py index a6f3a7bc3a6f..e3c5382c5fd9 100644 --- a/airbyte-integrations/connectors/source-commcare/source_commcare/source.py +++ b/airbyte-integrations/connectors/source-commcare/source_commcare/source.py @@ -270,10 +270,18 @@ def read_records(self, *args, **kwargs) -> Iterable[Mapping[str, Any]]: # Source class SourceCommcare(AbstractSource): + def check_connection(self, logger, config) -> Tuple[bool, any]: - if "api_key" not in config: - return False, None - return True, None + + try: + auth = TokenAuthenticator(config["api_key"], auth_method="ApiKey") + args = { + "authenticator": auth, + } + stream = Application(**{**args, "app_id": config["app_id"], "project_space": config["project_space"]}).check_availability(logger=logger) + return True, None + except Exception as error: + return False, " Invalid apikey, project_space or app_id : "+str(error) def base_schema(self): return { diff --git a/airbyte-integrations/connectors/source-commcare/source_commcare/spec.yaml b/airbyte-integrations/connectors/source-commcare/source_commcare/spec.yaml index 18a5bcd0bf00..487c25ad6c02 100644 --- a/airbyte-integrations/connectors/source-commcare/source_commcare/spec.yaml +++ b/airbyte-integrations/connectors/source-commcare/source_commcare/spec.yaml @@ -7,6 +7,7 @@ connectionSpecification: - api_key - app_id - start_date + - project_space properties: api_key: type: string diff --git a/airbyte-integrations/connectors/source-commcare/unit_tests/test_source.py b/airbyte-integrations/connectors/source-commcare/unit_tests/test_source.py index dac61860c0c4..839fe80b8f2c 100644 --- a/airbyte-integrations/connectors/source-commcare/unit_tests/test_source.py +++ b/airbyte-integrations/connectors/source-commcare/unit_tests/test_source.py @@ -5,14 +5,15 @@ from unittest.mock import MagicMock, Mock import pytest +from unittest.mock import MagicMock, patch from source_commcare.source import SourceCommcare @pytest.fixture(name='config') def config_fixture(): - return {'api_key': 'apikey', 'app_id': 'appid', 'start_date': '2022-01-01T00:00:00Z'} - + return {'api_key': 'apikey', 'app_id': 'appid',"project_space": "project_space", 'start_date': '2022-01-01T00:00:00Z'} +@patch('source_commcare.source.Application.check_availability', return_value='true') def test_check_connection_ok(mocker, config): source = SourceCommcare() logger_mock = Mock() @@ -22,4 +23,5 @@ def test_check_connection_ok(mocker, config): def test_check_connection_fail(mocker, config): source = SourceCommcare() logger_mock = MagicMock() - assert source.check_connection(logger_mock, config={}) == (False, None) + excepted_outcome = " Invalid apikey, project_space or app_id : 'api_key'" + assert source.check_connection(logger_mock, config={}) == (False, excepted_outcome) diff --git a/docs/integrations/sources/commcare.md b/docs/integrations/sources/commcare.md index 6dd8fcebd647..e973abaf4fc1 100644 --- a/docs/integrations/sources/commcare.md +++ b/docs/integrations/sources/commcare.md @@ -36,4 +36,5 @@ The Commcare source connector supports the following streams: ## Changelog | Version | Date | Pull Request | Subject | +| 0.1.1 | 2023-07-27 | [28553](https://github.com/airbytehq/airbyte/pull/28553) | Added Check Connection | | 0.1.0 | 2022-11-08 | [20220](https://github.com/airbytehq/airbyte/pull/20220) | Commcare Source Connector |