Skip to content

Commit

Permalink
Removed parseSnapshotEvent (#1406)
Browse files Browse the repository at this point in the history
  • Loading branch information
prathmesh-stripe authored Oct 1, 2024
1 parent 206b394 commit ae9cfd1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion stripe/_stripe_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def parse_thin_event(

return ThinEvent(payload)

def parse_snapshot_event(
def construct_event(
self,
payload: Union[bytes, str],
sig_header: str,
Expand Down
18 changes: 18 additions & 0 deletions stripe/v2/_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,29 @@ class ThinEvent:
"""

id: str
"""
Unique identifier for the event.
"""
type: str
"""
The type of the event.
"""
created: str
"""
Time at which the object was created.
"""
context: Optional[str] = None
"""
[Optional] Authentication context needed to fetch the event or related object.
"""
related_object: Optional[RelatedObject] = None
"""
[Optional] Object containing the reference to API resource relevant to the event.
"""
reason: Optional[Reason] = None
"""
[Optional] Reason for the event.
"""

def __init__(self, payload: str) -> None:
parsed = json.loads(payload)
Expand Down
12 changes: 6 additions & 6 deletions tests/test_webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def test_timestamp_off_but_no_tolerance(self):
class TestStripeClientConstructEvent(object):
def test_construct_event(self, stripe_mock_stripe_client):
header = generate_header()
event = stripe_mock_stripe_client.parse_snapshot_event(
event = stripe_mock_stripe_client.construct_event(
DUMMY_WEBHOOK_PAYLOAD, header, DUMMY_WEBHOOK_SECRET
)
assert isinstance(event, stripe.Event)
Expand All @@ -144,29 +144,29 @@ def test_raise_on_json_error(self, stripe_mock_stripe_client):
payload = "this is not valid JSON"
header = generate_header(payload=payload)
with pytest.raises(ValueError):
stripe_mock_stripe_client.parse_snapshot_event(
stripe_mock_stripe_client.construct_event(
payload, header, DUMMY_WEBHOOK_SECRET
)

def test_raise_on_invalid_header(self, stripe_mock_stripe_client):
header = "bad_header"
with pytest.raises(stripe.error.SignatureVerificationError):
stripe_mock_stripe_client.parse_snapshot_event(
stripe_mock_stripe_client.construct_event(
DUMMY_WEBHOOK_PAYLOAD, header, DUMMY_WEBHOOK_SECRET
)

def test_construct_event_from_bytearray(self, stripe_mock_stripe_client):
header = generate_header()
payload = bytearray(DUMMY_WEBHOOK_PAYLOAD, "utf-8")
event = stripe_mock_stripe_client.parse_snapshot_event(
event = stripe_mock_stripe_client.construct_event(
payload, header, DUMMY_WEBHOOK_SECRET
)
assert isinstance(event, stripe.Event)

def test_construct_event_from_bytes(self, stripe_mock_stripe_client):
header = generate_header()
payload = bytes(DUMMY_WEBHOOK_PAYLOAD, "utf-8")
event = stripe_mock_stripe_client.parse_snapshot_event(
event = stripe_mock_stripe_client.construct_event(
payload, header, DUMMY_WEBHOOK_SECRET
)
assert isinstance(event, stripe.Event)
Expand All @@ -181,7 +181,7 @@ def test_construct_event_inherits_requestor(self, http_client_mock):
http_client=http_client_mock.get_mock_http_client(),
)
header = generate_header()
event = client.parse_snapshot_event(
event = client.construct_event(
DUMMY_WEBHOOK_PAYLOAD, header, DUMMY_WEBHOOK_SECRET
)
assert event._requestor == client._requestor
Expand Down

0 comments on commit ae9cfd1

Please sign in to comment.