Skip to content

Commit

Permalink
🐛 Source Zendesk Talk: migrate to CDK (#7173)
Browse files Browse the repository at this point in the history
* Upd pagination edge case
* migrate to CDK and connect SAT
+ added primary key based on datetime.now
+ added unittests

Co-authored-by: Eugene Kulak <kulak.eugene@gmail.com>
  • Loading branch information
gaart and eugene-kulak committed Nov 13, 2021
1 parent 2fe927b commit 5a24ef5
Show file tree
Hide file tree
Showing 38 changed files with 1,067 additions and 1,425 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@
- name: Zendesk Talk
sourceDefinitionId: c8630570-086d-4a40-99ae-ea5b18673071
dockerRepository: airbyte/source-zendesk-talk
dockerImageTag: 0.1.2
dockerImageTag: 0.1.3
documentationUrl: https://docs.airbyte.io/integrations/sources/zendesk-talk
sourceType: api
- sourceDefinitionId: cdaf146a-9b75-49fd-9dd2-9d64a0bb4781
Expand Down
48 changes: 28 additions & 20 deletions airbyte-config/init/src/main/resources/seed/source_specs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5998,41 +5998,49 @@
supportsNormalization: false
supportsDBT: false
supported_destination_sync_modes: []
- dockerImage: "airbyte/source-zendesk-talk:0.1.2"
- dockerImage: "airbyte/source-zendesk-talk:0.1.3"
spec:
documentationUrl: "https://docs.airbyte.io/integrations/sources/zendesk-talk"
changelogUrl: "https://docs.airbyte.io/integrations/sources/zendesk-talk"
connectionSpecification:
$schema: "http://json-schema.org/draft-07/schema#"
title: "Zendesk Talk Spec"
type: "object"
required:
- "start_date"
- "subdomain"
- "access_token"
- "email"
additionalProperties: false
properties:
start_date:
type: "string"
description: "The date from which you'd like to replicate data for Zendesk\
\ Talk API, in the format YYYY-MM-DDT00:00:00Z."
examples:
- "2021-04-01T00:00:00Z"
pattern: "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
subdomain:
title: "Subdomain"
description: "The subdomain for your Zendesk Talk."
type: "string"
description: "The subdomain for your Zendesk Talk"
access_token:
type: "string"
title: "Access Token"
description: "The value of the API token generated. See the <a href=\"https://docs.airbyte.io/integrations/sources/zendesk-talk\"\
>docs</a> for more information"
>docs</a> for more information."
airbyte_secret: true
type: "string"
email:
title: "Email"
description: "The user email for your Zendesk account."
type: "string"
description: "The user email for your Zendesk account"
start_date:
title: "Replication Start Date"
description: "The date/datetime from which you'd like to replicate data\
\ for Zendesk Talk API, in the format YYYY-MM-DDT00:00:00Z. The time part\
\ is optional."
pattern: "^[0-9]{4}-[0-9]{2}-[0-9]{2}(T[0-9]{2}:[0-9]{2}:[0-9]{2}Z)?$"
examples:
- "2017-01-25T00:00:00Z"
- "2017-01-25"
type: "string"
format: "date-time"
required:
- "subdomain"
- "access_token"
- "email"
- "start_date"
supportsIncremental: true
supportsNormalization: false
supportsDBT: false
supported_destination_sync_modes: []
supported_destination_sync_modes:
- "append"
- dockerImage: "airbyte/source-sentry:0.1.0"
spec:
documentationUrl: "https://docs.airbyte.io/integrations/sources/sentry"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
*
!Dockerfile
!Dockerfile.test
!main.py
!source_zendesk_talk
!setup.py
!secrets
14 changes: 6 additions & 8 deletions airbyte-integrations/connectors/source-zendesk-talk/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
FROM airbyte/integration-base-python:0.1.1
FROM python:3.7-slim

# Bash is installed for more convenient debugging.
RUN apt-get update && apt-get install -y bash && rm -rf /var/lib/apt/lists/*

ENV CODE_PATH="source_zendesk_talk"
ENV AIRBYTE_IMPL_MODULE="source_zendesk_talk"
ENV AIRBYTE_IMPL_PATH="SourceZendeskTalk"

WORKDIR /airbyte/integration_code
COPY $CODE_PATH ./$CODE_PATH
COPY source_zendesk_talk ./source_zendesk_talk
COPY main.py ./
COPY setup.py ./
RUN pip install .

ENV AIRBYTE_ENTRYPOINT "/airbyte/base.sh"
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]

LABEL io.airbyte.version=0.1.2
LABEL io.airbyte.version=0.1.3
LABEL io.airbyte.name=airbyte/source-zendesk-talk
63 changes: 46 additions & 17 deletions airbyte-integrations/connectors/source-zendesk-talk/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Zendesk Talk Source
# Zendesk Talk Source

This is the repository for the Zendesk Talk source connector, written in Python.
This is the repository for the Zendesk Talk source connector, written in Python.
For information about how to use this connector within Airbyte, see [the documentation](https://docs.airbyte.io/integrations/sources/zendesk-talk).

## Local development
Expand Down Expand Up @@ -44,19 +44,12 @@ See `sample_files/sample_config.json` for a sample config file.
**If you are an Airbyte core member**, copy the credentials in Lastpass under the secret name `source zendesk-talk test creds`
and place them into `secrets/config.json`.


### Locally running the connector
```
python main_dev.py spec
python main_dev.py check --config secrets/config.json
python main_dev.py discover --config secrets/config.json
python main_dev.py read --config secrets/config.json --catalog sample_files/configured_catalog.json
```

### Unit Tests
To run unit tests locally, from the connector directory run:
```
python -m pytest unit_tests
python main.py spec
python main.py check --config secrets/config.json
python main.py discover --config secrets/config.json
python main.py read --config secrets/config.json --catalog sample_files/configured_catalog.json
```

### Locally running the connector docker image
Expand All @@ -82,19 +75,55 @@ docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-zendesk-talk:dev check
docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-zendesk-talk:dev discover --config /secrets/config.json
docker run --rm -v $(pwd)/secrets:/secrets -v $(pwd)/sample_files:/sample_files airbyte/source-zendesk-talk:dev read --config /secrets/config.json --catalog /sample_files/configured_catalog.json
```
## Testing
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.
First install test dependencies into your virtual environment:
```
pip install .[tests]
```
### Unit Tests
To run unit tests locally, from the connector directory run:
```
python -m pytest unit_tests
```

### Integration Tests
1. From the airbyte project root, run `./gradlew :airbyte-integrations:connectors:source-zendesk-talk:integrationTest` to run the standard integration test suite.
1. To run additional integration tests, place your integration tests in a new directory `integration_tests` and run them with `python -m pytest -s integration_tests`.
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.
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).
#### Custom Integration tests
Place custom tests inside `integration_tests/` folder, then, from the connector root, run
```
python -m pytest integration_tests
```
#### Acceptance Tests
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.
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.
To run your integration tests with acceptance tests, from the connector root, run
```
python -m pytest integration_tests -p integration_tests.acceptance
```
To run your integration tests with docker

### Using gradle to run tests
All commands should be run from airbyte project root.
To run unittest run:
```
./gradlew :airbyte-integrations:connectors:source-zendesk-talk:unitTest
```
To run acceptance and custom integration tests run:
```
./gradlew :airbyte-integrations:connectors:source-zendesk-talk:IntegrationTest
```

## Dependency Management
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.
We split dependencies between two groups, dependencies that are:
* required for your connector to work need to go to `MAIN_REQUIREMENTS` list.
* required for the testing need to go to `TEST_REQUIREMENTS` list

### Publishing a new version of the connector
You've checked out the repo, implemented a million dollar feature, and you're ready to share your changes with the world. Now what?
1. Make sure your changes are passing unit and integration tests
1. Bump the connector version in `Dockerfile` -- just increment the value of the `LABEL io.airbyte.version` appropriately (we use SemVer).
1. Bump the connector version in `Dockerfile` -- just increment the value of the `LABEL io.airbyte.version` appropriately (we use [SemVer](https://semver.org/)).
1. Create a Pull Request
1. Pat yourself on the back for being an awesome contributor
1. Someone from Airbyte will take a look at your PR and iterate with you to merge it into master
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# See [Source Acceptance Tests](https://docs.airbyte.io/connector-development/testing-connectors/source-acceptance-tests-reference)
# for more information about how to configure these tests
# intentionally left out explicit configured_catalog.json to test all streams from discovery
connector_image: airbyte/source-zendesk-talk:dev
tests:
spec:
- spec_path: "integration_tests/spec.json"
connection:
- config_path: "secrets/config.json"
status: "succeed"
- config_path: "integration_tests/invalid_config.json"
status: "failed"
discovery:
- config_path: "secrets/config.json"
basic_read:
- config_path: "secrets/config.json"
incremental:
- config_path: "secrets/config.json"
future_state_path: "integration_tests/abnormal_state.json"
full_refresh:
- config_path: "secrets/config.json"
# Statistics streams (with single record) have artificial PK that changes everytime
ignored_fields:
"account_overview": ["current_timestamp"]
"agents_overview": ["current_timestamp"]
"current_queue_activity": ["current_timestamp"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env sh

# Build latest connector image
docker build . -t $(cat acceptance-test-config.yml | grep "connector_image" | head -n 1 | cut -d: -f2)

# Pull latest acctest image
docker pull airbyte/source-acceptance-test:latest

# Run
docker run --rm -it \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /tmp:/tmp \
-v $(pwd):/test_input \
airbyte/source-acceptance-test \
--acceptance-test-config /test_input

18 changes: 2 additions & 16 deletions airbyte-integrations/connectors/source-zendesk-talk/build.gradle
Original file line number Diff line number Diff line change
@@ -1,27 +1,13 @@
plugins {
id 'airbyte-python'
id 'airbyte-docker'
id 'airbyte-standard-source-test-file'
id 'airbyte-source-acceptance-test'
}

airbytePython {
moduleDirectory 'source_zendesk_talk'
}

airbyteStandardSourceTestFile {
specPath = "source_zendesk_talk/spec.json"
configPath = "secrets/config.json"
configuredCatalogPath = "sample_files/configured_catalog.json"
}

task("pythonIntegrationTests", type: PythonTask, dependsOn: installTestReqs) {
module = "pytest"
command = "-s integration_tests"
}

integrationTest.dependsOn("pythonIntegrationTests")

dependencies {
implementation files(project(':airbyte-integrations:bases:base-standard-source-test-file').airbyteDocker.outputs)
implementation files(project(':airbyte-integrations:bases:base-python').airbyteDocker.outputs)
implementation files(project(':airbyte-integrations:bases:source-acceptance-test').airbyteDocker.outputs)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#
# Copyright (c) 2021 Airbyte, Inc., all rights reserved.
#
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"calls": {
"updated_at": "2121-01-01T00:00:00Z"
},
"call_legs": {
"updated_at": "2121-01-01T00:00:00Z"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#
# Copyright (c) 2021 Airbyte, Inc., all rights reserved.
#


import pytest

pytest_plugins = ("source_acceptance_test.plugin",)


@pytest.fixture(scope="session", autouse=True)
def connector_setup():
"""This fixture is a placeholder for external resources that acceptance test might require."""
yield
Loading

0 comments on commit 5a24ef5

Please sign in to comment.