Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/commcare check connection #57

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion airbyte-integrations/connectors/source-commcare/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ connectionSpecification:
- api_key
- app_id
- start_date
- project_space
properties:
api_key:
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
1 change: 1 addition & 0 deletions docs/integrations/sources/commcare.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |