Skip to content

Commit 089f0d7

Browse files
chore(internal): codegen related update
1 parent a476549 commit 089f0d7

1 file changed

Lines changed: 28 additions & 10 deletions

File tree

tests/api_resources/test_webhooks.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ class TestWebhooks:
2222

2323
timestamp = "1676312382"
2424
fake_now = datetime.fromtimestamp(float(timestamp), tz=timezone.utc)
25-
2625
payload = """{"card_token":"sit Lorem ipsum, accusantium repellendus possimus","created_at":"elit. placeat libero architecto molestias, sit","account_token":"elit.","issuer_decision":"magnam, libero esse Lorem ipsum magnam, magnam,","tokenization_attempt_id":"illum dolor repellendus libero esse accusantium","wallet_decisioning_info":{"device_score":"placeat architecto"},"digital_wallet_token_metadata":{"status":"reprehenderit dolor","token_requestor_id":"possimus","payment_account_info":{"account_holder_data":{"phone_number":"libero","email_address":"nobis molestias, veniam culpa! quas elit. quas libero esse architecto placeat"},"pan_unique_reference":"adipisicing odit magnam, odit"}}}"""
2726
signature = "Dwa0AHInLL3XFo2sxcHamOQDrJNi7F654S3L6skMAOI="
2827
headers = {
@@ -31,15 +30,13 @@ class TestWebhooks:
3130
"webhook-signature": f"v1,{signature}",
3231
}
3332
secret = "whsec_zlFsbBZ8Xcodlpcu6NDTdSzZRLSdhkst"
34-
3533
@time_machine.travel(fake_now)
3634
def test_unwrap(self, client: Lithic) -> None:
3735
payload = self.payload
3836
headers = self.headers
3937
secret = self.secret
4038

4139
client.webhooks.unwrap(payload, headers, secret=secret)
42-
4340
@time_machine.travel(fake_now)
4441
def test_verify_signature(self, client: Lithic) -> None:
4542
payload = self.payload
@@ -120,7 +117,6 @@ def test_verify_signature(self, client: Lithic) -> None:
120117
headers=headers,
121118
secret=secret,
122119
)
123-
124120
@time_machine.travel(fake_now)
125121
def test_parse(self, client: Lithic) -> None:
126122
valid_payload = """{"event_type":"account_holder.created","token":"00000000-0000-0000-0000-000000000001","account_token":"00000000-0000-0000-0000-000000000001","created":"2019-12-27T18:11:19.117Z","status":"ACCEPTED"}"""
@@ -155,7 +151,6 @@ def test_parse(self, client: Lithic) -> None:
155151
wrong_secret = f"whsec_{base64.b64encode(b'wrong').decode('utf-8')}"
156152
with pytest.raises(standardwebhooks.WebhookVerificationError):
157153
client.webhooks.parse(valid_payload, headers=headers, secret=wrong_secret)
158-
159154
def test_parse_unsafe(self, client: Lithic) -> None:
160155
valid_payload = """{"event_type":"account_holder.created","token":"00000000-0000-0000-0000-000000000001","account_token":"00000000-0000-0000-0000-000000000001","created":"2019-12-27T18:11:19.117Z","status":"ACCEPTED"}"""
161156

@@ -166,14 +161,27 @@ def test_parse_unsafe(self, client: Lithic) -> None:
166161
assert isinstance(result, AccountHolderCreatedWebhookEvent)
167162
assert result.event_type == "account_holder.created"
168163
assert result.token == "00000000-0000-0000-0000-000000000001"
164+
@pytest.mark.parametrize(
165+
"client_opt,method_opt",
166+
[
167+
("whsec_c2VjcmV0Cg==", None),
168+
("wrong", b"secret\n"),
169+
("wrong", "whsec_c2VjcmV0Cg=="),
170+
(None, b"secret\n"),
171+
(None, "whsec_c2VjcmV0Cg=="),
172+
],
173+
)
174+
def test_method_parsed(self, client: Lithic, client_opt: str | None, method_opt: str | bytes | None) -> None:
175+
hook = standardwebhooks.Webhook(b"secret\n")
176+
177+
client = client.with_options(webhook_secret=client_opt)
169178

170179

171180
class TestAsyncWebhooks:
172181
parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])
173182

174183
timestamp = "1676312382"
175184
fake_now = datetime.fromtimestamp(float(timestamp), tz=timezone.utc)
176-
177185
payload = """{"card_token":"sit Lorem ipsum, accusantium repellendus possimus","created_at":"elit. placeat libero architecto molestias, sit","account_token":"elit.","issuer_decision":"magnam, libero esse Lorem ipsum magnam, magnam,","tokenization_attempt_id":"illum dolor repellendus libero esse accusantium","wallet_decisioning_info":{"device_score":"placeat architecto"},"digital_wallet_token_metadata":{"status":"reprehenderit dolor","token_requestor_id":"possimus","payment_account_info":{"account_holder_data":{"phone_number":"libero","email_address":"nobis molestias, veniam culpa! quas elit. quas libero esse architecto placeat"},"pan_unique_reference":"adipisicing odit magnam, odit"}}}"""
178186
signature = "Dwa0AHInLL3XFo2sxcHamOQDrJNi7F654S3L6skMAOI="
179187
headers = {
@@ -182,15 +190,13 @@ class TestAsyncWebhooks:
182190
"webhook-signature": f"v1,{signature}",
183191
}
184192
secret = "whsec_zlFsbBZ8Xcodlpcu6NDTdSzZRLSdhkst"
185-
186193
@time_machine.travel(fake_now)
187194
def test_unwrap(self, async_client: AsyncLithic) -> None:
188195
payload = self.payload
189196
headers = self.headers
190197
secret = self.secret
191198

192199
async_client.webhooks.unwrap(payload, headers, secret=secret)
193-
194200
@time_machine.travel(fake_now)
195201
def test_verify_signature(self, async_client: AsyncLithic) -> None:
196202
payload = self.payload
@@ -271,7 +277,6 @@ def test_verify_signature(self, async_client: AsyncLithic) -> None:
271277
headers=headers,
272278
secret=secret,
273279
)
274-
275280
@time_machine.travel(fake_now)
276281
def test_parse(self, async_client: AsyncLithic) -> None:
277282
valid_payload = """{"event_type":"account_holder.created","token":"00000000-0000-0000-0000-000000000001","account_token":"00000000-0000-0000-0000-000000000001","created":"2019-12-27T18:11:19.117Z","status":"ACCEPTED"}"""
@@ -306,7 +311,6 @@ def test_parse(self, async_client: AsyncLithic) -> None:
306311
wrong_secret = f"whsec_{base64.b64encode(b'wrong').decode('utf-8')}"
307312
with pytest.raises(standardwebhooks.WebhookVerificationError):
308313
async_client.webhooks.parse(valid_payload, headers=headers, secret=wrong_secret)
309-
310314
def test_parse_unsafe(self, async_client: AsyncLithic) -> None:
311315
valid_payload = """{"event_type":"account_holder.created","token":"00000000-0000-0000-0000-000000000001","account_token":"00000000-0000-0000-0000-000000000001","created":"2019-12-27T18:11:19.117Z","status":"ACCEPTED"}"""
312316

@@ -317,3 +321,17 @@ def test_parse_unsafe(self, async_client: AsyncLithic) -> None:
317321
assert isinstance(result, AccountHolderCreatedWebhookEvent)
318322
assert result.event_type == "account_holder.created"
319323
assert result.token == "00000000-0000-0000-0000-000000000001"
324+
@pytest.mark.parametrize(
325+
"client_opt,method_opt",
326+
[
327+
("whsec_c2VjcmV0Cg==", None),
328+
("wrong", b"secret\n"),
329+
("wrong", "whsec_c2VjcmV0Cg=="),
330+
(None, b"secret\n"),
331+
(None, "whsec_c2VjcmV0Cg=="),
332+
],
333+
)
334+
def test_method_parsed(self, async_client: Lithic, client_opt: str | None, method_opt: str | bytes | None) -> None:
335+
hook = standardwebhooks.Webhook(b"secret\n")
336+
337+
async_client = async_client.with_options(webhook_secret=client_opt)

0 commit comments

Comments
 (0)