Skip to content

Commit

Permalink
api_key fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
adgsantos committed Oct 21, 2024
1 parent 70c3b85 commit 44392c0
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 48 deletions.
4 changes: 1 addition & 3 deletions ntropy_sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions ntropy_sdk/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 8 additions & 6 deletions ntropy_sdk/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
8 changes: 0 additions & 8 deletions tests/__init__.py

This file was deleted.

13 changes: 13 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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
5 changes: 2 additions & 3 deletions tests/v2/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 0 additions & 12 deletions tests/v2/test_recurring_payments.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
19 changes: 9 additions & 10 deletions tests/v2/test_sdk.py → tests/v2/test_v2_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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,
Expand All @@ -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):
Expand All @@ -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):
Expand Down
5 changes: 2 additions & 3 deletions tests/v3/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 2 additions & 3 deletions tests/v3/test_sdk.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
from itertools import islice
from ntropy_sdk import SDK
from .. import API_KEY


def test_pagination(sdk: SDK):
Expand All @@ -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())

0 comments on commit 44392c0

Please sign in to comment.