Skip to content

Commit

Permalink
🎉Source WooCommerce: migrate to low-code (#19903)
Browse files Browse the repository at this point in the history
* Source WooCommerce: migrate to low-code

* Source WooCommerce: docs update

* Source WooCommerce: update release stage

* Source WooCommerce: add expected records

* Source WooCommerce: test fix

* Source WooCommerce: docs update

* Source WooCommerce: fix

* Source WooCommerce: fix; refactor

* Source WooCommerce: fix check stream

* Source WooCommerce: fix tests

* Source Square: test fix

* Source Square: test fix

* Source WooCommerce: fix schemas

* Source WooCommerce: fix schemas

* Source WooCommerce: fix schemas

* Source WooCommerce: fix tests

* Source WooCommerce: update expected records

* Source WooCommerce: fix tests

* Source WooCommerce: fix slice gap: hardcode interval

* Source WooCommerce: schemas formatting

* Source WooCommerce: schemas formatting

* auto-bump connector version

Co-authored-by: Octavia Squidington III <octavia-squidington-iii@users.noreply.github.com>
  • Loading branch information
artem1205 and octavia-squidington-iii authored Dec 16, 2022
1 parent c57689a commit 2de1dca
Show file tree
Hide file tree
Showing 53 changed files with 1,871 additions and 2,243 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1825,11 +1825,11 @@
- name: WooCommerce
sourceDefinitionId: 2a2552ca-9f78-4c1c-9eb7-4d0dc66d72df
dockerRepository: airbyte/source-woocommerce
dockerImageTag: 0.1.2
dockerImageTag: 0.2.0
documentationUrl: https://docs.airbyte.com/integrations/sources/woocommerce
icon: woocommerce.svg
sourceType: api
releaseStage: alpha
releaseStage: beta
- name: Workable
sourceDefinitionId: ef3c99c6-9e90-43c8-9517-926cfd978517
dockerRepository: airbyte/source-workable
Expand Down
42 changes: 25 additions & 17 deletions airbyte-config/init/src/main/resources/seed/source_specs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15754,50 +15754,58 @@
supportsNormalization: false
supportsDBT: false
supported_destination_sync_modes: []
- dockerImage: "airbyte/source-woocommerce:0.1.2"
- dockerImage: "airbyte/source-woocommerce:0.2.0"
spec:
documentationUrl: "https://docs.airbyte.com/integrations/sources/woocommerce"
connectionSpecification:
$schema: "http://json-schema.org/draft-07/schema#"
title: "Woocommerce Source CDK Specifications"
title: "Woocommerce Spec"
type: "object"
required:
- "shop"
- "start_date"
- "api_key"
- "api_secret"
additionalProperties: false
- "shop"
- "start_date"
additionalProperties: true
properties:
api_key:
type: "string"
title: "Customer Key"
description: "Customer Key for API in WooCommerce shop"
airbyte_secret: true
order: 0
api_secret:
type: "string"
title: "Customer Secret"
description: "Customer Secret for API in WooCommerce shop"
airbyte_secret: true
order: 1
shop:
type: "string"
title: "Shop Name"
description: "The name of the store. For https://EXAMPLE.com, the shop name\
\ is 'EXAMPLE.com'."
order: 2
start_date:
type: "string"
description: "The date you would like to replicate data. Format: YYYY-MM-DD."
title: "Start Date"
description: "The date you would like to replicate data from. Format: YYYY-MM-DD"
examples:
- "2021-01-01"
pattern: "^[0-9]{4}-[0-9]{2}-[0-9]{2}$"
api_key:
type: "string"
description: "The CUSTOMER KEY for API in WooCommerce shop."
airbyte_secret: true
api_secret:
type: "string"
description: "The CUSTOMER SECRET for API in WooCommerce shop."
airbyte_secret: true
order: 3
conversion_window_days:
title: "Conversion Window"
type: "integer"
title: "Conversion Window"
description: "A conversion window is the period of time after an ad interaction\
\ (such as an ad click or video view) during which a conversion, such\
\ as a purchase, is recorded in Google Ads."
\ as a purchase, is recorded in Google Ads"
order: 4
minimum: 0
maximum: 1095
default: 0
examples:
- 14
order: 5
supportsNormalization: false
supportsDBT: false
supported_destination_sync_modes: []
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
*
!Dockerfile
!Dockerfile.test
!main.py
!source_woocommerce
!setup.py
Expand Down
36 changes: 29 additions & 7 deletions airbyte-integrations/connectors/source-woocommerce/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,38 @@
FROM python:3.9-slim
FROM python:3.9.11-alpine3.15 as base

# build and load all requirements
FROM base as builder
WORKDIR /airbyte/integration_code

# upgrade pip to the latest version
RUN apk --no-cache upgrade \
&& pip install --upgrade pip \
&& apk --no-cache add tzdata build-base

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

COPY setup.py ./
# install necessary packages to a temporary folder
RUN pip install --prefix=/install .

# build a clean environment
FROM base
WORKDIR /airbyte/integration_code
COPY source_woocommerce ./source_woocommerce

# copy all loaded and built libraries to a pure basic image
COPY --from=builder /install /usr/local
# add default timezone settings
COPY --from=builder /usr/share/zoneinfo/Etc/UTC /etc/localtime
RUN echo "Etc/UTC" > /etc/timezone

# bash is installed for more convenient debugging.
RUN apk --no-cache add bash

# copy payload code only
COPY main.py ./
COPY setup.py ./
RUN pip install .
COPY source_woocommerce ./source_woocommerce

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.2.0
LABEL io.airbyte.name=airbyte/source-woocommerce
58 changes: 3 additions & 55 deletions airbyte-integrations/connectors/source-woocommerce/README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,10 @@
# Woocommerce Source

This is the repository for the Woocommerce source connector, written in Python.
This is the repository for the Woocommerce configuration based source connector.
For information about how to use this connector within Airbyte, see [the documentation](https://docs.airbyte.io/integrations/sources/woocommerce).

## Local development

### Prerequisites
**To iterate on this connector, make sure to complete this prerequisites section.**

#### Minimum Python version required `= 3.7.0`

#### Build & Activate Virtual Environment and install dependencies
From this connector directory, create a virtual environment:
```
python -m venv .venv
```

This will generate a virtualenv for this module in `.venv/`. Make sure this venv is active in your
development environment of choice. To activate it from the terminal, run:
```
source .venv/bin/activate
pip install -r requirements.txt
```
If you are in an IDE, follow your IDE's instructions to activate the virtualenv.

Note that while we are installing dependencies from `requirements.txt`, you should only edit `setup.py` for your dependencies. `requirements.txt` is
used for editable installs (`pip install -e`) to pull in Python dependencies from the monorepo and will call `setup.py`.
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
should work as you expect.

#### Building via Gradle
You can also build the connector in Gradle. This is typically used in CI and not needed for your development workflow.

Expand All @@ -39,21 +15,13 @@ To build using Gradle, from the Airbyte repository root, run:

#### Create credentials
**If you are a community contributor**, follow the instructions in the [documentation](https://docs.airbyte.io/integrations/sources/woocommerce)
to generate the necessary credentials. Then create a file `secrets/config.json` conforming to the `source_woocommerce/spec.json` file.
to generate the necessary credentials. Then create a file `secrets/config.json` conforming to the `source_woocommerce/spec.yaml` file.
Note that any directory named `secrets` is gitignored across the entire Airbyte repo, so there is no danger of accidentally checking in sensitive information.
See `integration_tests/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 woocommerce test creds`
and place them into `secrets/config.json`.

### Locally running the connector
```
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 integration_tests/configured_catalog.json
```

### Locally running the connector docker image

#### Build
Expand All @@ -78,31 +46,11 @@ docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-woocommerce:dev discov
docker run --rm -v $(pwd)/secrets:/secrets -v $(pwd)/integration_tests:/integration_tests airbyte/source-woocommerce:dev read --config /secrets/config.json --catalog /integration_tests/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
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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
#
# Copyright (c) 2022 Airbyte, Inc., all rights reserved.
#


def test_example_method():
assert True
Original file line number Diff line number Diff line change
@@ -1,24 +1,39 @@
# See [Source Acceptance Tests](https://docs.airbyte.com/contributing-to-airbyte/building-new-connector/source-acceptance-tests.md)
# See [Source Acceptance Tests](https://docs.airbyte.com/connector-development/testing-connectors/source-acceptance-tests-reference)
# for more information about how to configure these tests
connector_image: airbyte/source-woocommerce:dev
tests:
acceptance_tests:
spec:
- spec_path: "source_woocommerce/spec.json"
tests:
- spec_path: "source_woocommerce/spec.yaml"
connection:
- config_path: "secrets/config.json"
status: "succeed"
- config_path: "integration_tests/invalid_config.json"
status: "failed"
tests:
- config_path: "secrets/config.json"
status: "succeed"
- config_path: "integration_tests/invalid_config.json"
status: "failed"
timeout_seconds: 300
discovery:
- config_path: "secrets/config.json"
tests:
- config_path: "secrets/config.json"
backward_compatibility_tests_config:
disable_for_version: "0.1.2"
basic_read:
- config_path: "secrets/config.json"
configured_catalog_path: "integration_tests/configured_catalog.json"
empty_streams: []
incremental: # TODO if your connector does not implement incremental sync, remove this block
- config_path: "secrets/config.json"
configured_catalog_path: "integration_tests/configured_catalog.json"
future_state_path: "integration_tests/abnormal_state.json"
tests:
- config_path: "secrets/config.json"
configured_catalog_path: "integration_tests/configured_catalog.json"
timeout_seconds: 3600
expect_records:
path: "integration_tests/expected_records.txt"
extra_fields: no
exact_order: no
extra_records: no
incremental:
tests:
- config_path: "secrets/config.json"
configured_catalog_path: "integration_tests/configured_catalog.json"
future_state:
future_state_path: "integration_tests/abnormal_state.json"
full_refresh:
- config_path: "secrets/config.json"
configured_catalog_path: "integration_tests/configured_catalog.json"
tests:
- config_path: "secrets/config.json"
configured_catalog_path: "integration_tests/configured_catalog.json"
9 changes: 9 additions & 0 deletions airbyte-integrations/connectors/source-woocommerce/acceptance-test-docker.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +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

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#
# Copyright (c) 2022 Airbyte, Inc., all rights reserved.
#
Original file line number Diff line number Diff line change
@@ -1,11 +1,46 @@
{
"customers": {
"date_created": "2030-07-30T22:16:46"
[
{
"type": "STREAM",
"stream": {
"stream_state": {
"date_modified_gmt": "2100-01-01T00:00:00"
},
"stream_descriptor": {
"name": "coupons"
}
}
},
"orders": {
"date_modified": "2050-07-30T22:16:46"
{
"type": "STREAM",
"stream": {
"stream_state": {
"date_modified_gmt": "2100-01-01T00:00:00"
},
"stream_descriptor": {
"name": "orders"
}
}
},
"coupons": {
"date_modified": "2060-07-30T22:16:46"
{
"type": "STREAM",
"stream": {
"stream_state": {
"date_modified_gmt": "2100-01-01T00:00:00"
},
"stream_descriptor": {
"name": "products"
}
}
},
{
"type": "STREAM",
"stream": {
"stream_state": {
"date_created_gmt": "2100-01-01T00:00:00"
},
"stream_descriptor": {
"name": "product_reviews"
}
}
}
}
]
Loading

0 comments on commit 2de1dca

Please sign in to comment.