🐛Source Exchange Rates: Fix handling error during check connection (#18726)
* Fix handling error during check connection * Updated PR number * auto-bump connector version Co-authored-by: Octavia Squidington III <octavia-squidington-iii@users.noreply.github.com>
This commit is contained in:
@@ -328,7 +328,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
|
||||
|
||||
@@ -2835,7 +2835,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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -101,7 +101,7 @@ class SourceExchangeRates(AbstractSource):
|
||||
# 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
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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 |
|
||||
|
||||
Reference in New Issue
Block a user