diff --git a/airbyte-integrations/connectors/source-freshsales/.dockerignore b/airbyte-integrations/connectors/source-freshsales/.dockerignore new file mode 100644 index 000000000000..02bb719d4c3e --- /dev/null +++ b/airbyte-integrations/connectors/source-freshsales/.dockerignore @@ -0,0 +1,7 @@ +* +!Dockerfile +!Dockerfile.test +!main.py +!source_freshsales +!setup.py +!secrets diff --git a/airbyte-integrations/connectors/source-freshsales/Dockerfile b/airbyte-integrations/connectors/source-freshsales/Dockerfile new file mode 100644 index 000000000000..d7e7bc910231 --- /dev/null +++ b/airbyte-integrations/connectors/source-freshsales/Dockerfile @@ -0,0 +1,38 @@ +FROM python:3.7.11-alpine3.14 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_freshsales ./source_freshsales + +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-freshsales diff --git a/airbyte-integrations/connectors/source-freshsales/README.md b/airbyte-integrations/connectors/source-freshsales/README.md new file mode 100644 index 000000000000..01cfa7382c1c --- /dev/null +++ b/airbyte-integrations/connectors/source-freshsales/README.md @@ -0,0 +1,132 @@ +# Freshsales Source + +This is the repository for the Freshsales source connector, written in Python. +For information about how to use this connector within Airbyte, see [the documentation](https://docs.airbyte.io/integrations/sources/freshsales). + +## 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-freshsales:build +``` + +#### Create credentials +**If you are a community contributor**, follow the instructions in the [documentation](https://docs.airbyte.io/integrations/sources/freshsales) +to generate the necessary credentials. Then create a file `secrets/config.json` conforming to the `source_freshsales/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 freshsales 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 airbyte/source-freshsales:dev +``` + +You can also build the connector image via Gradle: +``` +./gradlew :airbyte-integrations:connectors:source-freshsales: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-freshsales:dev spec +docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-freshsales:dev check --config /secrets/config.json +docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-freshsales:dev discover --config /secrets/config.json +docker run --rm -v $(pwd)/secrets:/secrets -v $(pwd)/integration_tests:/integration_tests airbyte/source-freshsales: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-freshsales:unitTest +``` +To run acceptance and custom integration tests: +``` +./gradlew :airbyte-integrations:connectors:source-freshsales: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-freshsales/acceptance-test-config.yml b/airbyte-integrations/connectors/source-freshsales/acceptance-test-config.yml new file mode 100644 index 000000000000..dfd392cb6e67 --- /dev/null +++ b/airbyte-integrations/connectors/source-freshsales/acceptance-test-config.yml @@ -0,0 +1,20 @@ +# 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-freshsales:dev +tests: + spec: + - spec_path: "source_freshsales/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: [] + full_refresh: + - config_path: "secrets/config.json" + configured_catalog_path: "integration_tests/configured_catalog.json" diff --git a/airbyte-integrations/connectors/source-freshsales/acceptance-test-docker.sh b/airbyte-integrations/connectors/source-freshsales/acceptance-test-docker.sh new file mode 100644 index 000000000000..e4d8b1cef896 --- /dev/null +++ b/airbyte-integrations/connectors/source-freshsales/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-freshsales/build.gradle b/airbyte-integrations/connectors/source-freshsales/build.gradle new file mode 100644 index 000000000000..097ec61b07f8 --- /dev/null +++ b/airbyte-integrations/connectors/source-freshsales/build.gradle @@ -0,0 +1,14 @@ +plugins { + id 'airbyte-python' + id 'airbyte-docker' + id 'airbyte-source-acceptance-test' +} + +airbytePython { + moduleDirectory 'source_freshsales' +} + +dependencies { + implementation files(project(':airbyte-integrations:bases:source-acceptance-test').airbyteDocker.outputs) + implementation files(project(':airbyte-integrations:bases:base-python').airbyteDocker.outputs) +} diff --git a/airbyte-integrations/connectors/source-freshsales/integration_tests/__init__.py b/airbyte-integrations/connectors/source-freshsales/integration_tests/__init__.py new file mode 100644 index 000000000000..46b7376756ec --- /dev/null +++ b/airbyte-integrations/connectors/source-freshsales/integration_tests/__init__.py @@ -0,0 +1,3 @@ +# +# Copyright (c) 2021 Airbyte, Inc., all rights reserved. +# diff --git a/airbyte-integrations/connectors/source-freshsales/integration_tests/acceptance.py b/airbyte-integrations/connectors/source-freshsales/integration_tests/acceptance.py new file mode 100644 index 000000000000..108075487440 --- /dev/null +++ b/airbyte-integrations/connectors/source-freshsales/integration_tests/acceptance.py @@ -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 diff --git a/airbyte-integrations/connectors/source-freshsales/integration_tests/configured_catalog.json b/airbyte-integrations/connectors/source-freshsales/integration_tests/configured_catalog.json new file mode 100644 index 000000000000..470df870dfdb --- /dev/null +++ b/airbyte-integrations/connectors/source-freshsales/integration_tests/configured_catalog.json @@ -0,0 +1,94 @@ +{ + "streams": [ + { + "stream": { + "name": "contacts", + "json_schema": {}, + "supported_sync_modes": ["full_refresh"], + "source_defined_primary_key": [["id"]] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "overwrite" + }, + { + "stream": { + "name": "accounts", + "json_schema": {}, + "supported_sync_modes": ["full_refresh"], + "source_defined_primary_key": [["id"]] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "overwrite" + }, + { + "stream": { + "name": "open_deals", + "json_schema": {}, + "supported_sync_modes": ["full_refresh"], + "source_defined_primary_key": [["id"]] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "overwrite" + }, + { + "stream": { + "name": "won_deals", + "json_schema": {}, + "supported_sync_modes": ["full_refresh"], + "source_defined_primary_key": [["id"]] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "overwrite" + }, + { + "stream": { + "name": "lost_deals", + "json_schema": {}, + "supported_sync_modes": ["full_refresh"], + "source_defined_primary_key": [["id"]] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "overwrite" + }, + { + "stream": { + "name": "open_tasks", + "json_schema": {}, + "supported_sync_modes": ["full_refresh"], + "source_defined_primary_key": [["id"]] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "overwrite" + }, + { + "stream": { + "name": "completed_tasks", + "json_schema": {}, + "supported_sync_modes": ["full_refresh"], + "source_defined_primary_key": [["id"]] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "overwrite" + }, + { + "stream": { + "name": "past_appointments", + "json_schema": {}, + "supported_sync_modes": ["full_refresh"], + "source_defined_primary_key": [["id"]] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "overwrite" + }, + { + "stream": { + "name": "upcoming_appointments", + "json_schema": {}, + "supported_sync_modes": ["full_refresh"], + "source_defined_primary_key": [["id"]] + }, + "sync_mode": "full_refresh", + "destination_sync_mode": "overwrite" + } + ] +} diff --git a/airbyte-integrations/connectors/source-freshsales/integration_tests/integration_test.py b/airbyte-integrations/connectors/source-freshsales/integration_tests/integration_test.py new file mode 100644 index 000000000000..2824cd4a16cd --- /dev/null +++ b/airbyte-integrations/connectors/source-freshsales/integration_tests/integration_test.py @@ -0,0 +1,8 @@ +# +# Copyright (c) 2021 Airbyte, Inc., all rights reserved. +# + + +def test_dummy_test(): + """ this is the dummy test to pass integration tests step """ + pass diff --git a/airbyte-integrations/connectors/source-freshsales/integration_tests/invalid_config.json b/airbyte-integrations/connectors/source-freshsales/integration_tests/invalid_config.json new file mode 100644 index 000000000000..8b7f2e2e3e00 --- /dev/null +++ b/airbyte-integrations/connectors/source-freshsales/integration_tests/invalid_config.json @@ -0,0 +1 @@ +{"domain_name": "", "api_key": "ghiklmn"} \ No newline at end of file diff --git a/airbyte-integrations/connectors/source-freshsales/integration_tests/sample_config.json b/airbyte-integrations/connectors/source-freshsales/integration_tests/sample_config.json new file mode 100644 index 000000000000..1e106e9658f8 --- /dev/null +++ b/airbyte-integrations/connectors/source-freshsales/integration_tests/sample_config.json @@ -0,0 +1 @@ +{"domain_name": "testabc.myfreshworks.com", "api_key": "ghiklmn"} \ No newline at end of file diff --git a/airbyte-integrations/connectors/source-freshsales/main.py b/airbyte-integrations/connectors/source-freshsales/main.py new file mode 100644 index 000000000000..3f4d8a1f45c4 --- /dev/null +++ b/airbyte-integrations/connectors/source-freshsales/main.py @@ -0,0 +1,13 @@ +# +# Copyright (c) 2021 Airbyte, Inc., all rights reserved. +# + + +import sys + +from airbyte_cdk.entrypoint import launch +from source_freshsales import SourceFreshsales + +if __name__ == "__main__": + source = SourceFreshsales() + launch(source, sys.argv[1:]) diff --git a/airbyte-integrations/connectors/source-freshsales/requirements.txt b/airbyte-integrations/connectors/source-freshsales/requirements.txt new file mode 100644 index 000000000000..0411042aa091 --- /dev/null +++ b/airbyte-integrations/connectors/source-freshsales/requirements.txt @@ -0,0 +1,2 @@ +-e ../../bases/source-acceptance-test +-e . diff --git a/airbyte-integrations/connectors/source-freshsales/setup.py b/airbyte-integrations/connectors/source-freshsales/setup.py new file mode 100644 index 000000000000..2539849d0c67 --- /dev/null +++ b/airbyte-integrations/connectors/source-freshsales/setup.py @@ -0,0 +1,29 @@ +# +# Copyright (c) 2021 Airbyte, Inc., all rights reserved. +# + + +from setuptools import find_packages, setup + +MAIN_REQUIREMENTS = [ + "airbyte-cdk", +] + +TEST_REQUIREMENTS = [ + "pytest~=6.1", + "pytest-mock~=3.6.1", + "source-acceptance-test", +] + +setup( + name="source_freshsales", + description="Source implementation for Freshsales.", + author="Tuan Nguyen", + author_email="anhtuan.nguyen@me.com", + 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-freshsales/source_freshsales/__init__.py b/airbyte-integrations/connectors/source-freshsales/source_freshsales/__init__.py new file mode 100644 index 000000000000..9061e6659822 --- /dev/null +++ b/airbyte-integrations/connectors/source-freshsales/source_freshsales/__init__.py @@ -0,0 +1,8 @@ +# +# Copyright (c) 2021 Airbyte, Inc., all rights reserved. +# + + +from .source import SourceFreshsales + +__all__ = ["SourceFreshsales"] diff --git a/airbyte-integrations/connectors/source-freshsales/source_freshsales/schemas/accounts.json b/airbyte-integrations/connectors/source-freshsales/source_freshsales/schemas/accounts.json new file mode 100644 index 000000000000..ec1193d483c3 --- /dev/null +++ b/airbyte-integrations/connectors/source-freshsales/source_freshsales/schemas/accounts.json @@ -0,0 +1,67 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "required": ["id"], + "properties": { + "id": { "type": ["null", "integer"] }, + "name": { "type": ["null", "string"] }, + "address": { "type": ["null", "string"] }, + "city": { "type": ["null", "string"] }, + "state": { "type": ["null", "string"] }, + "zipcode": { "type": ["null", "string"] }, + "country": { "type": ["null", "string"] }, + "industry_type_id": { "type": ["null", "integer"] }, + "business_type_id": { "type": ["null", "integer"] }, + "number_of_employees": { "type": ["null", "integer"] }, + "annual_revenue": { "type": ["null", "number"] }, + "website": { "type": ["null", "string"] }, + "phone": { "type": ["null", "string"] }, + "owner_id": { "type": ["null", "integer"] }, + "facebook": { "type": ["null", "string"] }, + "twitter": { "type": ["null", "string"] }, + "linkedin": { "type": ["null", "string"] }, + "territory_id": { "type": ["null", "integer"] }, + "created_at": { "type": ["null", "string"] }, + "updated_at": { "type": ["null", "string"] }, + "parent_sales_account_id": { "type": ["null", "integer"] }, + "first_name": { "type": ["null", "string"] }, + "last_name": { "type": ["null", "string"] }, + "display_name": { "type": ["null", "string"] }, + "avatar": { "type": ["null", "string"] }, + "job_title": { "type": ["null", "string"] }, + "email": { "type": ["null", "string"] }, + "emails": { "type": ["null", "array"] }, + "time_zone": { "type": ["null", "string"] }, + "work_number": { "type": ["null", "string"] }, + "mobile_number": { "type": ["null", "string"] }, + "last_seen": { "type": ["null", "string"] }, + "lead_score": { "type": ["null", "integer"] }, + "last_contacted": { "type": ["null", "string"] }, + "open_deals_amount": { "type": ["null", "number"] }, + "won_deals_amount": { "type": ["null", "number"] }, + "links": { "type": ["null", "object"] }, + "last_contacted_sales_activity_mode": { "type": ["null", "string"] }, + "custom_field": { "type": ["null", "object"] }, + "keyword": { "type": ["null", "string"] }, + "medium": { "type": ["null", "string"] }, + "last_contacted_mode": { "type": ["null", "string"] }, + "recent_note": { "type": ["null", "string"] }, + "won_deals_count": { "type": ["null", "integer"] }, + "last_contacted_via_sales_activity": { "type": ["null", "string"] }, + "completed_sales_sequences": { "type": ["null", "string"] }, + "active_sales_sequences": { "type": ["null", "string"] }, + "web_form_ids": { "type": ["null", "array"] }, + "open_deals_count": { "type": ["null", "integer"] }, + "last_assigned_at": { "type": ["null", "string"] }, + "tags": { "type": ["null", "array"] }, + "is_deleted": { "type": ["null", "boolean"] }, + "team_user_ids": { "type": ["null", "array"] }, + "external_id": { "type": ["null", "string"] }, + "work_email": { "type": ["null", "string"] }, + "subscription_status": { "type": ["null", "integer"] }, + "subscription_types": { "type": ["null", "string"] }, + "customer_fit": { "type": ["null", "string"] }, + "whatsapp_subscription_status": { "type": ["null", "string"] }, + "phone_numbers": { "type": ["null", "array"] } + } +} diff --git a/airbyte-integrations/connectors/source-freshsales/source_freshsales/schemas/completed_tasks.json b/airbyte-integrations/connectors/source-freshsales/source_freshsales/schemas/completed_tasks.json new file mode 100644 index 000000000000..dfdcb18586e0 --- /dev/null +++ b/airbyte-integrations/connectors/source-freshsales/source_freshsales/schemas/completed_tasks.json @@ -0,0 +1,21 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "required": ["id"], + "properties": { + "id": { "type": ["null", "integer"] }, + "title": { "type": ["null", "string"] }, + "description": { "type": ["null", "string"] }, + "due_date": { "type": ["null", "string"] }, + "targetable_id": { "type": ["null", "integer"] }, + "targetable_type": { "type": ["null", "string"] }, + "Possible": { "type": ["null", "string"] }, + "owner_id": { "type": ["null", "integer"] }, + "status": { "type": ["null", "string"] }, + "creater_id": { "type": ["null", "integer"] }, + "created_at": { "type": ["null", "string"] }, + "updated_at": { "type": ["null", "string"] }, + "outcome_id": { "type": ["null", "integer"] }, + "task_type_id": { "type": ["null", "integer"] } + } +} diff --git a/airbyte-integrations/connectors/source-freshsales/source_freshsales/schemas/contacts.json b/airbyte-integrations/connectors/source-freshsales/source_freshsales/schemas/contacts.json new file mode 100644 index 000000000000..cf32ac6abe1d --- /dev/null +++ b/airbyte-integrations/connectors/source-freshsales/source_freshsales/schemas/contacts.json @@ -0,0 +1,65 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "required": ["id"], + "properties": { + "id": { "type": ["null", "integer"] }, + "first_name": { "type": ["null", "string"] }, + "last_name": { "type": ["null", "string"] }, + "subscription_status": { "type": ["null", "string"] }, + "job_title": { "type": ["null", "string"] }, + "email": { "type": ["null", "string"] }, + "emails": { "type": ["null", "string"] }, + "work_number": { "type": ["null", "string"] }, + "external_id": { "type": ["null", "string"] }, + "mobile_number": { "type": ["null", "string"] }, + "address": { "type": ["null", "string"] }, + "city": { "type": ["null", "string"] }, + "state": { "type": ["null", "string"] }, + "zipcode": { "type": ["null", "string"] }, + "country": { "type": ["null", "string"] }, + "sales_accounts": { "type": ["null", "array"] }, + "territory_id": { "type": ["null", "integer"] }, + "lead_source_id": { "type": ["null", "integer"] }, + "owner_id": { "type": ["null", "integer"] }, + "subscription_types": { "type": ["null", "string"] }, + "medium": { "type": ["null", "string"] }, + "campaign_id": { "type": ["null", "integer"] }, + "keyword": { "type": ["null", "string"] }, + "time_zone": { "type": ["null", "string"] }, + "facebook": { "type": ["null", "string"] }, + "twitter": { "type": ["null", "string"] }, + "linkedin": { "type": ["null", "string"] }, + "created_at": { "type": ["null", "string"] }, + "updated_at": { "type": ["null", "string"] }, + "contact_status_id": { "type": ["null", "integer"] }, + "sales_account_id": { "type": ["null", "integer"] }, + "lifecycle_stage_id": { "type": ["null", "integer"] }, + "display_name": { "type": ["null", "string"] }, + "avatar": { "type": ["null", "string"] }, + "last_seen": { "type": ["null", "string"] }, + "lead_score": { "type": ["null", "integer"] }, + "last_contacted": { "type": ["null", "string"] }, + "open_deals_amount": { "type": ["null", "number"] }, + "won_deals_amount": { "type": ["null", "number"] }, + "links": { "type": ["null", "object"] }, + "last_contacted_sales_activity_mode": { "type": ["null", "string"] }, + "custom_field": { "type": ["null", "object"] }, + "last_contacted_mode": { "type": ["null", "string"] }, + "recent_note": { "type": ["null", "string"] }, + "won_deals_count": { "type": ["null", "integer"] }, + "last_contacted_via_sales_activity": { "type": ["null", "string"] }, + "completed_sales_sequences": { "type": ["null", "string"] }, + "active_sales_sequences": { "type": ["null", "string"] }, + "web_form_ids": { "type": ["null", "string"] }, + "open_deals_count": { "type": ["null", "integer"] }, + "last_assigned_at": { "type": ["null", "string"] }, + "tags": { "type": ["null", "array"] }, + "is_deleted": { "type": ["null", "boolean"] }, + "team_user_ids": { "type": ["null", "string"] }, + "work_email": { "type": ["null", "string"] }, + "customer_fit": { "type": ["null", "integer"] }, + "whatsapp_subscription_status": { "type": ["null", "integer"] }, + "phone_numbers": { "type": ["null", "array"] } + } +} diff --git a/airbyte-integrations/connectors/source-freshsales/source_freshsales/schemas/lost_deals.json b/airbyte-integrations/connectors/source-freshsales/source_freshsales/schemas/lost_deals.json new file mode 100644 index 000000000000..625e5823b30d --- /dev/null +++ b/airbyte-integrations/connectors/source-freshsales/source_freshsales/schemas/lost_deals.json @@ -0,0 +1,52 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "required": ["id"], + "properties": { + "id": { "type": ["null", "integer"] }, + "name": { "type": ["null", "string"] }, + "amount": { "type": ["null", "number"] }, + "currency_id": { "type": ["null", "integer"] }, + "base_currency_amount": { "type": ["null", "number"] }, + "sales_account_id": { "type": ["null", "integer"] }, + "deal_stage_id": { "type": ["null", "integer"] }, + "deal_reason_id": { "type": ["null", "integer"] }, + "deal_type_id": { "type": ["null", "integer"] }, + "owner_id": { "type": ["null", "integer"] }, + "expected_close": { "type": ["null", "string"] }, + "closed_date": { "type": ["null", "string"] }, + "lead_source_id": { "type": ["null", "integer"] }, + "campaign_id": { "type": ["null", "integer"] }, + "deal_product_id": { "type": ["null", "integer"] }, + "deal_payment_status_id": { "type": ["null", "integer"] }, + "probability": { "type": ["null", "integer"] }, + "created_at": { "type": ["null", "string"] }, + "updated_at": { "type": ["null", "string"] }, + "territory_id": { "type": ["null", "integer"] }, + "deal_pipeline_id": { "type": "integer" }, + "stage_updated_time": { "type": ["null", "string"] }, + "custom_field": { "type": ["null", "object"] }, + "age": { "type": ["null", "integer"] }, + "links": { "type": ["null", "object"] }, + "recent_note": { "type": ["null", "string"] }, + "completed_sales_sequences": { "type": ["null", "string"] }, + "active_sales_sequences": { "type": ["null", "string"] }, + "web_form_id": { "type": ["null", "integer"] }, + "upcoming_activities_time": { "type": ["null", "string"] }, + "collaboration": { "type": ["null", "object"] }, + "last_assigned_at": { "type": ["null", "string"] }, + "tags": { "type": ["null", "array"] }, + "last_contacted_sales_activity_mode": { "type": ["null", "string"] }, + "last_contacted_via_sales_activity": { "type": ["null", "string"] }, + "expected_deal_value": { "type": ["null", "number"] }, + "is_deleted": { "type": ["null", "boolean"] }, + "team_user_ids": { "type": ["null", "string"] }, + "avatar": { "type": ["null", "string"] }, + "fc_widget_collaboration": { "type": ["null", "object"] }, + "forecast_category": { "type": ["null", "integer"] }, + "deal_prediction_last_updated_at": { "type": ["null", "string"] }, + "rotten_days": { "type": ["null", "integer"] }, + "has_products": { "type": ["null", "boolean"] }, + "products": { "type": ["null", "string"] } + } +} diff --git a/airbyte-integrations/connectors/source-freshsales/source_freshsales/schemas/open_deals.json b/airbyte-integrations/connectors/source-freshsales/source_freshsales/schemas/open_deals.json new file mode 100644 index 000000000000..625e5823b30d --- /dev/null +++ b/airbyte-integrations/connectors/source-freshsales/source_freshsales/schemas/open_deals.json @@ -0,0 +1,52 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "required": ["id"], + "properties": { + "id": { "type": ["null", "integer"] }, + "name": { "type": ["null", "string"] }, + "amount": { "type": ["null", "number"] }, + "currency_id": { "type": ["null", "integer"] }, + "base_currency_amount": { "type": ["null", "number"] }, + "sales_account_id": { "type": ["null", "integer"] }, + "deal_stage_id": { "type": ["null", "integer"] }, + "deal_reason_id": { "type": ["null", "integer"] }, + "deal_type_id": { "type": ["null", "integer"] }, + "owner_id": { "type": ["null", "integer"] }, + "expected_close": { "type": ["null", "string"] }, + "closed_date": { "type": ["null", "string"] }, + "lead_source_id": { "type": ["null", "integer"] }, + "campaign_id": { "type": ["null", "integer"] }, + "deal_product_id": { "type": ["null", "integer"] }, + "deal_payment_status_id": { "type": ["null", "integer"] }, + "probability": { "type": ["null", "integer"] }, + "created_at": { "type": ["null", "string"] }, + "updated_at": { "type": ["null", "string"] }, + "territory_id": { "type": ["null", "integer"] }, + "deal_pipeline_id": { "type": "integer" }, + "stage_updated_time": { "type": ["null", "string"] }, + "custom_field": { "type": ["null", "object"] }, + "age": { "type": ["null", "integer"] }, + "links": { "type": ["null", "object"] }, + "recent_note": { "type": ["null", "string"] }, + "completed_sales_sequences": { "type": ["null", "string"] }, + "active_sales_sequences": { "type": ["null", "string"] }, + "web_form_id": { "type": ["null", "integer"] }, + "upcoming_activities_time": { "type": ["null", "string"] }, + "collaboration": { "type": ["null", "object"] }, + "last_assigned_at": { "type": ["null", "string"] }, + "tags": { "type": ["null", "array"] }, + "last_contacted_sales_activity_mode": { "type": ["null", "string"] }, + "last_contacted_via_sales_activity": { "type": ["null", "string"] }, + "expected_deal_value": { "type": ["null", "number"] }, + "is_deleted": { "type": ["null", "boolean"] }, + "team_user_ids": { "type": ["null", "string"] }, + "avatar": { "type": ["null", "string"] }, + "fc_widget_collaboration": { "type": ["null", "object"] }, + "forecast_category": { "type": ["null", "integer"] }, + "deal_prediction_last_updated_at": { "type": ["null", "string"] }, + "rotten_days": { "type": ["null", "integer"] }, + "has_products": { "type": ["null", "boolean"] }, + "products": { "type": ["null", "string"] } + } +} diff --git a/airbyte-integrations/connectors/source-freshsales/source_freshsales/schemas/open_tasks.json b/airbyte-integrations/connectors/source-freshsales/source_freshsales/schemas/open_tasks.json new file mode 100644 index 000000000000..dfdcb18586e0 --- /dev/null +++ b/airbyte-integrations/connectors/source-freshsales/source_freshsales/schemas/open_tasks.json @@ -0,0 +1,21 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "required": ["id"], + "properties": { + "id": { "type": ["null", "integer"] }, + "title": { "type": ["null", "string"] }, + "description": { "type": ["null", "string"] }, + "due_date": { "type": ["null", "string"] }, + "targetable_id": { "type": ["null", "integer"] }, + "targetable_type": { "type": ["null", "string"] }, + "Possible": { "type": ["null", "string"] }, + "owner_id": { "type": ["null", "integer"] }, + "status": { "type": ["null", "string"] }, + "creater_id": { "type": ["null", "integer"] }, + "created_at": { "type": ["null", "string"] }, + "updated_at": { "type": ["null", "string"] }, + "outcome_id": { "type": ["null", "integer"] }, + "task_type_id": { "type": ["null", "integer"] } + } +} diff --git a/airbyte-integrations/connectors/source-freshsales/source_freshsales/schemas/past_appointments.json b/airbyte-integrations/connectors/source-freshsales/source_freshsales/schemas/past_appointments.json new file mode 100644 index 000000000000..29117a8d9fdf --- /dev/null +++ b/airbyte-integrations/connectors/source-freshsales/source_freshsales/schemas/past_appointments.json @@ -0,0 +1,29 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "required": ["id"], + "properties": { + "id": { "type": ["null", "integer"] }, + "from_date": { "type": ["null", "string"] }, + "date": { "type": ["null", "string"] }, + "Start": { "type": ["null", "string"] }, + "end_date": { "type": ["null", "string"] }, + "End": { "type": ["null", "string"] }, + "time_zone": { "type": ["null", "string"] }, + "title": { "type": ["null", "string"] }, + "description": { "type": ["null", "string"] }, + "creater_id": { "type": ["null", "integer"] }, + "targetable_id": { "type": ["null", "integer"] }, + "targetable_type": { "type": ["null", "string"] }, + "Possible": { "type": ["null", "string"] }, + "location": { "type": ["null", "string"] }, + "created_at": { "type": ["null", "string"] }, + "updated_at": { "type": ["null", "string"] }, + "is_allday": { "type": ["null", "string"] }, + "appointment_attendees_attributes": { "type": ["null", "array"] }, + "outcome_id": { "type": ["null", "integer"] }, + "latitude": { "type": ["null", "string"] }, + "longitude": { "type": ["null", "string"] }, + "checkedin_at": { "type": ["null", "string"] } + } +} diff --git a/airbyte-integrations/connectors/source-freshsales/source_freshsales/schemas/upcoming_appointments.json b/airbyte-integrations/connectors/source-freshsales/source_freshsales/schemas/upcoming_appointments.json new file mode 100644 index 000000000000..29117a8d9fdf --- /dev/null +++ b/airbyte-integrations/connectors/source-freshsales/source_freshsales/schemas/upcoming_appointments.json @@ -0,0 +1,29 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "required": ["id"], + "properties": { + "id": { "type": ["null", "integer"] }, + "from_date": { "type": ["null", "string"] }, + "date": { "type": ["null", "string"] }, + "Start": { "type": ["null", "string"] }, + "end_date": { "type": ["null", "string"] }, + "End": { "type": ["null", "string"] }, + "time_zone": { "type": ["null", "string"] }, + "title": { "type": ["null", "string"] }, + "description": { "type": ["null", "string"] }, + "creater_id": { "type": ["null", "integer"] }, + "targetable_id": { "type": ["null", "integer"] }, + "targetable_type": { "type": ["null", "string"] }, + "Possible": { "type": ["null", "string"] }, + "location": { "type": ["null", "string"] }, + "created_at": { "type": ["null", "string"] }, + "updated_at": { "type": ["null", "string"] }, + "is_allday": { "type": ["null", "string"] }, + "appointment_attendees_attributes": { "type": ["null", "array"] }, + "outcome_id": { "type": ["null", "integer"] }, + "latitude": { "type": ["null", "string"] }, + "longitude": { "type": ["null", "string"] }, + "checkedin_at": { "type": ["null", "string"] } + } +} diff --git a/airbyte-integrations/connectors/source-freshsales/source_freshsales/schemas/won_deals.json b/airbyte-integrations/connectors/source-freshsales/source_freshsales/schemas/won_deals.json new file mode 100644 index 000000000000..625e5823b30d --- /dev/null +++ b/airbyte-integrations/connectors/source-freshsales/source_freshsales/schemas/won_deals.json @@ -0,0 +1,52 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "required": ["id"], + "properties": { + "id": { "type": ["null", "integer"] }, + "name": { "type": ["null", "string"] }, + "amount": { "type": ["null", "number"] }, + "currency_id": { "type": ["null", "integer"] }, + "base_currency_amount": { "type": ["null", "number"] }, + "sales_account_id": { "type": ["null", "integer"] }, + "deal_stage_id": { "type": ["null", "integer"] }, + "deal_reason_id": { "type": ["null", "integer"] }, + "deal_type_id": { "type": ["null", "integer"] }, + "owner_id": { "type": ["null", "integer"] }, + "expected_close": { "type": ["null", "string"] }, + "closed_date": { "type": ["null", "string"] }, + "lead_source_id": { "type": ["null", "integer"] }, + "campaign_id": { "type": ["null", "integer"] }, + "deal_product_id": { "type": ["null", "integer"] }, + "deal_payment_status_id": { "type": ["null", "integer"] }, + "probability": { "type": ["null", "integer"] }, + "created_at": { "type": ["null", "string"] }, + "updated_at": { "type": ["null", "string"] }, + "territory_id": { "type": ["null", "integer"] }, + "deal_pipeline_id": { "type": "integer" }, + "stage_updated_time": { "type": ["null", "string"] }, + "custom_field": { "type": ["null", "object"] }, + "age": { "type": ["null", "integer"] }, + "links": { "type": ["null", "object"] }, + "recent_note": { "type": ["null", "string"] }, + "completed_sales_sequences": { "type": ["null", "string"] }, + "active_sales_sequences": { "type": ["null", "string"] }, + "web_form_id": { "type": ["null", "integer"] }, + "upcoming_activities_time": { "type": ["null", "string"] }, + "collaboration": { "type": ["null", "object"] }, + "last_assigned_at": { "type": ["null", "string"] }, + "tags": { "type": ["null", "array"] }, + "last_contacted_sales_activity_mode": { "type": ["null", "string"] }, + "last_contacted_via_sales_activity": { "type": ["null", "string"] }, + "expected_deal_value": { "type": ["null", "number"] }, + "is_deleted": { "type": ["null", "boolean"] }, + "team_user_ids": { "type": ["null", "string"] }, + "avatar": { "type": ["null", "string"] }, + "fc_widget_collaboration": { "type": ["null", "object"] }, + "forecast_category": { "type": ["null", "integer"] }, + "deal_prediction_last_updated_at": { "type": ["null", "string"] }, + "rotten_days": { "type": ["null", "integer"] }, + "has_products": { "type": ["null", "boolean"] }, + "products": { "type": ["null", "string"] } + } +} diff --git a/airbyte-integrations/connectors/source-freshsales/source_freshsales/source.py b/airbyte-integrations/connectors/source-freshsales/source_freshsales/source.py new file mode 100644 index 000000000000..974114398ffc --- /dev/null +++ b/airbyte-integrations/connectors/source-freshsales/source_freshsales/source.py @@ -0,0 +1,246 @@ +# +# Copyright (c) 2021 Airbyte, Inc., all rights reserved. +# + + +from abc import ABC +from typing import Any, Iterable, List, Mapping, MutableMapping, Optional, Tuple + +import requests +from airbyte_cdk.sources import AbstractSource +from airbyte_cdk.sources.streams import Stream +from airbyte_cdk.sources.streams.http import HttpStream +from airbyte_cdk.sources.streams.http.auth import TokenAuthenticator +from airbyte_cdk.sources.utils.transform import TransformConfig, TypeTransformer + + +# Basic full refresh stream +class FreshsalesStream(HttpStream, ABC): + url_base = "https://{}/crm/sales/api/" + primary_key = "id" + order_field = "updated_at" + transformer: TypeTransformer = TypeTransformer(TransformConfig.DefaultSchemaNormalization) + + def __init__(self, domain_name: str, **kwargs): + super().__init__(**kwargs) + self.url_base = self.url_base.format(domain_name) + self.domain_name = domain_name + self.page = 1 + + def next_page_token(self, response: requests.Response) -> Optional[Mapping[str, Any]]: + """ + There is no next page token in the respond so incrementing the page param until there is no new result + """ + list_result = response.json().get(self.object_name, []) + if list_result: + self.page += 1 + return self.page + else: + return None + + 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]: + params = {"page": self.page, "sort": self.order_field, "sort_type": "asc"} + return params + + def parse_response(self, response: requests.Response, **kwargs) -> Iterable[Mapping]: + json_response = response.json() + records = json_response.get(self.object_name, []) if self.object_name is not None else json_response + yield from records + + def _get_filters(self) -> List: + """ + Some streams require a filter_id to be passed in. This function gets all available filters. + """ + filters_url = f"https://{self.domain_name}/crm/sales/api/{self.object_name}/filters" + auth = self.authenticator.get_auth_header() + + try: + r = requests.get(filters_url, headers=auth) + r.raise_for_status() + return r.json().get("filters") + except requests.exceptions.RequestException as e: + raise e + + def get_view_id(self): + """ + This function iterate over all available filters and get the relevant filter_id. + """ + if hasattr(self, "filter_name"): + filters = self._get_filters() + return next(filter["id"] for filter in filters if filter["name"] == self.filter_name) + else: + return + + def path( + self, stream_state: Mapping[str, Any] = None, stream_slice: Mapping[str, Any] = None, next_page_token: Mapping[str, Any] = None + ) -> str: + view_id = self.get_view_id() + return f"{self.object_name}/view/{view_id}" + + +class Contacts(FreshsalesStream): + """ + API docs: https://developers.freshworks.com/crm/api/#contacts + """ + + object_name = "contacts" + filter_name = "All Contacts" + + +class Accounts(FreshsalesStream): + """ + API docs: https://developers.freshworks.com/crm/api/#accounts + """ + + object_name = "sales_accounts" + filter_name = "All Accounts" + + +class Deals(FreshsalesStream): + object_name = "deals" + + def parse_response(self, response: requests.Response, **kwargs) -> Iterable[Mapping]: + json_response = response.json() + records = json_response.get(self.object_name, []) if self.object_name is not None else json_response + # This is to remove data form widget development. Keeping this in failed integration tests. + for record in records: + record.pop("fc_widget_collaboration", None) + yield from records + + +class OpenDeals(Deals): + """ + API docs: https://developers.freshworks.com/crm/api/#deals + """ + + filter_name = "Open Deals" + + +class WonDeals(Deals): + """ + API docs: https://developers.freshworks.com/crm/api/#deals + """ + + filter_name = "Won Deals" + + +class LostDeals(Deals): + """ + API docs: https://developers.freshworks.com/crm/api/#deals + """ + + filter_name = "Lost Deals" + + +class OpenTasks(FreshsalesStream): + """ + API docs: https://developers.freshworks.com/crm/api/#tasks + """ + + object_name = "tasks" + filter_value = "open" + + def path( + self, stream_state: Mapping[str, Any] = None, stream_slice: Mapping[str, Any] = None, next_page_token: Mapping[str, Any] = None + ) -> str: + return f"{self.object_name}" + + 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]: + params = super().request_params(stream_state, stream_slice=stream_slice, next_page_token=next_page_token) + params["filter"] = self.filter_value + return params + + +class CompletedTasks(FreshsalesStream): + """ + API docs: https://developers.freshworks.com/crm/api/#tasks + """ + + object_name = "tasks" + filter_value = "completed" + + def path( + self, stream_state: Mapping[str, Any] = None, stream_slice: Mapping[str, Any] = None, next_page_token: Mapping[str, Any] = None + ) -> str: + return f"{self.object_name}" + + 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]: + params = super().request_params(stream_state, stream_slice=stream_slice, next_page_token=next_page_token) + params["filter"] = self.filter_value + return params + + +class PastAppointments(FreshsalesStream): + """ + API docs: https://developers.freshworks.com/crm/api/#appointments + """ + + object_name = "appointments" + filter_value = "past" + + def path( + self, stream_state: Mapping[str, Any] = None, stream_slice: Mapping[str, Any] = None, next_page_token: Mapping[str, Any] = None + ) -> str: + return f"{self.object_name}" + + 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]: + params = super().request_params(stream_state, stream_slice=stream_slice, next_page_token=next_page_token) + params["filter"] = self.filter_value + return params + + +class UpcomingAppointments(FreshsalesStream): + """ + API docs: https://developers.freshworks.com/crm/api/#appointments + """ + + object_name = "appointments" + filter_value = "upcoming" + + def path( + self, stream_state: Mapping[str, Any] = None, stream_slice: Mapping[str, Any] = None, next_page_token: Mapping[str, Any] = None + ) -> str: + return f"{self.object_name}" + + 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]: + params = super().request_params(stream_state, stream_slice=stream_slice, next_page_token=next_page_token) + params["filter"] = self.filter_value + return params + + +# Source +class SourceFreshsales(AbstractSource): + def check_connection(self, logger, config) -> Tuple[bool, any]: + auth = TokenAuthenticator(token=f'token={config["api_key"]}', auth_method="Token").get_auth_header() + url = f'https://{config["domain_name"]}/crm/sales/api/contacts/filters' + try: + session = requests.get(url, headers=auth) + session.raise_for_status() + return True, None + except requests.exceptions.RequestException as e: + return False, e + + def streams(self, config: Mapping[str, Any]) -> List[Stream]: + auth = TokenAuthenticator(token=f'token={config["api_key"]}', auth_method="Token") + args = {"authenticator": auth, "domain_name": config["domain_name"]} + return [ + Contacts(**args), + Accounts(**args), + OpenDeals(**args), + WonDeals(**args), + LostDeals(**args), + OpenTasks(**args), + CompletedTasks(**args), + PastAppointments(**args), + UpcomingAppointments(**args), + ] diff --git a/airbyte-integrations/connectors/source-freshsales/source_freshsales/spec.json b/airbyte-integrations/connectors/source-freshsales/source_freshsales/spec.json new file mode 100644 index 000000000000..f4155198bc27 --- /dev/null +++ b/airbyte-integrations/connectors/source-freshsales/source_freshsales/spec.json @@ -0,0 +1,22 @@ +{ + "documentationUrl": "https://docsurl.com", + "connectionSpecification": { + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Freshsales Spec", + "type": "object", + "required": ["domain_name", "api_key"], + "additionalProperties": false, + "properties": { + "domain_name": { + "type": "string", + "description": "Freshsales domain", + "examples": ["mydomain.myfreshworks.com"] + }, + "api_key": { + "type": "string", + "description": "Your API Access Key. See here. The key is case sensitive.", + "airbyte_secret": true + } + } + } +} diff --git a/airbyte-integrations/connectors/source-freshsales/unit_tests/__init__.py b/airbyte-integrations/connectors/source-freshsales/unit_tests/__init__.py new file mode 100644 index 000000000000..46b7376756ec --- /dev/null +++ b/airbyte-integrations/connectors/source-freshsales/unit_tests/__init__.py @@ -0,0 +1,3 @@ +# +# Copyright (c) 2021 Airbyte, Inc., all rights reserved. +# diff --git a/airbyte-integrations/connectors/source-freshsales/unit_tests/conftest.py b/airbyte-integrations/connectors/source-freshsales/unit_tests/conftest.py new file mode 100644 index 000000000000..d03c2820311d --- /dev/null +++ b/airbyte-integrations/connectors/source-freshsales/unit_tests/conftest.py @@ -0,0 +1,13 @@ +# +# Copyright (c) 2021 Airbyte, Inc., all rights reserved. +# + +import json + +import pytest + + +@pytest.fixture(scope="session", name="config") +def config_fixture(): + with open("secrets/config.json", "r") as config_file: + return json.load(config_file) diff --git a/airbyte-integrations/connectors/source-freshsales/unit_tests/test_source.py b/airbyte-integrations/connectors/source-freshsales/unit_tests/test_source.py new file mode 100644 index 000000000000..132f3c417ad1 --- /dev/null +++ b/airbyte-integrations/connectors/source-freshsales/unit_tests/test_source.py @@ -0,0 +1,21 @@ +# +# Copyright (c) 2021 Airbyte, Inc., all rights reserved. +# + +from unittest.mock import MagicMock + +from source_freshsales.source import SourceFreshsales + + +def test_check_connection(mocker, config): + source = SourceFreshsales() + logger_mock = MagicMock() + assert source.check_connection(logger_mock, config) == (True, None) + + +def test_count_streams(mocker): + source = SourceFreshsales() + config_mock = MagicMock() + streams = source.streams(config_mock) + expected_streams_number = 9 + assert len(streams) == expected_streams_number