diff --git a/ntropy_sdk/__init__.py b/ntropy_sdk/__init__.py index 3783a97..d7b7dbf 100644 --- a/ntropy_sdk/__init__.py +++ b/ntropy_sdk/__init__.py @@ -38,8 +38,6 @@ class ExtraKwargs(TypedDict, total=False): NtropyRuntimeError, ) -from .transactions import ( - TransactionInput, LocationInput -) +from .transactions import TransactionInput, LocationInput from .account_holders import AccountHolder diff --git a/ntropy_sdk/http.py b/ntropy_sdk/http.py index 6df0892..bc7e7e5 100644 --- a/ntropy_sdk/http.py +++ b/ntropy_sdk/http.py @@ -18,6 +18,7 @@ def _get_session(self) -> requests.Session: if self._session is None: self._session = requests.Session() from requests_toolbelt.adapters.socket_options import TCPKeepAliveAdapter + self._session.mount("https://", TCPKeepAliveAdapter()) return self._session diff --git a/ntropy_sdk/sdk.py b/ntropy_sdk/sdk.py index 67158c9..f0c157d 100644 --- a/ntropy_sdk/sdk.py +++ b/ntropy_sdk/sdk.py @@ -44,9 +44,11 @@ def retry_ratelimited_request( if self.api_key and not kwargs_copy.get("api_key"): kwargs_copy["api_key"] = self.api_key - return self.http_client.retry_ratelimited_request(method=method, - url=self.base_url + url, - params=params, - payload=payload, - payload_json_str=payload_json_str, - **kwargs_copy) + return self.http_client.retry_ratelimited_request( + method=method, + url=self.base_url + url, + params=params, + payload=payload, + payload_json_str=payload_json_str, + **kwargs_copy, + ) diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index 197d0e6..0000000 --- a/tests/__init__.py +++ /dev/null @@ -1,8 +0,0 @@ -import os - - -API_KEY = os.environ.get("NTROPY_API_KEY") - - -if not API_KEY: - raise RuntimeError("Environment variable NTROPY_API_KEY is not defined") diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..d6afd8f --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,13 @@ +import os + +import pytest + + +@pytest.fixture() +def api_key(): + key = os.environ.get("NTROPY_API_KEY") + + if not key: + raise RuntimeError("Environment variable NTROPY_API_KEY is not defined") + + return key diff --git a/tests/v2/conftest.py b/tests/v2/conftest.py index e57075f..881a949 100644 --- a/tests/v2/conftest.py +++ b/tests/v2/conftest.py @@ -3,12 +3,11 @@ import pytest as pytest from ntropy_sdk.v2 import SDK -from .. import API_KEY @pytest.fixture -def sdk(): - sdk = SDK(API_KEY) +def sdk(api_key): + sdk = SDK(api_key) url = os.environ.get("NTROPY_API_URL") if url is not None: diff --git a/tests/v2/test_recurring_payments.py b/tests/v2/test_recurring_payments.py index e5a1cc0..11ce374 100644 --- a/tests/v2/test_recurring_payments.py +++ b/tests/v2/test_recurring_payments.py @@ -1,18 +1,6 @@ import os import pytest from ntropy_sdk.v2 import SDK, Transaction -from tests import API_KEY - - -@pytest.fixture -def sdk(): - sdk = SDK(API_KEY) - - url = os.environ.get("NTROPY_API_URL") - if url is not None: - sdk.base_url = url - - return sdk @pytest.fixture diff --git a/tests/v2/test_sdk.py b/tests/v2/test_v2_sdk.py similarity index 98% rename from tests/v2/test_sdk.py rename to tests/v2/test_v2_sdk.py index 205c928..af0893c 100644 --- a/tests/v2/test_sdk.py +++ b/tests/v2/test_v2_sdk.py @@ -17,7 +17,6 @@ from ntropy_sdk.v2.errors import NtropyValueError, NtropyBatchError from ntropy_sdk.utils import TransactionType from ntropy_sdk.v2.ntropy_sdk import ACCOUNT_HOLDER_TYPES -from tests import API_KEY def test_account_holder_type(): @@ -503,7 +502,7 @@ def test_enriched_fields(sdk): # assert 5432 in enriched.mcc -def test_sdk_region(): +def test_sdk_region(api_key): ah_id = str(uuid.uuid4()) tx = Transaction( amount=24.56, @@ -515,28 +514,28 @@ def test_sdk_region(): iso_currency_code="USD", ) - _sdk = SDK(API_KEY) + _sdk = SDK(api_key) assert _sdk.base_url == "https://api.ntropy.com" res = _sdk.add_transactions([tx])[0] assert res.website is not None - _sdk = SDK(API_KEY, region="us") + _sdk = SDK(api_key, region="us") assert _sdk.base_url == "https://api.ntropy.com" res = _sdk.add_transactions([tx])[0] assert res.website is not None - _sdk = SDK(API_KEY, region="eu") + _sdk = SDK(api_key, region="eu") assert _sdk.base_url == "https://api.eu.ntropy.com" res = _sdk.add_transactions([tx])[0] assert res.website is not None with pytest.raises(ValueError): - _sdk = SDK(API_KEY, region="atlantida") + _sdk = SDK(api_key, region="atlantida") @pytest.fixture() -def async_sdk(): - sdk = SDK(API_KEY) +def async_sdk(api_key): + sdk = SDK(api_key) sdk._make_batch = make_batch with patch.object(sdk, "MAX_SYNC_BATCH", 0): @@ -545,8 +544,8 @@ def async_sdk(): @pytest.fixture() -def sync_sdk(): - sdk = SDK(API_KEY) +def sync_sdk(api_key): + sdk = SDK(api_key) sdk._make_batch = lambda batch_status, results: results with patch.object(sdk, "MAX_SYNC_BATCH", 999999): diff --git a/tests/v3/conftest.py b/tests/v3/conftest.py index da41dcd..f4fd923 100644 --- a/tests/v3/conftest.py +++ b/tests/v3/conftest.py @@ -3,12 +3,11 @@ import pytest as pytest from ntropy_sdk import SDK -from .. import API_KEY @pytest.fixture -def sdk(): - sdk = SDK(API_KEY) +def sdk(api_key): + sdk = SDK(api_key) url = os.environ.get("NTROPY_API_URL") if url is not None: diff --git a/tests/v3/test_sdk.py b/tests/v3/test_sdk.py index af532a5..37ff327 100644 --- a/tests/v3/test_sdk.py +++ b/tests/v3/test_sdk.py @@ -1,7 +1,6 @@ import os from itertools import islice from ntropy_sdk import SDK -from .. import API_KEY def test_pagination(sdk: SDK): @@ -12,10 +11,10 @@ def test_pagination(sdk: SDK): assert len(tx_ids) == 10 -def test_readme(): +def test_readme(api_key): readme_file = open( os.path.join(os.path.dirname(__file__), "..", "..", "README.md") ).read() readme_data = readme_file.split("```python")[1].split("```")[0] - readme_data = readme_data.replace("YOUR-API-KEY", API_KEY) + readme_data = readme_data.replace("YOUR-API-KEY", api_key) exec(readme_data, globals())