-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛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 <[email protected]>
- Loading branch information
1 parent
bc09083
commit e45aec3
Showing
8 changed files
with
76 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
24 changes: 24 additions & 0 deletions
24
airbyte-integrations/connectors/source-exchange-rates/unit_tests/conftest.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
37 changes: 37 additions & 0 deletions
37
airbyte-integrations/connectors/source-exchange-rates/unit_tests/test_source.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters