Skip to content

Commit 64a4cb6

Browse files
chore(internal): share client instances between all tests (#145)
1 parent 72734a3 commit 64a4cb6

23 files changed

+894
-993
lines changed

tests/api_resources/beta/test_price.py

+12-18
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,14 @@
99

1010
from orb import Orb, AsyncOrb
1111
from orb._utils import parse_datetime
12-
from orb._client import Orb, AsyncOrb
1312
from tests.utils import assert_matches_type
1413
from orb.types.beta import PriceEvaluateResponse
1514

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

1917

2018
class TestPrice:
21-
strict_client = Orb(base_url=base_url, api_key=api_key, _strict_response_validation=True)
22-
loose_client = Orb(base_url=base_url, api_key=api_key, _strict_response_validation=False)
23-
parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"])
19+
parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
2420

2521
@parametrize
2622
def test_method_evaluate(self, client: Orb) -> None:
@@ -83,22 +79,20 @@ def test_path_params_evaluate(self, client: Orb) -> None:
8379

8480

8581
class TestAsyncPrice:
86-
strict_client = AsyncOrb(base_url=base_url, api_key=api_key, _strict_response_validation=True)
87-
loose_client = AsyncOrb(base_url=base_url, api_key=api_key, _strict_response_validation=False)
88-
parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"])
82+
parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])
8983

9084
@parametrize
91-
async def test_method_evaluate(self, client: AsyncOrb) -> None:
92-
price = await client.beta.price.evaluate(
85+
async def test_method_evaluate(self, async_client: AsyncOrb) -> None:
86+
price = await async_client.beta.price.evaluate(
9387
"string",
9488
timeframe_end=parse_datetime("2019-12-27T18:11:19.117Z"),
9589
timeframe_start=parse_datetime("2019-12-27T18:11:19.117Z"),
9690
)
9791
assert_matches_type(PriceEvaluateResponse, price, path=["response"])
9892

9993
@parametrize
100-
async def test_method_evaluate_with_all_params(self, client: AsyncOrb) -> None:
101-
price = await client.beta.price.evaluate(
94+
async def test_method_evaluate_with_all_params(self, async_client: AsyncOrb) -> None:
95+
price = await async_client.beta.price.evaluate(
10296
"string",
10397
timeframe_end=parse_datetime("2019-12-27T18:11:19.117Z"),
10498
timeframe_start=parse_datetime("2019-12-27T18:11:19.117Z"),
@@ -110,8 +104,8 @@ async def test_method_evaluate_with_all_params(self, client: AsyncOrb) -> None:
110104
assert_matches_type(PriceEvaluateResponse, price, path=["response"])
111105

112106
@parametrize
113-
async def test_raw_response_evaluate(self, client: AsyncOrb) -> None:
114-
response = await client.beta.price.with_raw_response.evaluate(
107+
async def test_raw_response_evaluate(self, async_client: AsyncOrb) -> None:
108+
response = await async_client.beta.price.with_raw_response.evaluate(
115109
"string",
116110
timeframe_end=parse_datetime("2019-12-27T18:11:19.117Z"),
117111
timeframe_start=parse_datetime("2019-12-27T18:11:19.117Z"),
@@ -123,8 +117,8 @@ async def test_raw_response_evaluate(self, client: AsyncOrb) -> None:
123117
assert_matches_type(PriceEvaluateResponse, price, path=["response"])
124118

125119
@parametrize
126-
async def test_streaming_response_evaluate(self, client: AsyncOrb) -> None:
127-
async with client.beta.price.with_streaming_response.evaluate(
120+
async def test_streaming_response_evaluate(self, async_client: AsyncOrb) -> None:
121+
async with async_client.beta.price.with_streaming_response.evaluate(
128122
"string",
129123
timeframe_end=parse_datetime("2019-12-27T18:11:19.117Z"),
130124
timeframe_start=parse_datetime("2019-12-27T18:11:19.117Z"),
@@ -138,9 +132,9 @@ async def test_streaming_response_evaluate(self, client: AsyncOrb) -> None:
138132
assert cast(Any, response.is_closed) is True
139133

140134
@parametrize
141-
async def test_path_params_evaluate(self, client: AsyncOrb) -> None:
135+
async def test_path_params_evaluate(self, async_client: AsyncOrb) -> None:
142136
with pytest.raises(ValueError, match=r"Expected a non-empty value for `price_id` but received ''"):
143-
await client.beta.price.with_raw_response.evaluate(
137+
await async_client.beta.price.with_raw_response.evaluate(
144138
"",
145139
timeframe_end=parse_datetime("2019-12-27T18:11:19.117Z"),
146140
timeframe_start=parse_datetime("2019-12-27T18:11:19.117Z"),

tests/api_resources/coupons/test_subscriptions.py

+12-18
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,14 @@
99

1010
from orb import Orb, AsyncOrb
1111
from orb.types import Subscription
12-
from orb._client import Orb, AsyncOrb
1312
from tests.utils import assert_matches_type
1413
from orb.pagination import SyncPage, AsyncPage
1514

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

1917

2018
class TestSubscriptions:
21-
strict_client = Orb(base_url=base_url, api_key=api_key, _strict_response_validation=True)
22-
loose_client = Orb(base_url=base_url, api_key=api_key, _strict_response_validation=False)
23-
parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"])
19+
parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
2420

2521
@parametrize
2622
def test_method_list(self, client: Orb) -> None:
@@ -71,29 +67,27 @@ def test_path_params_list(self, client: Orb) -> None:
7167

7268

7369
class TestAsyncSubscriptions:
74-
strict_client = AsyncOrb(base_url=base_url, api_key=api_key, _strict_response_validation=True)
75-
loose_client = AsyncOrb(base_url=base_url, api_key=api_key, _strict_response_validation=False)
76-
parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"])
70+
parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])
7771

7872
@parametrize
79-
async def test_method_list(self, client: AsyncOrb) -> None:
80-
subscription = await client.coupons.subscriptions.list(
73+
async def test_method_list(self, async_client: AsyncOrb) -> None:
74+
subscription = await async_client.coupons.subscriptions.list(
8175
"string",
8276
)
8377
assert_matches_type(AsyncPage[Subscription], subscription, path=["response"])
8478

8579
@parametrize
86-
async def test_method_list_with_all_params(self, client: AsyncOrb) -> None:
87-
subscription = await client.coupons.subscriptions.list(
80+
async def test_method_list_with_all_params(self, async_client: AsyncOrb) -> None:
81+
subscription = await async_client.coupons.subscriptions.list(
8882
"string",
8983
cursor="string",
9084
limit=0,
9185
)
9286
assert_matches_type(AsyncPage[Subscription], subscription, path=["response"])
9387

9488
@parametrize
95-
async def test_raw_response_list(self, client: AsyncOrb) -> None:
96-
response = await client.coupons.subscriptions.with_raw_response.list(
89+
async def test_raw_response_list(self, async_client: AsyncOrb) -> None:
90+
response = await async_client.coupons.subscriptions.with_raw_response.list(
9791
"string",
9892
)
9993

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

10599
@parametrize
106-
async def test_streaming_response_list(self, client: AsyncOrb) -> None:
107-
async with client.coupons.subscriptions.with_streaming_response.list(
100+
async def test_streaming_response_list(self, async_client: AsyncOrb) -> None:
101+
async with async_client.coupons.subscriptions.with_streaming_response.list(
108102
"string",
109103
) as response:
110104
assert not response.is_closed
@@ -116,8 +110,8 @@ async def test_streaming_response_list(self, client: AsyncOrb) -> None:
116110
assert cast(Any, response.is_closed) is True
117111

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

0 commit comments

Comments
 (0)