Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed parseSnapshotEvent #1406

Merged
merged 2 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading