Skip to content

Commit 88082b9

Browse files
chore(tests): improve enum examples (#734)
1 parent b373ff1 commit 88082b9

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

@@ -374,7 +374,7 @@ def test_method_provision_with_all_params(self, client: Lithic) -> None:
374374
certificate="U3RhaW5sZXNzIHJvY2tz",
375375
client_device_id="client_device_id",
376376
client_wallet_account_id="client_wallet_account_id",
377-
digital_wallet="APPLE_PAY",
377+
digital_wallet="GOOGLE_PAY",
378378
nonce="U3RhaW5sZXNzIHJvY2tz",
379379
nonce_signature="U3RhaW5sZXNzIHJvY2tz",
380380
)
@@ -437,7 +437,7 @@ def test_method_reissue_with_all_params(self, client: Lithic) -> None:
437437
"line2_text": "The Bluth Company",
438438
"phone_number": "+15555555555",
439439
},
440-
shipping_method="2_DAY",
440+
shipping_method="STANDARD",
441441
)
442442
assert_matches_type(Card, card, path=["response"])
443443

@@ -509,7 +509,7 @@ def test_method_renew_with_all_params(self, client: Lithic) -> None:
509509
exp_month="06",
510510
exp_year="2027",
511511
product_id="100",
512-
shipping_method="2_DAY",
512+
shipping_method="STANDARD",
513513
)
514514
assert_matches_type(Card, card, path=["response"])
515515

@@ -647,14 +647,14 @@ class TestAsyncCards:
647647
@parametrize
648648
async def test_method_create(self, async_client: AsyncLithic) -> None:
649649
card = await async_client.cards.create(
650-
type="MERCHANT_LOCKED",
650+
type="VIRTUAL",
651651
)
652652
assert_matches_type(Card, card, path=["response"])
653653

654654
@parametrize
655655
async def test_method_create_with_all_params(self, async_client: AsyncLithic) -> None:
656656
card = await async_client.cards.create(
657-
type="MERCHANT_LOCKED",
657+
type="VIRTUAL",
658658
account_token="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
659659
card_program_token="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
660660
carrier={"qr_code_url": "qr_code_url"},
@@ -681,15 +681,15 @@ async def test_method_create_with_all_params(self, async_client: AsyncLithic) ->
681681
},
682682
shipping_method="2_DAY",
683683
spend_limit=1000,
684-
spend_limit_duration="ANNUALLY",
684+
spend_limit_duration="TRANSACTION",
685685
state="OPEN",
686686
)
687687
assert_matches_type(Card, card, path=["response"])
688688

689689
@parametrize
690690
async def test_raw_response_create(self, async_client: AsyncLithic) -> None:
691691
response = await async_client.cards.with_raw_response.create(
692-
type="MERCHANT_LOCKED",
692+
type="VIRTUAL",
693693
)
694694

695695
assert response.is_closed is True
@@ -700,7 +700,7 @@ async def test_raw_response_create(self, async_client: AsyncLithic) -> None:
700700
@parametrize
701701
async def test_streaming_response_create(self, async_client: AsyncLithic) -> None:
702702
async with async_client.cards.with_streaming_response.create(
703-
type="MERCHANT_LOCKED",
703+
type="VIRTUAL",
704704
) as response:
705705
assert not response.is_closed
706706
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
@@ -764,8 +764,8 @@ async def test_method_update_with_all_params(self, async_client: AsyncLithic) ->
764764
pin="pin",
765765
pin_status="OK",
766766
spend_limit=100,
767-
spend_limit_duration="ANNUALLY",
768-
state="CLOSED",
767+
spend_limit_duration="FOREVER",
768+
state="OPEN",
769769
)
770770
assert_matches_type(Card, card, path=["response"])
771771

@@ -873,7 +873,7 @@ async def test_method_convert_physical_with_all_params(self, async_client: Async
873873
},
874874
carrier={"qr_code_url": "https://lithic.com/activate-card/1"},
875875
product_id="100",
876-
shipping_method="2_DAY",
876+
shipping_method="STANDARD",
877877
)
878878
assert_matches_type(Card, card, path=["response"])
879879

@@ -995,7 +995,7 @@ async def test_method_provision_with_all_params(self, async_client: AsyncLithic)
995995
certificate="U3RhaW5sZXNzIHJvY2tz",
996996
client_device_id="client_device_id",
997997
client_wallet_account_id="client_wallet_account_id",
998-
digital_wallet="APPLE_PAY",
998+
digital_wallet="GOOGLE_PAY",
999999
nonce="U3RhaW5sZXNzIHJvY2tz",
10001000
nonce_signature="U3RhaW5sZXNzIHJvY2tz",
10011001
)
@@ -1058,7 +1058,7 @@ async def test_method_reissue_with_all_params(self, async_client: AsyncLithic) -
10581058
"line2_text": "The Bluth Company",
10591059
"phone_number": "+15555555555",
10601060
},
1061-
shipping_method="2_DAY",
1061+
shipping_method="STANDARD",
10621062
)
10631063
assert_matches_type(Card, card, path=["response"])
10641064

@@ -1130,7 +1130,7 @@ async def test_method_renew_with_all_params(self, async_client: AsyncLithic) ->
11301130
exp_month="06",
11311131
exp_year="2027",
11321132
product_id="100",
1133-
shipping_method="2_DAY",
1133+
shipping_method="STANDARD",
11341134
)
11351135
assert_matches_type(Card, card, path=["response"])
11361136

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)