diff --git a/airbyte-config/init/src/main/resources/seed/source_definitions.yaml b/airbyte-config/init/src/main/resources/seed/source_definitions.yaml index 08b6c7182ad5..83c22f9a971a 100644 --- a/airbyte-config/init/src/main/resources/seed/source_definitions.yaml +++ b/airbyte-config/init/src/main/resources/seed/source_definitions.yaml @@ -321,7 +321,7 @@ - name: Exchange Rates Api sourceDefinitionId: e2b40e36-aa0e-4bed-b41b-bcea6fa348b1 dockerRepository: airbyte/source-exchange-rates - dockerImageTag: 1.2.6 + dockerImageTag: 1.2.7 documentationUrl: https://docs.airbyte.com/integrations/sources/exchangeratesapi icon: exchangeratesapi.svg sourceType: api diff --git a/airbyte-config/init/src/main/resources/seed/source_specs.yaml b/airbyte-config/init/src/main/resources/seed/source_specs.yaml index 01df42f6377d..7e50b8c2d902 100644 --- a/airbyte-config/init/src/main/resources/seed/source_specs.yaml +++ b/airbyte-config/init/src/main/resources/seed/source_specs.yaml @@ -2794,7 +2794,7 @@ supportsDBT: false supported_destination_sync_modes: [] protocol_version: "0.2.1" -- dockerImage: "airbyte/source-exchange-rates:1.2.6" +- dockerImage: "airbyte/source-exchange-rates:1.2.7" spec: documentationUrl: "https://docs.airbyte.com/integrations/sources/exchangeratesapi" connectionSpecification: diff --git a/airbyte-integrations/connectors/source-exchange-rates/Dockerfile b/airbyte-integrations/connectors/source-exchange-rates/Dockerfile index 8b81bb2107c8..bdbd1d9f4da3 100644 --- a/airbyte-integrations/connectors/source-exchange-rates/Dockerfile +++ b/airbyte-integrations/connectors/source-exchange-rates/Dockerfile @@ -16,5 +16,5 @@ RUN pip install . ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py" ENTRYPOINT ["python", "/airbyte/integration_code/main.py"] -LABEL io.airbyte.version=1.2.6 +LABEL io.airbyte.version=1.2.7 LABEL io.airbyte.name=airbyte/source-exchange-rates diff --git a/airbyte-integrations/connectors/source-exchange-rates/source_exchange_rates/source.py b/airbyte-integrations/connectors/source-exchange-rates/source_exchange_rates/source.py index 9b45a5d06a7d..95183449df7a 100644 --- a/airbyte-integrations/connectors/source-exchange-rates/source_exchange_rates/source.py +++ b/airbyte-integrations/connectors/source-exchange-rates/source_exchange_rates/source.py @@ -101,7 +101,7 @@ def check_connection(self, logger: AirbyteLogger, config: Mapping[str, Any]) -> # When API requests is sent but the requested data is not available or the API call fails # for some reason, a JSON error is returned. # https://exchangeratesapi.io/documentation/#errors - error = resp.json().get("error") + error = resp.json().get("error", resp.json()) code = error.get("code") message = error.get("message") or error.get("info") # If code is base_currency_access_restricted, error is caused by switching base currency while using free diff --git a/airbyte-integrations/connectors/source-exchange-rates/unit_tests/__init__.py b/airbyte-integrations/connectors/source-exchange-rates/unit_tests/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/airbyte-integrations/connectors/source-exchange-rates/unit_tests/conftest.py b/airbyte-integrations/connectors/source-exchange-rates/unit_tests/conftest.py new file mode 100644 index 000000000000..24b680db9bed --- /dev/null +++ b/airbyte-integrations/connectors/source-exchange-rates/unit_tests/conftest.py @@ -0,0 +1,24 @@ +# +# Copyright (c) 2022 Airbyte, Inc., all rights reserved. +# + +from pytest import fixture + + +@fixture(name="config") +def config_fixture(requests_mock): + config = {"start_date": "2022-09-08", "base": "USD", "access_key": "KEY"} + + return config + + +@fixture(name="mock_stream") +def mock_stream_fixture(requests_mock): + def _mock_stream(path, response=None, status_code=200): + if response is None: + response = {} + + url = f"https://api.apilayer.com/exchangerates_data/{path}" + requests_mock.get(url, json=response, status_code=status_code) + + return _mock_stream diff --git a/airbyte-integrations/connectors/source-exchange-rates/unit_tests/test_source.py b/airbyte-integrations/connectors/source-exchange-rates/unit_tests/test_source.py new file mode 100644 index 000000000000..750ed6806c2b --- /dev/null +++ b/airbyte-integrations/connectors/source-exchange-rates/unit_tests/test_source.py @@ -0,0 +1,37 @@ +# +# Copyright (c) 2022 Airbyte, Inc., all rights reserved. +# + +import logging + +from source_exchange_rates.source import SourceExchangeRates + +logger = logging.getLogger("airbyte") + + +def test_check_connection_ok(config, mock_stream): + response = {"success": True, "timestamp": 1662681599, "historical": True, "base": "USD", "date": "2022-09-08", "rates": {"AED": 1}} + mock_stream(config["start_date"], response=response) + ok, error_msg = SourceExchangeRates().check_connection(logger, config=config) + + assert ok + assert not error_msg + + +def test_check_connection_exception(config, mock_stream): + message = ( + "You have exceeded your daily/monthly API rate limit. Please review and upgrade your subscription plan at " + "https://promptapi.com/subscriptions to continue. " + ) + response = {"message": message} + mock_stream(config["start_date"], response=response, status_code=429) + ok, error_msg = SourceExchangeRates().check_connection(logger, config=config) + + assert not ok + assert error_msg == message + + +def test_streams(config): + streams = SourceExchangeRates().streams(config) + + assert len(streams) == 1 diff --git a/docs/integrations/sources/exchangeratesapi.md b/docs/integrations/sources/exchangeratesapi.md index e5f33ace327b..6b4f79a305a1 100644 --- a/docs/integrations/sources/exchangeratesapi.md +++ b/docs/integrations/sources/exchangeratesapi.md @@ -44,13 +44,14 @@ If you have `free` subscription plan \(you may check it [here](https://manage.ex ## Changelog -| Version | Date | Pull Request | Subject | -|:--------| :--- | :--- | :--- | -| 1.2.6 | 2022-08-23 | [15884](https://github.com/airbytehq/airbyte/pull/15884) | Migrated to new API Layer endpoint | -| 0.2.6 | 2022-04-20 | [12230](https://github.com/airbytehq/airbyte/pull/12230) | Update connector to use a `spec.yaml` | -| 0.2.5 | 2021-11-12 | [7936](https://github.com/airbytehq/airbyte/pull/7936) | Add ignore_weekends boolean option | -| 0.2.4 | 2021-11-08 | [7499](https://github.com/airbytehq/airbyte/pull/7499) | Remove base-python dependencies | -| 0.2.3 | 2021-06-06 | [3973](https://github.com/airbytehq/airbyte/pull/3973) | Add `AIRBYTE_ENTRYPOINT` for kubernetes support | -| 0.2.2 | 2021-05-28 | [3677](https://github.com/airbytehq/airbyte/pull/3677) | Adding clearer error message when a currency isn't supported. access_key field in spec.json was marked as sensitive | -| 0.2.0 | 2021-05-26 | [3566](https://github.com/airbytehq/airbyte/pull/3566) | Move from `api.ratesapi.io/` to `api.exchangeratesapi.io/`. Add required field `access_key` to `config.json`. | -| 0.1.0 | 2021-04-19 | [2942](https://github.com/airbytehq/airbyte/pull/2942) | Implement Exchange API using the CDK | +| Version | Date | Pull Request | Subject | +|:--------| :--------- | :------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------- | +| 1.2.7 | 2022-10-31 | [18726](https://github.com/airbytehq/airbyte/pull/18726) | Fix handling error during check connection | +| 1.2.6 | 2022-08-23 | [15884](https://github.com/airbytehq/airbyte/pull/15884) | Migrated to new API Layer endpoint | +| 0.2.6 | 2022-04-20 | [12230](https://github.com/airbytehq/airbyte/pull/12230) | Update connector to use a `spec.yaml` | +| 0.2.5 | 2021-11-12 | [7936](https://github.com/airbytehq/airbyte/pull/7936) | Add ignore_weekends boolean option | +| 0.2.4 | 2021-11-08 | [7499](https://github.com/airbytehq/airbyte/pull/7499) | Remove base-python dependencies | +| 0.2.3 | 2021-06-06 | [3973](https://github.com/airbytehq/airbyte/pull/3973) | Add `AIRBYTE_ENTRYPOINT` for kubernetes support | +| 0.2.2 | 2021-05-28 | [3677](https://github.com/airbytehq/airbyte/pull/3677) | Adding clearer error message when a currency isn't supported. access_key field in spec.json was marked as sensitive | +| 0.2.0 | 2021-05-26 | [3566](https://github.com/airbytehq/airbyte/pull/3566) | Move from `api.ratesapi.io/` to `api.exchangeratesapi.io/`. Add required field `access_key` to `config.json`. | +| 0.1.0 | 2021-04-19 | [2942](https://github.com/airbytehq/airbyte/pull/2942) | Implement Exchange API using the CDK |