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

Testing WEBHOOK_PAYLOAD_EXAMPLE deserialization #1732

Merged
merged 3 commits into from
Oct 13, 2023
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
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
Loading