diff --git a/airbyte-integrations/connectors/source-junip-reviews/.dockerignore b/airbyte-integrations/connectors/source-junip-reviews/.dockerignore new file mode 100644 index 000000000000..243f65234f7a --- /dev/null +++ b/airbyte-integrations/connectors/source-junip-reviews/.dockerignore @@ -0,0 +1,6 @@ +* +!Dockerfile +!main.py +!source_junip_reviews +!setup.py +!secrets diff --git a/airbyte-integrations/connectors/source-junip-reviews/Dockerfile b/airbyte-integrations/connectors/source-junip-reviews/Dockerfile new file mode 100644 index 000000000000..46c60cb6c393 --- /dev/null +++ b/airbyte-integrations/connectors/source-junip-reviews/Dockerfile @@ -0,0 +1,38 @@ +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 + + +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 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 source_junip_reviews ./source_junip_reviews + +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.name=airbyte/source-junip-reviews diff --git a/airbyte-integrations/connectors/source-junip-reviews/README.md b/airbyte-integrations/connectors/source-junip-reviews/README.md new file mode 100644 index 000000000000..f677d2582e2b --- /dev/null +++ b/airbyte-integrations/connectors/source-junip-reviews/README.md @@ -0,0 +1,132 @@ +# Junip Reviews Source + +This is the repository for the Junip Reviews source connector, written in Python. +For information about how to use this connector within Airbyte, see [the documentation](https://junip.co/docs/api/). + +## 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 +pip install '.[tests]' +``` +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. + +To build using Gradle, from the Airbyte repository root, run: +``` +./gradlew :airbyte-integrations:connectors:source-junip-reviews:build +``` + +#### Create credentials +**If you are a community contributor**, follow the instructions in the [documentation](https://docs.airbyte.io/integrations/sources/junip-reviews) +to generate the necessary credentials. Then create a file `secrets/config.json` conforming to the `source_junip_reviews/spec.json` 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 junip-reviews 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 +First, make sure you build the latest Docker image: +``` +docker build . -t ghilman17/source-junip-reviews:0.1 +``` + +You can also build the connector image via Gradle: +``` +./gradlew :airbyte-integrations:connectors:source-junip-reviews:airbyteDocker +``` +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 +the Dockerfile. + +#### Run +Then run any of the connector commands as follows: +``` +docker run --rm airbyte/source-junip-reviews:dev spec +docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-junip-reviews:dev check --config /secrets/config.json +docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-junip-reviews:dev discover --config /secrets/config.json +docker run --rm -v $(pwd)/secrets:/secrets -v $(pwd)/integration_tests:/integration_tests airbyte/source-junip-reviews: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 +All commands should be run from airbyte project root. +To run unit tests: +``` +./gradlew :airbyte-integrations:connectors:source-junip-reviews:unitTest +``` +To run acceptance and custom integration tests: +``` +./gradlew :airbyte-integrations:connectors:source-junip-reviews: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](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. diff --git a/airbyte-integrations/connectors/source-junip-reviews/acceptance-test-config.yml b/airbyte-integrations/connectors/source-junip-reviews/acceptance-test-config.yml new file mode 100644 index 000000000000..4c4ff991cde9 --- /dev/null +++ b/airbyte-integrations/connectors/source-junip-reviews/acceptance-test-config.yml @@ -0,0 +1,24 @@ +# 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 +connector_image: airbyte/source-junip-reviews:dev +tests: + spec: + - spec_path: "source_junip_reviews/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" + configured_catalog_path: "integration_tests/configured_catalog.json" + empty_streams: [] + incremental: + - config_path: "secrets/config.json" + configured_catalog_path: "integration_tests/configured_catalog.json" + future_state_path: "integration_tests/abnormal_state.json" + full_refresh: + - config_path: "secrets/config.json" + configured_catalog_path: "integration_tests/configured_catalog.json" diff --git a/airbyte-integrations/connectors/source-junip-reviews/acceptance-test-docker.sh b/airbyte-integrations/connectors/source-junip-reviews/acceptance-test-docker.sh new file mode 100644 index 000000000000..c51577d10690 --- /dev/null +++ b/airbyte-integrations/connectors/source-junip-reviews/acceptance-test-docker.sh @@ -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 + diff --git a/airbyte-integrations/connectors/source-junip-reviews/build.gradle b/airbyte-integrations/connectors/source-junip-reviews/build.gradle new file mode 100644 index 000000000000..9fe15a2a7580 --- /dev/null +++ b/airbyte-integrations/connectors/source-junip-reviews/build.gradle @@ -0,0 +1,9 @@ +plugins { + id 'airbyte-python' + id 'airbyte-docker' + id 'airbyte-source-acceptance-test' +} + +airbytePython { + moduleDirectory 'source_junip_reviews' +} diff --git a/airbyte-integrations/connectors/source-junip-reviews/integration_tests/__init__.py b/airbyte-integrations/connectors/source-junip-reviews/integration_tests/__init__.py new file mode 100644 index 000000000000..46b7376756ec --- /dev/null +++ b/airbyte-integrations/connectors/source-junip-reviews/integration_tests/__init__.py @@ -0,0 +1,3 @@ +# +# Copyright (c) 2021 Airbyte, Inc., all rights reserved. +# diff --git a/airbyte-integrations/connectors/source-junip-reviews/integration_tests/abnormal_state.json b/airbyte-integrations/connectors/source-junip-reviews/integration_tests/abnormal_state.json new file mode 100644 index 000000000000..8b137891791f --- /dev/null +++ b/airbyte-integrations/connectors/source-junip-reviews/integration_tests/abnormal_state.json @@ -0,0 +1 @@ + diff --git a/airbyte-integrations/connectors/source-junip-reviews/integration_tests/acceptance.py b/airbyte-integrations/connectors/source-junip-reviews/integration_tests/acceptance.py new file mode 100644 index 000000000000..c1f0803ff9a6 --- /dev/null +++ b/airbyte-integrations/connectors/source-junip-reviews/integration_tests/acceptance.py @@ -0,0 +1,15 @@ +# +# 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 + diff --git a/airbyte-integrations/connectors/source-junip-reviews/integration_tests/catalog.json b/airbyte-integrations/connectors/source-junip-reviews/integration_tests/catalog.json new file mode 100644 index 000000000000..2bc1957c363c --- /dev/null +++ b/airbyte-integrations/connectors/source-junip-reviews/integration_tests/catalog.json @@ -0,0 +1,330 @@ +{ + "streams": [ + { + "name": "products", + "source_defined_cursor": true, + "json_schema": { + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "created_at": { + "type": "string", + "examples": [ + "2021-06-18T18:24:48.702Z" + ] + }, + "deleted_at": { + "type": "string", + "examples": [ + "2021-06-18T18:24:48.702Z" + ] + }, + "rating_average": { + "type": "number" + }, + "rating_count": { + "type": "integer" + }, + "rating_distribution": { + "type": "object" + }, + "recommended_count": { + "type": "integer" + }, + "remote_handle": { + "type": "string" + }, + "remote_id": { + "type": "string" + }, + "title": { + "type": "string" + }, + "unreviewable": { + "type": "boolean" + }, + "updated_at": { + "type": "string", + "examples": [ + "2021-06-18T18:24:48.702Z" + ] + } + } + }, + "supported_sync_modes": [ + "full_refresh" + ], + "default_cursor_field": ["created_at"], + "source_defined_primary_key": [["id"]] + }, + { + "name": "product_overviews", + "source_defined_cursor": true, + "json_schema": { + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "created_at": { + "type": "string", + "examples": [ + "2021-06-18T18:24:48.702Z" + ] + }, + "deleted_at": { + "type": "string", + "examples": [ + "2021-06-18T18:24:48.702Z" + ] + }, + "rating_average": { + "type": "number" + }, + "rating_count": { + "type": "integer" + }, + "rating_distribution": { + "type": "object" + }, + "recommended_count": { + "type": "integer" + }, + "updated_at": { + "type": "string", + "examples": [ + "2021-06-18T18:24:48.702Z" + ] + } + } + }, + "supported_sync_modes": [ + "full_refresh" + ], + "default_cursor_field": ["created_at"], + "source_defined_primary_key": [["id"]] + }, + { + "name": "product_reviews", + "source_defined_cursor": true, + "json_schema": { + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "body": { + "type": [ + "null", + "string" + ] + }, + "created_at": { + "type": "string", + "examples": [ + "2021-06-18T18:25:07.033Z" + ] + }, + "customer_id": { + "type": "integer" + }, + "down_vote_count": { + "type": "integer" + }, + "featured": { + "type": "boolean" + }, + "product_id": { + "type": "integer" + }, + "rating": { + "type": "integer" + }, + "response": { + "type": [ + "null", + "object" + ] + }, + "target_title": { + "type": "string" + }, + "title": { + "type": [ + "string", + "null" + ] + }, + "up_vote_count": { + "type": "integer" + }, + "updated_at": { + "type": "string", + "examples": [ + "2021-06-18T18:25:07.033Z" + ] + }, + "verified_buyer": { + "type": "boolean" + }, + "would_recommend": { + "type": [ + "null", + "string" + ] + }, + "photo_urls": { + "type": "array" + }, + "video_urls": { + "type": "array" + } + } + }, + "supported_sync_modes": [ + "full_refresh" + ], + "default_cursor_field": ["created_at"], + "source_defined_primary_key": [["id"]] + }, + { + "name": "stores", + "source_defined_cursor": true, + "json_schema": { + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "created_at": { + "type": "string", + "examples": [ + "2021-06-18T18:25:17.951Z" + ] + }, + "key": { + "type": "string" + }, + "name": { + "type": "string" + }, + "rating_average": { + "type": "number" + }, + "rating_count": { + "type": "number" + }, + "rating_distribution": { + "type": "object" + }, + "recommended_count": { + "type": "integer" + }, + "slug": { + "type": "string" + }, + "updated_at": { + "type": "string", + "examples": [ + "2021-06-18T18:25:17.951Z" + ] + }, + "url": { + "type": "string" + } + } + }, + "supported_sync_modes": [ + "full_refresh" + ], + "default_cursor_field": ["created_at"], + "source_defined_primary_key": [["id"]] + }, + { + "name": "store_reviews", + "json_schema": { + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "body": { + "type": [ + "null", + "object" + ] + }, + "created_at": { + "type": "string", + "examples": [ + "2021-06-18T18:25:16.161Z" + ] + }, + "customer_id": { + "type": "integer" + }, + "down_vote_count": { + "type": "number" + }, + "featured": { + "type": "boolean" + }, + "rating": { + "type": "number" + }, + "response": { + "type": [ + "null", + "object" + ] + }, + "target_title": { + "type": "string" + }, + "title": { + "type": [ + "null", + "string" + ] + }, + "up_vote_count": { + "type": "integer" + }, + "updated_at": { + "type": "string", + "examples": [ + "2021-06-18T18:25:16.161Z" + ] + }, + "verified_buyer": { + "type": "boolean" + }, + "would_recommend": { + "type": [ + "null", + "string" + ] + }, + "photo_urls": { + "type": "array" + }, + "video_urls": { + "type": "array" + } + } + }, + "supported_sync_modes": [ + "full_refresh" + ], + "default_cursor_field": ["created_at"], + "source_defined_primary_key": [["id"]] + } + ] +} diff --git a/airbyte-integrations/connectors/source-junip-reviews/integration_tests/configured_catalog.json b/airbyte-integrations/connectors/source-junip-reviews/integration_tests/configured_catalog.json new file mode 100644 index 000000000000..8f790ac53285 --- /dev/null +++ b/airbyte-integrations/connectors/source-junip-reviews/integration_tests/configured_catalog.json @@ -0,0 +1,311 @@ +{ + "streams": [ + { + "stream": { + "name": "products", + "json_schema": { + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "created_at": { + "type": "string", + "examples": [ + "2021-06-18T18:24:48.702Z" + ] + }, + "deleted_at": { + "type": "string", + "examples": [ + "2021-06-18T18:24:48.702Z" + ] + }, + "rating_average": { + "type": "number" + }, + "rating_count": { + "type": "integer" + }, + "rating_distribution": { + "type": "object" + }, + "recommended_count": { + "type": "integer" + }, + "remote_handle": { + "type": "string" + }, + "remote_id": { + "type": "string" + }, + "title": { + "type": "string" + }, + "unreviewable": { + "type": "boolean" + }, + "updated_at": { + "type": "string", + "examples": [ + "2021-06-18T18:24:48.702Z" + ] + } + } + }, + "supported_sync_modes": [ + "full_refresh" + ] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "append_dedup" + }, + { + "stream": { + "name": "product_overviews", + "json_schema": { + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "created_at": { + "type": "string", + "examples": [ + "2021-06-18T18:24:48.702Z" + ] + }, + "deleted_at": { + "type": "string", + "examples": [ + "2021-06-18T18:24:48.702Z" + ] + }, + "rating_average": { + "type": "number" + }, + "rating_count": { + "type": "integer" + }, + "rating_distribution": { + "type": "object" + }, + "recommended_count": { + "type": "integer" + }, + "updated_at": { + "type": "string", + "examples": [ + "2021-06-18T18:24:48.702Z" + ] + } + } + }, + "supported_sync_modes": [ + "full_refresh", + "incremental" + ] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "append_dedup" + }, + { + "stream": { + "name": "product_reviews", + "json_schema": { + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "body": { + "type": [ + "null", + "string" + ] + }, + "created_at": { + "type": "string", + "examples": [ + "2021-06-18T18:25:07.033Z" + ] + }, + "customer_id": { + "type": "integer" + }, + "down_vote_count": { + "type": "integer" + }, + "featured": { + "type": "boolean" + }, + "product_id": { + "type": "integer" + }, + "rating": { + "type": "integer" + }, + "response": { + "type": [ + "null", + "object" + ] + }, + "target_title": { + "type": "string" + }, + "title": { + "type": [ + "string", + "null" + ] + }, + "up_vote_count": { + "type": "integer" + }, + "updated_at": { + "type": "string", + "examples": [ + "2021-06-18T18:25:07.033Z" + ] + }, + "verified_buyer": { + "type": "boolean" + }, + "would_recommend": { + "type": [ + "null", + "string" + ] + }, + "photo_urls": { + "type": "array" + }, + "video_urls": { + "type": "array" + } + } + }, + "supported_sync_modes": ["full_refresh", "incremental"] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "append_dedup" + }, + { + "stream": { + "name": "stores", + "json_schema": { + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "created_at": { + "type": "string", + "examples": ["2021-06-18T18:25:17.951Z"] + }, + "key": { + "type": "string" + }, + "name": { + "type": "string" + }, + "rating_average": { + "type": "number" + }, + "rating_count": { + "type": "number" + }, + "rating_distribution": { + "type": "object" + }, + "recommended_count": { + "type": "integer" + }, + "slug": { + "type": "string" + }, + "updated_at": { + "type": "string", + "examples": ["2021-06-18T18:25:17.951Z"] + }, + "url": { + "type": "string" + } + } + }, + "supported_sync_modes": ["full_refresh", "incremental"] + }, + "sync_mode": "incremental", + "destination_sync_mode": "append_dedup" + }, + { + "stream": { + "name": "store_reviews", + "json_schema": { + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "body": { + "type": ["null", "object"] + }, + "created_at": { + "type": "string", + "examples": ["2021-06-18T18:25:16.161Z"] + }, + "customer_id": { + "type": "integer" + }, + "down_vote_count": { + "type": "number" + }, + "featured": { + "type": "boolean" + }, + "rating": { + "type": "number" + }, + "response": { + "type": ["null", "object"] + }, + "target_title": { + "type": "string" + }, + "title": { + "type": ["null", "string"] + }, + "up_vote_count": { + "type": "integer" + }, + "updated_at": { + "type": "string", + "examples": ["2021-06-18T18:25:16.161Z"] + }, + "verified_buyer": { + "type": "boolean" + }, + "would_recommend": { + "type": ["null", "string"] + }, + "photo_urls": { + "type": "array" + }, + "video_urls": { + "type": "array" + } + } + }, + "supported_sync_modes": ["full_refresh", "incremental"] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "append_dedup" + } + ] +} diff --git a/airbyte-integrations/connectors/source-junip-reviews/integration_tests/invalid_config.json b/airbyte-integrations/connectors/source-junip-reviews/integration_tests/invalid_config.json new file mode 100644 index 000000000000..64a18d6a5f50 --- /dev/null +++ b/airbyte-integrations/connectors/source-junip-reviews/integration_tests/invalid_config.json @@ -0,0 +1,3 @@ +{ + "junip_store_key": "234567854454", +} diff --git a/airbyte-integrations/connectors/source-junip-reviews/integration_tests/sample_config.json b/airbyte-integrations/connectors/source-junip-reviews/integration_tests/sample_config.json new file mode 100644 index 000000000000..040b2986df22 --- /dev/null +++ b/airbyte-integrations/connectors/source-junip-reviews/integration_tests/sample_config.json @@ -0,0 +1,3 @@ +{ + "junip_store_key": "" +} diff --git a/airbyte-integrations/connectors/source-junip-reviews/integration_tests/sample_state.json b/airbyte-integrations/connectors/source-junip-reviews/integration_tests/sample_state.json new file mode 100644 index 000000000000..8b137891791f --- /dev/null +++ b/airbyte-integrations/connectors/source-junip-reviews/integration_tests/sample_state.json @@ -0,0 +1 @@ + diff --git a/airbyte-integrations/connectors/source-junip-reviews/main.py b/airbyte-integrations/connectors/source-junip-reviews/main.py new file mode 100644 index 000000000000..d274d0445ddc --- /dev/null +++ b/airbyte-integrations/connectors/source-junip-reviews/main.py @@ -0,0 +1,13 @@ +# +# Copyright (c) 2021 Airbyte, Inc., all rights reserved. +# + + +import sys + +from airbyte_cdk.entrypoint import launch +from source_junip_reviews import SourceJunipReviews + +if __name__ == "__main__": + source = SourceJunipReviews() + launch(source, sys.argv[1:]) diff --git a/airbyte-integrations/connectors/source-junip-reviews/requirements.txt b/airbyte-integrations/connectors/source-junip-reviews/requirements.txt new file mode 100644 index 000000000000..0411042aa091 --- /dev/null +++ b/airbyte-integrations/connectors/source-junip-reviews/requirements.txt @@ -0,0 +1,2 @@ +-e ../../bases/source-acceptance-test +-e . diff --git a/airbyte-integrations/connectors/source-junip-reviews/sample_files/configured_catalog.json b/airbyte-integrations/connectors/source-junip-reviews/sample_files/configured_catalog.json new file mode 100644 index 000000000000..4ec5a4458a38 --- /dev/null +++ b/airbyte-integrations/connectors/source-junip-reviews/sample_files/configured_catalog.json @@ -0,0 +1,312 @@ +{ + "streams": [ + { + "stream": { + "name": "products", + "json_schema": { + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "created_at": { + "type": "string", + "examples": [ + "2021-06-18T18:24:48.702Z" + ] + }, + "deleted_at": { + "type": "string", + "examples": [ + "2021-06-18T18:24:48.702Z" + ] + }, + "rating_average": { + "type": "number" + }, + "rating_count": { + "type": "integer" + }, + "rating_distribution": { + "type": "object" + }, + "recommended_count": { + "type": "integer" + }, + "remote_handle": { + "type": "string" + }, + "remote_id": { + "type": "string" + }, + "title": { + "type": "string" + }, + "unreviewable": { + "type": "boolean" + }, + "updated_at": { + "type": "string", + "examples": [ + "2021-06-18T18:24:48.702Z" + ] + } + } + }, + "supported_sync_modes": [ + "full_refresh", + "incremental" + ] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "append_dedup" + }, + { + "stream": { + "name": "product_overviews", + "json_schema": { + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "created_at": { + "type": "string", + "examples": [ + "2021-06-18T18:24:48.702Z" + ] + }, + "deleted_at": { + "type": "string", + "examples": [ + "2021-06-18T18:24:48.702Z" + ] + }, + "rating_average": { + "type": "number" + }, + "rating_count": { + "type": "integer" + }, + "rating_distribution": { + "type": "object" + }, + "recommended_count": { + "type": "integer" + }, + "updated_at": { + "type": "string", + "examples": [ + "2021-06-18T18:24:48.702Z" + ] + } + } + }, + "supported_sync_modes": [ + "full_refresh", + "incremental" + ] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "append_dedup" + }, + { + "stream": { + "name": "product_reviews", + "json_schema": { + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "body": { + "type": [ + "null", + "string" + ] + }, + "created_at": { + "type": "string", + "examples": [ + "2021-06-18T18:25:07.033Z" + ] + }, + "customer_id": { + "type": "integer" + }, + "down_vote_count": { + "type": "integer" + }, + "featured": { + "type": "boolean" + }, + "product_id": { + "type": "integer" + }, + "rating": { + "type": "integer" + }, + "response": { + "type": [ + "null", + "object" + ] + }, + "target_title": { + "type": "string" + }, + "title": { + "type": [ + "string", + "null" + ] + }, + "up_vote_count": { + "type": "integer" + }, + "updated_at": { + "type": "string", + "examples": [ + "2021-06-18T18:25:07.033Z" + ] + }, + "verified_buyer": { + "type": "boolean" + }, + "would_recommend": { + "type": [ + "null", + "string" + ] + }, + "photo_urls": { + "type": "array" + }, + "video_urls": { + "type": "array" + } + } + }, + "supported_sync_modes": ["full_refresh", "incremental"] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "append_dedup" + }, + { + "stream": { + "name": "stores", + "json_schema": { + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "created_at": { + "type": "string", + "examples": ["2021-06-18T18:25:17.951Z"] + }, + "key": { + "type": "string" + }, + "name": { + "type": "string" + }, + "rating_average": { + "type": "number" + }, + "rating_count": { + "type": "number" + }, + "rating_distribution": { + "type": "object" + }, + "recommended_count": { + "type": "integer" + }, + "slug": { + "type": "string" + }, + "updated_at": { + "type": "string", + "examples": ["2021-06-18T18:25:17.951Z"] + }, + "url": { + "type": "string" + } + } + }, + "supported_sync_modes": ["full_refresh", "incremental"] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "append_dedup" + }, + { + "stream": { + "name": "store_reviews", + "json_schema": { + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "body": { + "type": ["null", "object"] + }, + "created_at": { + "type": "string", + "examples": ["2021-06-18T18:25:16.161Z"] + }, + "customer_id": { + "type": "integer" + }, + "down_vote_count": { + "type": "number" + }, + "featured": { + "type": "boolean" + }, + "rating": { + "type": "number" + }, + "response": { + "type": ["null", "object"] + }, + "target_title": { + "type": "string" + }, + "title": { + "type": ["null", "string"] + }, + "up_vote_count": { + "type": "integer" + }, + "updated_at": { + "type": "string", + "examples": ["2021-06-18T18:25:16.161Z"] + }, + "verified_buyer": { + "type": "boolean" + }, + "would_recommend": { + "type": ["null", "string"] + }, + "photo_urls": { + "type": "array" + }, + "video_urls": { + "type": "array" + } + } + }, + "supported_sync_modes": ["full_refresh", "incremental"] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "append_dedup" + } + ] +} diff --git a/airbyte-integrations/connectors/source-junip-reviews/setup.py b/airbyte-integrations/connectors/source-junip-reviews/setup.py new file mode 100644 index 000000000000..f9d34e7df542 --- /dev/null +++ b/airbyte-integrations/connectors/source-junip-reviews/setup.py @@ -0,0 +1,29 @@ +# +# Copyright (c) 2021 Airbyte, Inc., all rights reserved. +# + + +from setuptools import find_packages, setup + +MAIN_REQUIREMENTS = [ + "airbyte-cdk~=0.1", +] + +TEST_REQUIREMENTS = [ + "pytest~=6.1", + "pytest-mock~=3.6.1", + "source-acceptance-test", +] + +setup( + name="source_junip_reviews", + description="Source implementation for Junip Reviews.", + author="Ghilman Randhawa", + author_email="ghilman.randhawa@cogentlabs.co", + packages=find_packages(), + install_requires=MAIN_REQUIREMENTS, + package_data={"": ["*.json", "schemas/*.json", "schemas/shared/*.json"]}, + extras_require={ + "tests": TEST_REQUIREMENTS, + }, +) diff --git a/airbyte-integrations/connectors/source-junip-reviews/source_junip_reviews/__init__.py b/airbyte-integrations/connectors/source-junip-reviews/source_junip_reviews/__init__.py new file mode 100644 index 000000000000..b756c7dbb17d --- /dev/null +++ b/airbyte-integrations/connectors/source-junip-reviews/source_junip_reviews/__init__.py @@ -0,0 +1,8 @@ +# +# Copyright (c) 2021 Airbyte, Inc., all rights reserved. +# + + +from .source import SourceJunipReviews + +__all__ = ["SourceJunipReviews"] diff --git a/airbyte-integrations/connectors/source-junip-reviews/source_junip_reviews/schemas/product_overviews.json b/airbyte-integrations/connectors/source-junip-reviews/source_junip_reviews/schemas/product_overviews.json new file mode 100644 index 000000000000..c6bf8f480f8e --- /dev/null +++ b/airbyte-integrations/connectors/source-junip-reviews/source_junip_reviews/schemas/product_overviews.json @@ -0,0 +1,33 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "created_at": { + "type": "string", + "examples": ["2021-06-18T18:24:48.702Z"] + }, + "deleted_at": { + "type": "string", + "examples": ["2021-06-18T18:24:48.702Z"] + }, + "rating_average": { + "type": "number" + }, + "rating_count": { + "type": "integer" + }, + "rating_distribution": { + "type": "array" + }, + "recommended_count": { + "type": "integer" + }, + "updated_at": { + "type": "string", + "examples": ["2021-06-18T18:24:48.702Z"] + } + } +} diff --git a/airbyte-integrations/connectors/source-junip-reviews/source_junip_reviews/schemas/product_reviews.json b/airbyte-integrations/connectors/source-junip-reviews/source_junip_reviews/schemas/product_reviews.json new file mode 100644 index 000000000000..30b658e643a1 --- /dev/null +++ b/airbyte-integrations/connectors/source-junip-reviews/source_junip_reviews/schemas/product_reviews.json @@ -0,0 +1,59 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "body": { + "type": ["null", "string"] + }, + "created_at": { + "type": "string", + "examples": ["2021-06-18T18:25:07.033Z"] + }, + "customer_id": { + "type": "integer" + }, + "down_vote_count": { + "type": "integer" + }, + "featured": { + "type": "boolean" + }, + "product_id": { + "type": "integer" + }, + "rating": { + "type": "integer" + }, + "response": { + "type": ["null", "object"] + }, + "target_title": { + "type": "string" + }, + "title": { + "type": ["string", "null"] + }, + "up_vote_count": { + "type": "integer" + }, + "updated_at": { + "type": "string", + "examples": ["2021-06-18T18:25:07.033Z"] + }, + "verified_buyer": { + "type": "boolean" + }, + "would_recommend": { + "type": ["null", "string"] + }, + "photo_urls": { + "type": "array" + }, + "video_urls": { + "type": "array" + } + } +} diff --git a/airbyte-integrations/connectors/source-junip-reviews/source_junip_reviews/schemas/products.json b/airbyte-integrations/connectors/source-junip-reviews/source_junip_reviews/schemas/products.json new file mode 100644 index 000000000000..82b330400eee --- /dev/null +++ b/airbyte-integrations/connectors/source-junip-reviews/source_junip_reviews/schemas/products.json @@ -0,0 +1,45 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "created_at": { + "type": "string", + "examples": ["2021-06-18T18:24:48.702Z"] + }, + "deleted_at": { + "type": "string", + "examples": ["2021-06-18T18:24:48.702Z"] + }, + "rating_average": { + "type": "number" + }, + "rating_count": { + "type": "integer" + }, + "rating_distribution": { + "type": "array" + }, + "recommended_count": { + "type": "integer" + }, + "remote_handle": { + "type": "string" + }, + "remote_id": { + "type": "string" + }, + "title": { + "type": "string" + }, + "unreviewable": { + "type": "boolean" + }, + "updated_at": { + "type": "string", + "examples": ["2021-06-18T18:24:48.702Z"] + } + } +} diff --git a/airbyte-integrations/connectors/source-junip-reviews/source_junip_reviews/schemas/store_reviews.json b/airbyte-integrations/connectors/source-junip-reviews/source_junip_reviews/schemas/store_reviews.json new file mode 100644 index 000000000000..d00ab7ed73c0 --- /dev/null +++ b/airbyte-integrations/connectors/source-junip-reviews/source_junip_reviews/schemas/store_reviews.json @@ -0,0 +1,56 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "body": { + "type": ["null", "object"] + }, + "created_at": { + "type": "string", + "examples": ["2021-06-18T18:25:16.161Z"] + }, + "customer_id": { + "type": "integer" + }, + "down_vote_count": { + "type": "number" + }, + "featured": { + "type": "boolean" + }, + "rating": { + "type": "number" + }, + "response": { + "type": ["null", "object"] + }, + "target_title": { + "type": "string" + }, + "title": { + "type": ["null", "string"] + }, + "up_vote_count": { + "type": "integer" + }, + "updated_at": { + "type": "string", + "examples": ["2021-06-18T18:25:16.161Z"] + }, + "verified_buyer": { + "type": "boolean" + }, + "would_recommend": { + "type": ["null", "string"] + }, + "photo_urls": { + "type": "array" + }, + "video_urls": { + "type": "array" + } + } +} diff --git a/airbyte-integrations/connectors/source-junip-reviews/source_junip_reviews/schemas/stores.json b/airbyte-integrations/connectors/source-junip-reviews/source_junip_reviews/schemas/stores.json new file mode 100644 index 000000000000..cabc2b044577 --- /dev/null +++ b/airbyte-integrations/connectors/source-junip-reviews/source_junip_reviews/schemas/stores.json @@ -0,0 +1,41 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "created_at": { + "type": "string", + "examples": ["2021-06-18T18:25:17.951Z"] + }, + "key": { + "type": "string" + }, + "name": { + "type": "string" + }, + "rating_average": { + "type": "number" + }, + "rating_count": { + "type": "number" + }, + "rating_distribution": { + "type": "object" + }, + "recommended_count": { + "type": "integer" + }, + "slug": { + "type": "string" + }, + "updated_at": { + "type": "string", + "examples": ["2021-06-18T18:25:17.951Z"] + }, + "url": { + "type": "string" + } + } +} diff --git a/airbyte-integrations/connectors/source-junip-reviews/source_junip_reviews/source.py b/airbyte-integrations/connectors/source-junip-reviews/source_junip_reviews/source.py new file mode 100644 index 000000000000..066657b52169 --- /dev/null +++ b/airbyte-integrations/connectors/source-junip-reviews/source_junip_reviews/source.py @@ -0,0 +1,47 @@ +# +# Copyright (c) 2021 Airbyte, Inc., all rights reserved. +# + + +from abc import ABC +from typing import Any, Iterable, List, Mapping, MutableMapping, Optional, Tuple + +from .streams import Products, ProductOverviews, ProductReviews, Stores, StoreReviews, JunipReviewsStream + +import requests +from airbyte_cdk.sources import AbstractSource +from airbyte_cdk.sources.streams import Stream + + +class SourceJunipReviews(AbstractSource): + def check_connection(self, logger, config) -> Tuple[bool, any]: + """ + See https://github.com/airbytehq/airbyte/blob/master/airbyte-integrations/connectors/source-stripe/source_stripe/source.py#L232 + for an example. + + :param config: the user-input config object conforming to the connector's spec.json + :param logger: logger object + :return Tuple[bool, any]: (True, None) if the input config can be used to connect to the API successfully, (False, error) otherwise. + """ + junip_store_key = config["junip_store_key"] + + try: + Products(junip_store_key=junip_store_key) + connection = True, None + except Exception as e: + connection = False, e + + return connection + + def streams(self, config: Mapping[str, Any]) -> List[Stream]: + args = { + "junip_store_key": config.get("junip_store_key") + } + + return [ + Products(**args), + ProductOverviews(**args), + ProductReviews(**args), + Stores(**args), + StoreReviews(**args) + ] diff --git a/airbyte-integrations/connectors/source-junip-reviews/source_junip_reviews/spec.json b/airbyte-integrations/connectors/source-junip-reviews/source_junip_reviews/spec.json new file mode 100644 index 000000000000..5196346eb598 --- /dev/null +++ b/airbyte-integrations/connectors/source-junip-reviews/source_junip_reviews/spec.json @@ -0,0 +1,17 @@ +{ + "documentationUrl": "https://docsurl.com", + "connectionSpecification": { + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Junip Reviews Spec", + "type": "object", + "required": ["junip_store_key"], + "additionalProperties": false, + "properties": { + "junip_store_key": { + "type": "string", + "description": "junip store key", + "airbyte_secret": true + } + } + } +} diff --git a/airbyte-integrations/connectors/source-junip-reviews/source_junip_reviews/streams.py b/airbyte-integrations/connectors/source-junip-reviews/source_junip_reviews/streams.py new file mode 100644 index 000000000000..3f5cce5f15bf --- /dev/null +++ b/airbyte-integrations/connectors/source-junip-reviews/source_junip_reviews/streams.py @@ -0,0 +1,200 @@ + +from abc import ABC +from typing import Any, Iterable, List, Mapping, MutableMapping, Optional, Tuple + +import datetime +import requests +from airbyte_cdk.sources.streams.http import HttpStream +from airbyte_cdk.sources.streams.http.auth import TokenAuthenticator + + +class JunipReviewsStream(HttpStream, ABC): + url_base = "https://api.juniphq.com/v1/" + primary_key = None + + def __init__(self, junip_store_key, **kwargs): + super().__init__(**kwargs) + self.junip_store_key = junip_store_key + + def next_page_token(self, response: requests.Response) -> Optional[Mapping[str, Any]]: + """ + Implements the pagination approach for stream. + + Returns: Next page token + """ + decoded_response = response.json() + page_token = None + + if decoded_response.get("after"): + page_token = { + "page[after]": decoded_response.get("after") + } + return page_token + + def request_params( + self, stream_state: Mapping[str, Any], stream_slice: Mapping[str, any] = None, next_page_token: Mapping[str, Any] = None + ) -> MutableMapping[str, Any]: + """ + Adds query params in requested URL. + """ + params = {} + + if next_page_token: + params.update(next_page_token) + + return params + + def request_headers( + self, stream_state: Mapping[str, Any], stream_slice: Mapping[str, Any] = None, next_page_token: Mapping[str, Any] = None + ) -> Mapping[str, Any]: + """ + Override to return any non-auth headers. Authentication headers will overwrite any overlapping headers returned from this method. + """ + return {"Junip_Store_key": self.junip_store_key} + + def parse_response(self, response: requests.Response, **kwargs) -> Iterable[Mapping]: + """ + :return an iterable containing each record in the response + """ + return {} + + def path( + self, + *, + stream_state: Mapping[str, Any] = None, + stream_slice: Mapping[str, Any] = None, + next_page_token: Mapping[str, Any] = None, + ) -> str: + + return self.name + + +class IncrementalJunipReviewsStream(JunipReviewsStream, ABC): + """ + Baseclass for all incremental streams of Bold source. Override cursor field property in order to use + incremental stream. + """ + state_checkpoint_interval = None + + @property + def cursor_field(self) -> str: + """ + Override to return the cursor field used by this stream e.g: an API entity might always use created_at as the cursor field. This is + usually id or date based. This field's presence tells the framework this in an incremental stream. Required for incremental. + :return str: The name of the cursor field. + """ + pass + + def _convert_date_to_timestamp(self, date: datetime): + return datetime.datetime.strptime(date, "%Y-%m-%dT%H:%M:%S.%fZ") + + def get_updated_state(self, current_stream_state: MutableMapping[str, Any], latest_record: Mapping[str, Any]) -> Mapping[str, Any]: + """ + Override to determine the latest state after reading the latest record. This typically compared the cursor_field from the latest record and + the current state and picks the 'most' recent cursor. This is how a stream's state is determined. Required for incremental. + """ + base_date = ( + datetime.datetime.combine( + datetime.date.fromtimestamp(0), + datetime.datetime.min.time() + ).strftime("%Y-%m-%dT%H:%M:%S.%fZ") + ) + state_dt = self._convert_date_to_timestamp(current_stream_state.get(self.cursor_field, base_date)) + latest_record = self._convert_date_to_timestamp(latest_record.get(self.cursor_field, base_date)) + + return {self.cursor_field: max(latest_record, state_dt)} + + +class Products(IncrementalJunipReviewsStream): + """ + Ref: https://junip.co/docs/api/ + + url: "self.base_url/self.name" + """ + cursor_field = "created_at" + primary_key = "id" + + def parse_response(self, response: requests.Response, **kwargs) -> Iterable[Mapping]: + """ + Ref: https://junip.co/docs/api/ + """ + + json_response = response.json() + for product in json_response.get("products"): + yield product + + +class ProductOverviews(IncrementalJunipReviewsStream): + """ + Ref: https://junip.co/docs/api/ + + url: "self.base_url/self.name" + """ + cursor_field = "created_at" + primary_key = "id" + + def parse_response(self, response: requests.Response, **kwargs) -> Iterable[Mapping]: + """ + Ref: https://junip.co/docs/api/ + """ + + json_response = response.json() + for product_overview in json_response.get("product_overviews"): + yield product_overview + + +class ProductReviews(IncrementalJunipReviewsStream): + """ + Ref: https://junip.co/docs/api/ + + url: "self.base_url/self.name" + """ + cursor_field = "created_at" + primary_key = "id" + + def parse_response(self, response: requests.Response, **kwargs) -> Iterable[Mapping]: + """ + Ref: https://junip.co/docs/api/ + """ + + json_response = response.json() + for product_reviews in json_response.get("product_reviews"): + yield product_reviews + + +class Stores(IncrementalJunipReviewsStream): + """ + Ref: https://junip.co/docs/api/ + + url: "self.base_url/self.name" + """ + cursor_field = "created_at" + primary_key = "id" + + def parse_response(self, response: requests.Response, **kwargs) -> Iterable[Mapping]: + """ + Ref: https://junip.co/docs/api/ + """ + + json_response = response.json() + for store in json_response.get("stores"): + yield store + + +class StoreReviews(IncrementalJunipReviewsStream): + """ + Ref: https://junip.co/docs/api/ + + url: "self.base_url/self.name" + """ + cursor_field = "created_at" + primary_key = "id" + + def parse_response(self, response: requests.Response, **kwargs) -> Iterable[Mapping]: + """ + Ref: https://junip.co/docs/api/ + """ + + json_response = response.json() + for store_reviews in json_response.get("store_reviews"): + yield store_reviews diff --git a/airbyte-integrations/connectors/source-junip-reviews/unit_tests/__init__.py b/airbyte-integrations/connectors/source-junip-reviews/unit_tests/__init__.py new file mode 100644 index 000000000000..46b7376756ec --- /dev/null +++ b/airbyte-integrations/connectors/source-junip-reviews/unit_tests/__init__.py @@ -0,0 +1,3 @@ +# +# Copyright (c) 2021 Airbyte, Inc., all rights reserved. +# diff --git a/airbyte-integrations/connectors/source-junip-reviews/unit_tests/test_incremental_streams.py b/airbyte-integrations/connectors/source-junip-reviews/unit_tests/test_incremental_streams.py new file mode 100644 index 000000000000..4fd707618c72 --- /dev/null +++ b/airbyte-integrations/connectors/source-junip-reviews/unit_tests/test_incremental_streams.py @@ -0,0 +1,59 @@ +# +# Copyright (c) 2021 Airbyte, Inc., all rights reserved. +# + + +from airbyte_cdk.models import SyncMode +from pytest import fixture +from source_junip_reviews.source import IncrementalJunipReviewsStream + + +@fixture +def patch_incremental_base_class(mocker): + # Mock abstract methods to enable instantiating abstract class + mocker.patch.object(IncrementalJunipReviewsStream, "path", "v0/example_endpoint") + mocker.patch.object(IncrementalJunipReviewsStream, "primary_key", "test_primary_key") + mocker.patch.object(IncrementalJunipReviewsStream, "__abstractmethods__", set()) + + +def test_cursor_field(patch_incremental_base_class): + stream = IncrementalJunipReviewsStream() + # TODO: replace this with your expected cursor field + expected_cursor_field = [] + assert stream.cursor_field == expected_cursor_field + + +def test_get_updated_state(patch_incremental_base_class): + stream = IncrementalJunipReviewsStream() + # TODO: replace this with your input parameters + inputs = {"current_stream_state": None, "latest_record": None} + # TODO: replace this with your expected updated stream state + expected_state = {} + assert stream.get_updated_state(**inputs) == expected_state + + +def test_stream_slices(patch_incremental_base_class): + stream = IncrementalJunipReviewsStream() + # TODO: replace this with your input parameters + inputs = {"sync_mode": SyncMode.incremental, "cursor_field": [], "stream_state": {}} + # TODO: replace this with your expected stream slices list + expected_stream_slice = [None] + assert stream.stream_slices(**inputs) == expected_stream_slice + + +def test_supports_incremental(patch_incremental_base_class, mocker): + mocker.patch.object(IncrementalJunipReviewsStream, "cursor_field", "dummy_field") + stream = IncrementalJunipReviewsStream() + assert stream.supports_incremental + + +def test_source_defined_cursor(patch_incremental_base_class): + stream = IncrementalJunipReviewsStream() + assert stream.source_defined_cursor + + +def test_stream_checkpoint_interval(patch_incremental_base_class): + stream = IncrementalJunipReviewsStream() + # TODO: replace this with your expected checkpoint interval + expected_checkpoint_interval = None + assert stream.state_checkpoint_interval == expected_checkpoint_interval diff --git a/airbyte-integrations/connectors/source-junip-reviews/unit_tests/test_source.py b/airbyte-integrations/connectors/source-junip-reviews/unit_tests/test_source.py new file mode 100644 index 000000000000..7e056bc48746 --- /dev/null +++ b/airbyte-integrations/connectors/source-junip-reviews/unit_tests/test_source.py @@ -0,0 +1,22 @@ +# +# Copyright (c) 2021 Airbyte, Inc., all rights reserved. +# + +from unittest.mock import MagicMock + +from source_junip_reviews.source import SourceJunipReviews + + +def test_check_connection(mocker): + source = SourceJunipReviews() + logger_mock, config_mock = MagicMock(), MagicMock() + assert source.check_connection(logger_mock, config_mock) == (True, None) + + +def test_streams(mocker): + source = SourceJunipReviews() + config_mock = MagicMock() + streams = source.streams(config_mock) + # TODO: replace this with your streams number + expected_streams_number = 2 + assert len(streams) == expected_streams_number diff --git a/airbyte-integrations/connectors/source-junip-reviews/unit_tests/test_streams.py b/airbyte-integrations/connectors/source-junip-reviews/unit_tests/test_streams.py new file mode 100644 index 000000000000..0af040ff63f7 --- /dev/null +++ b/airbyte-integrations/connectors/source-junip-reviews/unit_tests/test_streams.py @@ -0,0 +1,83 @@ +# +# Copyright (c) 2021 Airbyte, Inc., all rights reserved. +# + +from http import HTTPStatus +from unittest.mock import MagicMock + +import pytest +from source_junip_reviews.source import JunipReviewsStream + + +@pytest.fixture +def patch_base_class(mocker): + # Mock abstract methods to enable instantiating abstract class + mocker.patch.object(JunipReviewsStream, "path", "v0/example_endpoint") + mocker.patch.object(JunipReviewsStream, "primary_key", "test_primary_key") + mocker.patch.object(JunipReviewsStream, "__abstractmethods__", set()) + + +def test_request_params(patch_base_class): + stream = JunipReviewsStream() + # TODO: replace this with your input parameters + inputs = {"stream_slice": None, "stream_state": None, "next_page_token": None} + # TODO: replace this with your expected request parameters + expected_params = {} + assert stream.request_params(**inputs) == expected_params + + +def test_next_page_token(patch_base_class): + stream = JunipReviewsStream() + # TODO: replace this with your input parameters + inputs = {"response": MagicMock()} + # TODO: replace this with your expected next page token + expected_token = None + assert stream.next_page_token(**inputs) == expected_token + + +def test_parse_response(patch_base_class): + stream = JunipReviewsStream() + # TODO: replace this with your input parameters + inputs = {"response": MagicMock()} + # TODO: replace this with your expected parced object + expected_parsed_object = {} + assert next(stream.parse_response(**inputs)) == expected_parsed_object + + +def test_request_headers(patch_base_class): + stream = JunipReviewsStream() + # TODO: replace this with your input parameters + inputs = {"stream_slice": None, "stream_state": None, "next_page_token": None} + # TODO: replace this with your expected request headers + expected_headers = {} + assert stream.request_headers(**inputs) == expected_headers + + +def test_http_method(patch_base_class): + stream = JunipReviewsStream() + # TODO: replace this with your expected http request method + expected_method = "GET" + assert stream.http_method == expected_method + + +@pytest.mark.parametrize( + ("http_status", "should_retry"), + [ + (HTTPStatus.OK, False), + (HTTPStatus.BAD_REQUEST, False), + (HTTPStatus.TOO_MANY_REQUESTS, True), + (HTTPStatus.INTERNAL_SERVER_ERROR, True), + ], +) +def test_should_retry(patch_base_class, http_status, should_retry): + response_mock = MagicMock() + response_mock.status_code = http_status + stream = JunipReviewsStream() + assert stream.should_retry(response_mock) == should_retry + + +def test_backoff_time(patch_base_class): + response_mock = MagicMock() + stream = JunipReviewsStream() + expected_backoff_time = None + assert stream.backoff_time(response_mock) == expected_backoff_time