Skip to content

Commit

Permalink
Testing WEBHOOK_PAYLOAD_EXAMPLE deserialization (#1732)
Browse files Browse the repository at this point in the history
* Added test that the WEBHOOK_PAYLOAD_EXAMPLE can be deserialized

* Added defaults for Optional fields so tests can pass

---------

Co-authored-by: Lucain <lucainp@gmail.com>
  • Loading branch information
jamesbraza and Wauplin authored Oct 13, 2023
1 parent 865ace1 commit 9f343e0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/huggingface_hub/_webhooks_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ObjectId(BaseModel):

class WebhookPayloadUrl(BaseModel):
web: str
api: Optional[str]
api: Optional[str] = None


class WebhookPayloadMovedTo(BaseModel):
Expand All @@ -74,7 +74,7 @@ class WebhookPayloadEvent(BaseModel):

class WebhookPayloadDiscussionChanges(BaseModel):
base: str
mergeCommitId: Optional[str]
mergeCommitId: Optional[str] = None


class WebhookPayloadComment(ObjectId):
Expand All @@ -92,16 +92,16 @@ class WebhookPayloadDiscussion(ObjectId):
isPullRequest: bool
status: DiscussionStatus_T
changes: Optional[WebhookPayloadDiscussionChanges]
pinned: Optional[bool]
pinned: Optional[bool] = None


class WebhookPayloadRepo(ObjectId):
owner: ObjectId
head_sha: Optional[str]
head_sha: Optional[str] = None
name: str
private: bool
subdomain: Optional[str]
tags: Optional[List[str]]
subdomain: Optional[str] = None
tags: Optional[List[str]] = None
type: Literal["dataset", "model", "space"]
url: WebhookPayloadUrl

Expand All @@ -112,4 +112,4 @@ class WebhookPayload(BaseModel):
discussion: Optional[WebhookPayloadDiscussion]
comment: Optional[WebhookPayloadComment]
webhook: WebhookPayloadWebhook
movedTo: Optional[WebhookPayloadMovedTo]
movedTo: Optional[WebhookPayloadMovedTo] = None
6 changes: 6 additions & 0 deletions tests/test_webhooks_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@
}


def test_deserialize_payload_example() -> None:
"""Confirm that the test stub can actually be deserialized."""
payload = WebhookPayload.parse_obj(WEBHOOK_PAYLOAD_EXAMPLE)
assert payload.event.scope == WEBHOOK_PAYLOAD_EXAMPLE["event"]["scope"]


@require_webhooks
class TestWebhooksServerDontRun(unittest.TestCase):
def test_add_webhook_implicit_path(self):
Expand Down

0 comments on commit 9f343e0

Please sign in to comment.