Skip to content

Commit

Permalink
[wdspec] test for invalid subscription ids in unsubscribe (#50020)
Browse files Browse the repository at this point in the history
* [wdspec] Test for invalid subscription ids in unsubscribe

* fix optional
  • Loading branch information
OrKoN authored Jan 10, 2025
1 parent 3fc3dce commit 9acc23a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
11 changes: 8 additions & 3 deletions tools/webdriver/webdriver/bidi/modules/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,14 @@ def subscribe(self,

@command
def unsubscribe(self,
events: List[str],
contexts: Optional[List[str]] = None) -> Mapping[str, Any]:
params: MutableMapping[str, Any] = {"events": events}
events: Optional[List[str]] = None,
contexts: Optional[List[str]] = None,
subscriptions: Optional[List[str]] = None) -> Mapping[str, Any]:
params: MutableMapping[str, Any] = {}
if contexts is not None:
params["contexts"] = contexts
if events is not None:
params["events"] = events
if subscriptions is not None:
params["subscriptions"] = subscriptions
return params
14 changes: 14 additions & 0 deletions webdriver/tests/bidi/session/unsubscribe/invalid.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,17 @@ async def test_params_unsubscribe_from_one_context_with_global_subscription(
# Try to unsubscribe from one context
with pytest.raises(InvalidArgumentException):
await bidi_session.session.unsubscribe(events=["log.entryAdded"], contexts=[top_context["context"]])


@pytest.mark.asyncio
@pytest.mark.parametrize("subscriptions", [None, True, 42, {}, "foo"])
async def test_params_subscriptions_invalid_type(bidi_session, subscriptions):
with pytest.raises(InvalidArgumentException):
await bidi_session.session.unsubscribe(subscriptions=subscriptions)


@pytest.mark.asyncio
@pytest.mark.parametrize("subscriptions", [[""], ["12345678-1234-5678-1234-567812345678"]])
async def test_params_subscriptions_invalid_value(bidi_session, subscriptions):
with pytest.raises(InvalidArgumentException):
await bidi_session.session.unsubscribe(subscriptions=subscriptions)

0 comments on commit 9acc23a

Please sign in to comment.