Skip to content

Commit 7d4cf28

Browse files
chore(tests): improve enum examples (#734)
1 parent 1ac880a commit 7d4cf28

File tree

7 files changed

+75
-41
lines changed

7 files changed

+75
-41
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ from lithic import Lithic
152152
client = Lithic()
153153

154154
card = client.cards.create(
155-
type="MERCHANT_LOCKED",
155+
type="VIRTUAL",
156156
)
157157
print(card.product_id)
158158
```

src/lithic/_utils/_transform.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ def _maybe_transform_key(key: str, type_: type) -> str:
142142
return key
143143

144144

145+
def _no_transform_needed(annotation: type) -> bool:
146+
return annotation == float or annotation == int
147+
148+
145149
def _transform_recursive(
146150
data: object,
147151
*,
@@ -184,6 +188,15 @@ def _transform_recursive(
184188
return cast(object, data)
185189

186190
inner_type = extract_type_arg(stripped_type, 0)
191+
if _no_transform_needed(inner_type):
192+
# for some types there is no need to transform anything, so we can get a small
193+
# perf boost from skipping that work.
194+
#
195+
# but we still need to convert to a list to ensure the data is json-serializable
196+
if is_list(data):
197+
return data
198+
return list(data)
199+
187200
return [_transform_recursive(d, annotation=annotation, inner_type=inner_type) for d in data]
188201

189202
if is_union_type(stripped_type):
@@ -332,6 +345,15 @@ async def _async_transform_recursive(
332345
return cast(object, data)
333346

334347
inner_type = extract_type_arg(stripped_type, 0)
348+
if _no_transform_needed(inner_type):
349+
# for some types there is no need to transform anything, so we can get a small
350+
# perf boost from skipping that work.
351+
#
352+
# but we still need to convert to a list to ensure the data is json-serializable
353+
if is_list(data):
354+
return data
355+
return list(data)
356+
335357
return [await _async_transform_recursive(d, annotation=annotation, inner_type=inner_type) for d in data]
336358

337359
if is_union_type(stripped_type):

tests/api_resources/test_cards.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ class TestCards:
2626
@parametrize
2727
def test_method_create(self, client: Lithic) -> None:
2828
card = client.cards.create(
29-
type="MERCHANT_LOCKED",
29+
type="VIRTUAL",
3030
)
3131
assert_matches_type(Card, card, path=["response"])
3232

3333
@parametrize
3434
def test_method_create_with_all_params(self, client: Lithic) -> None:
3535
card = client.cards.create(
36-
type="MERCHANT_LOCKED",
36+
type="VIRTUAL",
3737
account_token="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
3838
card_program_token="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
3939
carrier={"qr_code_url": "qr_code_url"},
@@ -60,15 +60,15 @@ def test_method_create_with_all_params(self, client: Lithic) -> None:
6060
},
6161
shipping_method="2_DAY",
6262
spend_limit=1000,
63-
spend_limit_duration="ANNUALLY",
63+
spend_limit_duration="TRANSACTION",
6464
state="OPEN",
6565
)
6666
assert_matches_type(Card, card, path=["response"])
6767

6868
@parametrize
6969
def test_raw_response_create(self, client: Lithic) -> None:
7070
response = client.cards.with_raw_response.create(
71-
type="MERCHANT_LOCKED",
71+
type="VIRTUAL",
7272
)
7373

7474
assert response.is_closed is True
@@ -79,7 +79,7 @@ def test_raw_response_create(self, client: Lithic) -> None:
7979
@parametrize
8080
def test_streaming_response_create(self, client: Lithic) -> None:
8181
with client.cards.with_streaming_response.create(
82-
type="MERCHANT_LOCKED",
82+
type="VIRTUAL",
8383
) as response:
8484
assert not response.is_closed
8585
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
@@ -143,8 +143,8 @@ def test_method_update_with_all_params(self, client: Lithic) -> None:
143143
pin="pin",
144144
pin_status="OK",
145145
spend_limit=100,
146-
spend_limit_duration="ANNUALLY",
147-
state="CLOSED",
146+
spend_limit_duration="FOREVER",
147+
state="OPEN",
148148
)
149149
assert_matches_type(Card, card, path=["response"])
150150

@@ -252,7 +252,7 @@ def test_method_convert_physical_with_all_params(self, client: Lithic) -> None:
252252
},
253253
carrier={"qr_code_url": "https://lithic.com/activate-card/1"},
254254
product_id="100",
255-
shipping_method="2_DAY",
255+
shipping_method="STANDARD",
256256
)
257257
assert_matches_type(Card, card, path=["response"])
258258

@@ -362,7 +362,7 @@ def test_method_provision_with_all_params(self, client: Lithic) -> None:
362362
certificate="U3RhaW5sZXNzIHJvY2tz",
363363
client_device_id="client_device_id",
364364
client_wallet_account_id="client_wallet_account_id",
365-
digital_wallet="APPLE_PAY",
365+
digital_wallet="GOOGLE_PAY",
366366
nonce="U3RhaW5sZXNzIHJvY2tz",
367367
nonce_signature="U3RhaW5sZXNzIHJvY2tz",
368368
)
@@ -425,7 +425,7 @@ def test_method_reissue_with_all_params(self, client: Lithic) -> None:
425425
"line2_text": "The Bluth Company",
426426
"phone_number": "+15555555555",
427427
},
428-
shipping_method="2_DAY",
428+
shipping_method="STANDARD",
429429
)
430430
assert_matches_type(Card, card, path=["response"])
431431

@@ -497,7 +497,7 @@ def test_method_renew_with_all_params(self, client: Lithic) -> None:
497497
exp_month="06",
498498
exp_year="2027",
499499
product_id="100",
500-
shipping_method="2_DAY",
500+
shipping_method="STANDARD",
501501
)
502502
assert_matches_type(Card, card, path=["response"])
503503

@@ -635,14 +635,14 @@ class TestAsyncCards:
635635
@parametrize
636636
async def test_method_create(self, async_client: AsyncLithic) -> None:
637637
card = await async_client.cards.create(
638-
type="MERCHANT_LOCKED",
638+
type="VIRTUAL",
639639
)
640640
assert_matches_type(Card, card, path=["response"])
641641

642642
@parametrize
643643
async def test_method_create_with_all_params(self, async_client: AsyncLithic) -> None:
644644
card = await async_client.cards.create(
645-
type="MERCHANT_LOCKED",
645+
type="VIRTUAL",
646646
account_token="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
647647
card_program_token="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
648648
carrier={"qr_code_url": "qr_code_url"},
@@ -669,15 +669,15 @@ async def test_method_create_with_all_params(self, async_client: AsyncLithic) ->
669669
},
670670
shipping_method="2_DAY",
671671
spend_limit=1000,
672-
spend_limit_duration="ANNUALLY",
672+
spend_limit_duration="TRANSACTION",
673673
state="OPEN",
674674
)
675675
assert_matches_type(Card, card, path=["response"])
676676

677677
@parametrize
678678
async def test_raw_response_create(self, async_client: AsyncLithic) -> None:
679679
response = await async_client.cards.with_raw_response.create(
680-
type="MERCHANT_LOCKED",
680+
type="VIRTUAL",
681681
)
682682

683683
assert response.is_closed is True
@@ -688,7 +688,7 @@ async def test_raw_response_create(self, async_client: AsyncLithic) -> None:
688688
@parametrize
689689
async def test_streaming_response_create(self, async_client: AsyncLithic) -> None:
690690
async with async_client.cards.with_streaming_response.create(
691-
type="MERCHANT_LOCKED",
691+
type="VIRTUAL",
692692
) as response:
693693
assert not response.is_closed
694694
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
@@ -752,8 +752,8 @@ async def test_method_update_with_all_params(self, async_client: AsyncLithic) ->
752752
pin="pin",
753753
pin_status="OK",
754754
spend_limit=100,
755-
spend_limit_duration="ANNUALLY",
756-
state="CLOSED",
755+
spend_limit_duration="FOREVER",
756+
state="OPEN",
757757
)
758758
assert_matches_type(Card, card, path=["response"])
759759

@@ -861,7 +861,7 @@ async def test_method_convert_physical_with_all_params(self, async_client: Async
861861
},
862862
carrier={"qr_code_url": "https://lithic.com/activate-card/1"},
863863
product_id="100",
864-
shipping_method="2_DAY",
864+
shipping_method="STANDARD",
865865
)
866866
assert_matches_type(Card, card, path=["response"])
867867

@@ -971,7 +971,7 @@ async def test_method_provision_with_all_params(self, async_client: AsyncLithic)
971971
certificate="U3RhaW5sZXNzIHJvY2tz",
972972
client_device_id="client_device_id",
973973
client_wallet_account_id="client_wallet_account_id",
974-
digital_wallet="APPLE_PAY",
974+
digital_wallet="GOOGLE_PAY",
975975
nonce="U3RhaW5sZXNzIHJvY2tz",
976976
nonce_signature="U3RhaW5sZXNzIHJvY2tz",
977977
)
@@ -1034,7 +1034,7 @@ async def test_method_reissue_with_all_params(self, async_client: AsyncLithic) -
10341034
"line2_text": "The Bluth Company",
10351035
"phone_number": "+15555555555",
10361036
},
1037-
shipping_method="2_DAY",
1037+
shipping_method="STANDARD",
10381038
)
10391039
assert_matches_type(Card, card, path=["response"])
10401040

@@ -1106,7 +1106,7 @@ async def test_method_renew_with_all_params(self, async_client: AsyncLithic) ->
11061106
exp_month="06",
11071107
exp_year="2027",
11081108
product_id="100",
1109-
shipping_method="2_DAY",
1109+
shipping_method="STANDARD",
11101110
)
11111111
assert_matches_type(Card, card, path=["response"])
11121112

tests/api_resources/test_disputes.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class TestDisputes:
2626
def test_method_create(self, client: Lithic) -> None:
2727
dispute = client.disputes.create(
2828
amount=10000,
29-
reason="ATM_CASH_MISDISPENSE",
29+
reason="FRAUD_CARD_PRESENT",
3030
transaction_token="12345624-aa69-4cbc-a946-30d90181b621",
3131
)
3232
assert_matches_type(Dispute, dispute, path=["response"])
@@ -35,7 +35,7 @@ def test_method_create(self, client: Lithic) -> None:
3535
def test_method_create_with_all_params(self, client: Lithic) -> None:
3636
dispute = client.disputes.create(
3737
amount=10000,
38-
reason="ATM_CASH_MISDISPENSE",
38+
reason="FRAUD_CARD_PRESENT",
3939
transaction_token="12345624-aa69-4cbc-a946-30d90181b621",
4040
customer_filed_date=parse_datetime("2021-06-28T22:53:15Z"),
4141
customer_note="customer_note",
@@ -46,7 +46,7 @@ def test_method_create_with_all_params(self, client: Lithic) -> None:
4646
def test_raw_response_create(self, client: Lithic) -> None:
4747
response = client.disputes.with_raw_response.create(
4848
amount=10000,
49-
reason="ATM_CASH_MISDISPENSE",
49+
reason="FRAUD_CARD_PRESENT",
5050
transaction_token="12345624-aa69-4cbc-a946-30d90181b621",
5151
)
5252

@@ -59,7 +59,7 @@ def test_raw_response_create(self, client: Lithic) -> None:
5959
def test_streaming_response_create(self, client: Lithic) -> None:
6060
with client.disputes.with_streaming_response.create(
6161
amount=10000,
62-
reason="ATM_CASH_MISDISPENSE",
62+
reason="FRAUD_CARD_PRESENT",
6363
transaction_token="12345624-aa69-4cbc-a946-30d90181b621",
6464
) as response:
6565
assert not response.is_closed
@@ -433,7 +433,7 @@ class TestAsyncDisputes:
433433
async def test_method_create(self, async_client: AsyncLithic) -> None:
434434
dispute = await async_client.disputes.create(
435435
amount=10000,
436-
reason="ATM_CASH_MISDISPENSE",
436+
reason="FRAUD_CARD_PRESENT",
437437
transaction_token="12345624-aa69-4cbc-a946-30d90181b621",
438438
)
439439
assert_matches_type(Dispute, dispute, path=["response"])
@@ -442,7 +442,7 @@ async def test_method_create(self, async_client: AsyncLithic) -> None:
442442
async def test_method_create_with_all_params(self, async_client: AsyncLithic) -> None:
443443
dispute = await async_client.disputes.create(
444444
amount=10000,
445-
reason="ATM_CASH_MISDISPENSE",
445+
reason="FRAUD_CARD_PRESENT",
446446
transaction_token="12345624-aa69-4cbc-a946-30d90181b621",
447447
customer_filed_date=parse_datetime("2021-06-28T22:53:15Z"),
448448
customer_note="customer_note",
@@ -453,7 +453,7 @@ async def test_method_create_with_all_params(self, async_client: AsyncLithic) ->
453453
async def test_raw_response_create(self, async_client: AsyncLithic) -> None:
454454
response = await async_client.disputes.with_raw_response.create(
455455
amount=10000,
456-
reason="ATM_CASH_MISDISPENSE",
456+
reason="FRAUD_CARD_PRESENT",
457457
transaction_token="12345624-aa69-4cbc-a946-30d90181b621",
458458
)
459459

@@ -466,7 +466,7 @@ async def test_raw_response_create(self, async_client: AsyncLithic) -> None:
466466
async def test_streaming_response_create(self, async_client: AsyncLithic) -> None:
467467
async with async_client.disputes.with_streaming_response.create(
468468
amount=10000,
469-
reason="ATM_CASH_MISDISPENSE",
469+
reason="FRAUD_CARD_PRESENT",
470470
transaction_token="12345624-aa69-4cbc-a946-30d90181b621",
471471
) as response:
472472
assert not response.is_closed

tests/api_resources/test_tokenizations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def test_method_resend_activation_code(self, client: Lithic) -> None:
226226
def test_method_resend_activation_code_with_all_params(self, client: Lithic) -> None:
227227
tokenization = client.tokenizations.resend_activation_code(
228228
tokenization_token="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
229-
activation_method_type="EMAIL_TO_CARDHOLDER_ADDRESS",
229+
activation_method_type="TEXT_TO_CARDHOLDER_NUMBER",
230230
)
231231
assert tokenization is None
232232

@@ -605,7 +605,7 @@ async def test_method_resend_activation_code(self, async_client: AsyncLithic) ->
605605
async def test_method_resend_activation_code_with_all_params(self, async_client: AsyncLithic) -> None:
606606
tokenization = await async_client.tokenizations.resend_activation_code(
607607
tokenization_token="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
608-
activation_method_type="EMAIL_TO_CARDHOLDER_ADDRESS",
608+
activation_method_type="TEXT_TO_CARDHOLDER_NUMBER",
609609
)
610610
assert tokenization is None
611611

tests/test_client.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
768768

769769
respx_mock.post("/v1/cards").mock(side_effect=retry_handler)
770770

771-
response = client.cards.with_raw_response.create(type="MERCHANT_LOCKED")
771+
response = client.cards.with_raw_response.create(type="VIRTUAL")
772772

773773
assert response.retries_taken == failures_before_success
774774
assert int(response.http_request.headers.get("x-stainless-retry-count")) == failures_before_success
@@ -793,7 +793,7 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
793793
respx_mock.post("/v1/cards").mock(side_effect=retry_handler)
794794

795795
response = client.cards.with_raw_response.create(
796-
type="MERCHANT_LOCKED", extra_headers={"x-stainless-retry-count": Omit()}
796+
type="VIRTUAL", extra_headers={"x-stainless-retry-count": Omit()}
797797
)
798798

799799
assert len(response.http_request.headers.get_list("x-stainless-retry-count")) == 0
@@ -818,7 +818,7 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
818818
respx_mock.post("/v1/cards").mock(side_effect=retry_handler)
819819

820820
response = client.cards.with_raw_response.create(
821-
type="MERCHANT_LOCKED", extra_headers={"x-stainless-retry-count": "42"}
821+
type="VIRTUAL", extra_headers={"x-stainless-retry-count": "42"}
822822
)
823823

824824
assert response.http_request.headers.get("x-stainless-retry-count") == "42"
@@ -842,7 +842,7 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
842842

843843
respx_mock.post("/v1/cards").mock(side_effect=retry_handler)
844844

845-
with client.cards.with_streaming_response.create(type="MERCHANT_LOCKED") as response:
845+
with client.cards.with_streaming_response.create(type="VIRTUAL") as response:
846846
assert response.retries_taken == failures_before_success
847847
assert int(response.http_request.headers.get("x-stainless-retry-count")) == failures_before_success
848848

@@ -1582,7 +1582,7 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
15821582

15831583
respx_mock.post("/v1/cards").mock(side_effect=retry_handler)
15841584

1585-
response = await client.cards.with_raw_response.create(type="MERCHANT_LOCKED")
1585+
response = await client.cards.with_raw_response.create(type="VIRTUAL")
15861586

15871587
assert response.retries_taken == failures_before_success
15881588
assert int(response.http_request.headers.get("x-stainless-retry-count")) == failures_before_success
@@ -1608,7 +1608,7 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
16081608
respx_mock.post("/v1/cards").mock(side_effect=retry_handler)
16091609

16101610
response = await client.cards.with_raw_response.create(
1611-
type="MERCHANT_LOCKED", extra_headers={"x-stainless-retry-count": Omit()}
1611+
type="VIRTUAL", extra_headers={"x-stainless-retry-count": Omit()}
16121612
)
16131613

16141614
assert len(response.http_request.headers.get_list("x-stainless-retry-count")) == 0
@@ -1634,7 +1634,7 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
16341634
respx_mock.post("/v1/cards").mock(side_effect=retry_handler)
16351635

16361636
response = await client.cards.with_raw_response.create(
1637-
type="MERCHANT_LOCKED", extra_headers={"x-stainless-retry-count": "42"}
1637+
type="VIRTUAL", extra_headers={"x-stainless-retry-count": "42"}
16381638
)
16391639

16401640
assert response.http_request.headers.get("x-stainless-retry-count") == "42"
@@ -1659,7 +1659,7 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
16591659

16601660
respx_mock.post("/v1/cards").mock(side_effect=retry_handler)
16611661

1662-
async with client.cards.with_streaming_response.create(type="MERCHANT_LOCKED") as response:
1662+
async with client.cards.with_streaming_response.create(type="VIRTUAL") as response:
16631663
assert response.retries_taken == failures_before_success
16641664
assert int(response.http_request.headers.get("x-stainless-retry-count")) == failures_before_success
16651665

0 commit comments

Comments
 (0)