Skip to content

Commit cc80142

Browse files
New Source: Commcare (#20220)
* commcare connector * flake improvement * added the docs * added the config * project_space added in the config * project space is required * cleaning * added test case * disbaled the backward compatibility test * feat: revert .vscode/settings.json Co-authored-by: Sajarin <sajarindider@gmail.com>
1 parent 80504d9 commit cc80142

File tree

27 files changed

+884
-0
lines changed

27 files changed

+884
-0
lines changed

airbyte-config/init/src/main/resources/seed/source_definitions.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,13 @@
327327
documentationUrl: https://docs.airbyte.com/integrations/sources/convertkit
328328
sourceType: api
329329
releaseStage: alpha
330+
- name: Commcare
331+
sourceDefinitionId: f39208dc-7e1c-48b8-919b-5006360cc27f
332+
dockerRepository: airbyte/source-commcare
333+
dockerImageTag: 0.1.0
334+
documentationUrl: https://docs.airbyte.com/integrations/sources/commcare
335+
sourceType: api
336+
releaseStage: alpha
330337
- name: Copper
331338
sourceDefinitionId: 44f3002f-2df9-4f6d-b21c-02cd3b47d0dc
332339
dockerRepository: airbyte/source-copper

airbyte-config/init/src/main/resources/seed/source_specs.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2799,6 +2799,46 @@
27992799
supportsNormalization: false
28002800
supportsDBT: false
28012801
supported_destination_sync_modes: []
2802+
- dockerImage: "airbyte/source-commcare:0.1.0"
2803+
spec:
2804+
documentationUrl: "https://docsurl.com"
2805+
connectionSpecification:
2806+
$schema: "http://json-schema.org/draft-07/schema#"
2807+
title: "Commcare Source Spec"
2808+
type: "object"
2809+
required:
2810+
- "api_key"
2811+
- "app_id"
2812+
- "start_date"
2813+
properties:
2814+
api_key:
2815+
type: "string"
2816+
title: "API Key"
2817+
description: "Commcare API Key"
2818+
airbyte_secret: true
2819+
order: 0
2820+
project_space:
2821+
type: "string"
2822+
title: "Project Space"
2823+
description: "Project Space for commcare"
2824+
order: 1
2825+
app_id:
2826+
type: "string"
2827+
title: "Application ID"
2828+
description: "The Application ID we are interested in"
2829+
airbyte_secret: true
2830+
order: 2
2831+
start_date:
2832+
type: "string"
2833+
title: "Start date for extracting records"
2834+
pattern: "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
2835+
default: "2022-10-01T00:00:00Z"
2836+
description: "UTC date and time in the format 2017-01-25T00:00:00Z. Only\
2837+
\ records after this date will be replicated."
2838+
order: 3
2839+
supportsNormalization: false
2840+
supportsDBT: false
2841+
supported_destination_sync_modes: []
28022842
- dockerImage: "airbyte/source-copper:0.1.0"
28032843
spec:
28042844
documentationUrl: "https://docs.airbyte.com/integrations/sources/copper"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*
2+
!Dockerfile
3+
!main.py
4+
!source_commcare
5+
!setup.py
6+
!secrets
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
FROM python:3.9.15-slim-bullseye as base
2+
3+
# build and load all requirements
4+
FROM base as builder
5+
WORKDIR /airbyte/integration_code
6+
7+
# upgrade pip to the latest version
8+
RUN apt-get update && apt-get install -y && rm -rf /var/lib/apt/lists/* \
9+
&& pip install --upgrade pip \
10+
&& python3 -m pip install --upgrade setuptools
11+
12+
RUN DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get -y install tzdata
13+
14+
COPY setup.py ./
15+
# install necessary packages to a temporary folder
16+
RUN pip install --prefix=/install .
17+
18+
# build a clean environment
19+
FROM base
20+
WORKDIR /airbyte/integration_code
21+
22+
# copy all loaded and built libraries to a pure basic image
23+
COPY --from=builder /install /usr/local
24+
# add default timezone settings
25+
COPY --from=builder /usr/share/zoneinfo/Etc/UTC /etc/localtime
26+
RUN echo "Etc/UTC" > /etc/timezone
27+
28+
# bash is installed for more convenient debugging.
29+
# RUN apk --no-cache add bash
30+
31+
# copy payload code only
32+
COPY main.py ./
33+
COPY source_commcare ./source_commcare
34+
35+
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
36+
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]
37+
38+
LABEL io.airbyte.version=0.1.0
39+
LABEL io.airbyte.name=airbyte/source-commcare
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# Commcare Source
2+
3+
This is the repository for the Commcare source connector, written in Python.
4+
For information about how to use this connector within Airbyte, see [the documentation](https://docs.airbyte.io/integrations/sources/commcare).
5+
6+
## Local development
7+
8+
### Prerequisites
9+
**To iterate on this connector, make sure to complete this prerequisites section.**
10+
11+
#### Minimum Python version required `= 3.9.0`
12+
13+
#### Build & Activate Virtual Environment and install dependencies
14+
From this connector directory, create a virtual environment:
15+
```
16+
python -m venv .venv
17+
```
18+
19+
This will generate a virtualenv for this module in `.venv/`. Make sure this venv is active in your
20+
development environment of choice. To activate it from the terminal, run:
21+
```
22+
source .venv/bin/activate
23+
pip install -r requirements.txt
24+
pip install '.[tests]'
25+
```
26+
If you are in an IDE, follow your IDE's instructions to activate the virtualenv.
27+
28+
Note that while we are installing dependencies from `requirements.txt`, you should only edit `setup.py` for your dependencies. `requirements.txt` is
29+
used for editable installs (`pip install -e`) to pull in Python dependencies from the monorepo and will call `setup.py`.
30+
If this is mumbo jumbo to you, don't worry about it, just put your deps in `setup.py` but install using `pip install -r requirements.txt` and everything
31+
should work as you expect.
32+
33+
#### Building via Gradle
34+
You can also build the connector in Gradle. This is typically used in CI and not needed for your development workflow.
35+
36+
To build using Gradle, from the Airbyte repository root, run:
37+
```
38+
./gradlew :airbyte-integrations:connectors:source-commcare:build
39+
```
40+
41+
#### Create credentials
42+
**If you are a community contributor**, follow the instructions in the [documentation](https://docs.airbyte.io/integrations/sources/commcare)
43+
to generate the necessary credentials. Then create a file `secrets/config.json` conforming to the `source_commcare/spec.yaml` file.
44+
Note that any directory named `secrets` is gitignored across the entire Airbyte repo, so there is no danger of accidentally checking in sensitive information.
45+
See `integration_tests/sample_config.json` for a sample config file.
46+
47+
**If you are an Airbyte core member**, copy the credentials in Lastpass under the secret name `source commcare test creds`
48+
and place them into `secrets/config.json`.
49+
50+
### Locally running the connector
51+
```
52+
python main.py spec
53+
python main.py check --config secrets/config.json
54+
python main.py discover --config secrets/config.json
55+
python main.py read --config secrets/config.json --catalog integration_tests/configured_catalog.json
56+
```
57+
58+
### Locally running the connector docker image
59+
60+
#### Build
61+
First, make sure you build the latest Docker image:
62+
```
63+
docker build . -t airbyte/source-commcare:dev
64+
```
65+
66+
You can also build the connector image via Gradle:
67+
```
68+
./gradlew :airbyte-integrations:connectors:source-commcare:airbyteDocker
69+
```
70+
When building via Gradle, the docker image name and tag, respectively, are the values of the `io.airbyte.name` and `io.airbyte.version` `LABEL`s in
71+
the Dockerfile.
72+
73+
#### Run
74+
Then run any of the connector commands as follows:
75+
```
76+
docker run --rm airbyte/source-commcare:dev spec
77+
docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-commcare:dev check --config /secrets/config.json
78+
docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-commcare:dev discover --config /secrets/config.json
79+
docker run --rm -v $(pwd)/secrets:/secrets -v $(pwd)/integration_tests:/integration_tests airbyte/source-commcare:dev read --config /secrets/config.json --catalog /integration_tests/configured_catalog.json
80+
```
81+
## Testing
82+
Make sure to familiarize yourself with [pytest test discovery](https://docs.pytest.org/en/latest/goodpractices.html#test-discovery) to know how your test files and methods should be named.
83+
First install test dependencies into your virtual environment:
84+
```
85+
pip install .[tests]
86+
```
87+
### Unit Tests
88+
To run unit tests locally, from the connector directory run:
89+
```
90+
python -m pytest unit_tests
91+
```
92+
93+
### Integration Tests
94+
There are two types of integration tests: Acceptance Tests (Airbyte's test suite for all source connectors) and custom integration tests (which are specific to this connector).
95+
#### Custom Integration tests
96+
Place custom tests inside `integration_tests/` folder, then, from the connector root, run
97+
```
98+
python -m pytest integration_tests
99+
```
100+
#### Acceptance Tests
101+
Customize `acceptance-test-config.yml` file to configure tests. See [Source Acceptance Tests](https://docs.airbyte.io/connector-development/testing-connectors/source-acceptance-tests-reference) for more information.
102+
If your connector requires to create or destroy resources for use during acceptance tests create fixtures for it and place them inside integration_tests/acceptance.py.
103+
To run your integration tests with acceptance tests, from the connector root, run
104+
```
105+
python -m pytest integration_tests -p integration_tests.acceptance
106+
```
107+
To run your integration tests with docker
108+
109+
### Using gradle to run tests
110+
All commands should be run from airbyte project root.
111+
To run unit tests:
112+
```
113+
./gradlew :airbyte-integrations:connectors:source-commcare:unitTest
114+
```
115+
To run acceptance and custom integration tests:
116+
```
117+
./gradlew :airbyte-integrations:connectors:source-commcare:integrationTest
118+
```
119+
120+
## Dependency Management
121+
All of your dependencies should go in `setup.py`, NOT `requirements.txt`. The requirements file is only used to connect internal Airbyte dependencies in the monorepo for local development.
122+
We split dependencies between two groups, dependencies that are:
123+
* required for your connector to work need to go to `MAIN_REQUIREMENTS` list.
124+
* required for the testing need to go to `TEST_REQUIREMENTS` list
125+
126+
### Publishing a new version of the connector
127+
You've checked out the repo, implemented a million dollar feature, and you're ready to share your changes with the world. Now what?
128+
1. Make sure your changes are passing unit and integration tests.
129+
1. Bump the connector version in `Dockerfile` -- just increment the value of the `LABEL io.airbyte.version` appropriately (we use [SemVer](https://semver.org/)).
130+
1. Create a Pull Request.
131+
1. Pat yourself on the back for being an awesome contributor.
132+
1. Someone from Airbyte will take a look at your PR and iterate with you to merge it into master.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# See [Source Acceptance Tests](https://docs.airbyte.io/connector-development/testing-connectors/source-acceptance-tests-reference)
2+
# for more information about how to configure these tests
3+
connector_image: airbyte/source-commcare:dev
4+
tests:
5+
spec:
6+
- spec_path: "source_commcare/spec.yaml"
7+
connection:
8+
- config_path: "secrets/config.json"
9+
status: "succeed"
10+
- config_path: "integration_tests/invalid_config.json"
11+
status: "failed"
12+
# discovery:
13+
# - config_path: "secrets/config.json"
14+
# backward_compatibility_tests_config:
15+
# disable_for_version: "0.1.0"
16+
basic_read:
17+
- config_path: "secrets/config.json"
18+
configured_catalog_path: "integration_tests/configured_catalog.json"
19+
empty_streams: []
20+
full_refresh:
21+
- config_path: "secrets/config.json"
22+
configured_catalog_path: "integration_tests/configured_catalog.json"
23+
incremental:
24+
- config_path: "secrets/config.json"
25+
configured_catalog_path: "integration_tests/configured_catalog.json"
26+
future_state_path: "integration_tests/abnormal_state.json"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env sh
2+
3+
# Build latest connector image
4+
docker build . -t $(cat acceptance-test-config.yml | grep "connector_image" | head -n 1 | cut -d: -f2-)
5+
6+
# Pull latest acctest image
7+
docker pull airbyte/source-acceptance-test:latest
8+
9+
# Run
10+
docker run --rm -it \
11+
-v /var/run/docker.sock:/var/run/docker.sock \
12+
-v /tmp:/tmp \
13+
-v $(pwd):/test_input \
14+
airbyte/source-acceptance-test \
15+
--acceptance-test-config /test_input
16+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
plugins {
2+
id 'airbyte-python'
3+
id 'airbyte-docker'
4+
id 'airbyte-source-acceptance-test'
5+
}
6+
7+
airbytePython {
8+
moduleDirectory 'source_commcare'
9+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#
2+
# Copyright (c) 2022 Airbyte, Inc., all rights reserved.
3+
#
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"Assess a referred patient": {
3+
"indexed_on": "2023-11-25T20:30:30.2423"
4+
}
5+
}

0 commit comments

Comments
 (0)