Skip to content

chore(internal): share client instances between all tests #145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 12 additions & 18 deletions tests/api_resources/beta/test_price.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,14 @@

from orb import Orb, AsyncOrb
from orb._utils import parse_datetime
from orb._client import Orb, AsyncOrb
from tests.utils import assert_matches_type
from orb.types.beta import PriceEvaluateResponse

base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
api_key = "My API Key"


class TestPrice:
strict_client = Orb(base_url=base_url, api_key=api_key, _strict_response_validation=True)
loose_client = Orb(base_url=base_url, api_key=api_key, _strict_response_validation=False)
parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"])
parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])

@parametrize
def test_method_evaluate(self, client: Orb) -> None:
Expand Down Expand Up @@ -83,22 +79,20 @@ def test_path_params_evaluate(self, client: Orb) -> None:


class TestAsyncPrice:
strict_client = AsyncOrb(base_url=base_url, api_key=api_key, _strict_response_validation=True)
loose_client = AsyncOrb(base_url=base_url, api_key=api_key, _strict_response_validation=False)
parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"])
parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])

@parametrize
async def test_method_evaluate(self, client: AsyncOrb) -> None:
price = await client.beta.price.evaluate(
async def test_method_evaluate(self, async_client: AsyncOrb) -> None:
price = await async_client.beta.price.evaluate(
"string",
timeframe_end=parse_datetime("2019-12-27T18:11:19.117Z"),
timeframe_start=parse_datetime("2019-12-27T18:11:19.117Z"),
)
assert_matches_type(PriceEvaluateResponse, price, path=["response"])

@parametrize
async def test_method_evaluate_with_all_params(self, client: AsyncOrb) -> None:
price = await client.beta.price.evaluate(
async def test_method_evaluate_with_all_params(self, async_client: AsyncOrb) -> None:
price = await async_client.beta.price.evaluate(
"string",
timeframe_end=parse_datetime("2019-12-27T18:11:19.117Z"),
timeframe_start=parse_datetime("2019-12-27T18:11:19.117Z"),
Expand All @@ -110,8 +104,8 @@ async def test_method_evaluate_with_all_params(self, client: AsyncOrb) -> None:
assert_matches_type(PriceEvaluateResponse, price, path=["response"])

@parametrize
async def test_raw_response_evaluate(self, client: AsyncOrb) -> None:
response = await client.beta.price.with_raw_response.evaluate(
async def test_raw_response_evaluate(self, async_client: AsyncOrb) -> None:
response = await async_client.beta.price.with_raw_response.evaluate(
"string",
timeframe_end=parse_datetime("2019-12-27T18:11:19.117Z"),
timeframe_start=parse_datetime("2019-12-27T18:11:19.117Z"),
Expand All @@ -123,8 +117,8 @@ async def test_raw_response_evaluate(self, client: AsyncOrb) -> None:
assert_matches_type(PriceEvaluateResponse, price, path=["response"])

@parametrize
async def test_streaming_response_evaluate(self, client: AsyncOrb) -> None:
async with client.beta.price.with_streaming_response.evaluate(
async def test_streaming_response_evaluate(self, async_client: AsyncOrb) -> None:
async with async_client.beta.price.with_streaming_response.evaluate(
"string",
timeframe_end=parse_datetime("2019-12-27T18:11:19.117Z"),
timeframe_start=parse_datetime("2019-12-27T18:11:19.117Z"),
Expand All @@ -138,9 +132,9 @@ async def test_streaming_response_evaluate(self, client: AsyncOrb) -> None:
assert cast(Any, response.is_closed) is True

@parametrize
async def test_path_params_evaluate(self, client: AsyncOrb) -> None:
async def test_path_params_evaluate(self, async_client: AsyncOrb) -> None:
with pytest.raises(ValueError, match=r"Expected a non-empty value for `price_id` but received ''"):
await client.beta.price.with_raw_response.evaluate(
await async_client.beta.price.with_raw_response.evaluate(
"",
timeframe_end=parse_datetime("2019-12-27T18:11:19.117Z"),
timeframe_start=parse_datetime("2019-12-27T18:11:19.117Z"),
Expand Down
30 changes: 12 additions & 18 deletions tests/api_resources/coupons/test_subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,14 @@

from orb import Orb, AsyncOrb
from orb.types import Subscription
from orb._client import Orb, AsyncOrb
from tests.utils import assert_matches_type
from orb.pagination import SyncPage, AsyncPage

base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
api_key = "My API Key"


class TestSubscriptions:
strict_client = Orb(base_url=base_url, api_key=api_key, _strict_response_validation=True)
loose_client = Orb(base_url=base_url, api_key=api_key, _strict_response_validation=False)
parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"])
parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])

@parametrize
def test_method_list(self, client: Orb) -> None:
Expand Down Expand Up @@ -71,29 +67,27 @@ def test_path_params_list(self, client: Orb) -> None:


class TestAsyncSubscriptions:
strict_client = AsyncOrb(base_url=base_url, api_key=api_key, _strict_response_validation=True)
loose_client = AsyncOrb(base_url=base_url, api_key=api_key, _strict_response_validation=False)
parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"])
parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])

@parametrize
async def test_method_list(self, client: AsyncOrb) -> None:
subscription = await client.coupons.subscriptions.list(
async def test_method_list(self, async_client: AsyncOrb) -> None:
subscription = await async_client.coupons.subscriptions.list(
"string",
)
assert_matches_type(AsyncPage[Subscription], subscription, path=["response"])

@parametrize
async def test_method_list_with_all_params(self, client: AsyncOrb) -> None:
subscription = await client.coupons.subscriptions.list(
async def test_method_list_with_all_params(self, async_client: AsyncOrb) -> None:
subscription = await async_client.coupons.subscriptions.list(
"string",
cursor="string",
limit=0,
)
assert_matches_type(AsyncPage[Subscription], subscription, path=["response"])

@parametrize
async def test_raw_response_list(self, client: AsyncOrb) -> None:
response = await client.coupons.subscriptions.with_raw_response.list(
async def test_raw_response_list(self, async_client: AsyncOrb) -> None:
response = await async_client.coupons.subscriptions.with_raw_response.list(
"string",
)

Expand All @@ -103,8 +97,8 @@ async def test_raw_response_list(self, client: AsyncOrb) -> None:
assert_matches_type(AsyncPage[Subscription], subscription, path=["response"])

@parametrize
async def test_streaming_response_list(self, client: AsyncOrb) -> None:
async with client.coupons.subscriptions.with_streaming_response.list(
async def test_streaming_response_list(self, async_client: AsyncOrb) -> None:
async with async_client.coupons.subscriptions.with_streaming_response.list(
"string",
) as response:
assert not response.is_closed
Expand All @@ -116,8 +110,8 @@ async def test_streaming_response_list(self, client: AsyncOrb) -> None:
assert cast(Any, response.is_closed) is True

@parametrize
async def test_path_params_list(self, client: AsyncOrb) -> None:
async def test_path_params_list(self, async_client: AsyncOrb) -> None:
with pytest.raises(ValueError, match=r"Expected a non-empty value for `coupon_id` but received ''"):
await client.coupons.subscriptions.with_raw_response.list(
await async_client.coupons.subscriptions.with_raw_response.list(
"",
)
Loading