Skip to content

Commit 64f68fd

Browse files
jacalataclaude
andcommitted
test: strengthen webhook update test coverage
Tighten test_update_missing_id to assert MissingRequiredFieldError specifically. Add tests for update_req serializing url and event, omitting isEnabled when None, partial (name-only) updates, and correct parsing of isEnabled="false" from XML. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 21b2cdd commit 64f68fd

1 file changed

Lines changed: 58 additions & 1 deletion

File tree

test/test_webhook.py

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def test_update(server: TSC.Server) -> None:
202202
def test_update_missing_id(server: TSC.Server) -> None:
203203
webhook_item = WebhookItem()
204204
webhook_item.name = "some-webhook"
205-
with pytest.raises(Exception):
205+
with pytest.raises(TSC.MissingRequiredFieldError):
206206
server.webhooks.update(webhook_item)
207207

208208

@@ -217,3 +217,60 @@ def test_update_request_factory_is_enabled() -> None:
217217

218218
assert 'isEnabled="false"' in request_str
219219
assert "webhook-name" in request_str
220+
221+
222+
def test_update_request_factory_url_and_event() -> None:
223+
"""update_req should serialize url and event into the request body."""
224+
webhook_item = WebhookItem()
225+
webhook_item._set_values("webhook-id", "webhook-name", "https://example.com/hook", "datasource-created", None)
226+
227+
request_bytes = RequestFactory.Webhook.update_req(webhook_item)
228+
request_str = request_bytes.decode("utf-8")
229+
230+
assert "https://example.com/hook" in request_str
231+
assert "webhook-source-event-datasource-created" in request_str
232+
assert 'method="POST"' in request_str
233+
234+
235+
def test_update_request_factory_partial_update_name_only() -> None:
236+
"""update_req with only name set should omit url, event, and isEnabled."""
237+
webhook_item = WebhookItem()
238+
webhook_item.name = "new-name"
239+
240+
request_bytes = RequestFactory.Webhook.update_req(webhook_item)
241+
request_str = request_bytes.decode("utf-8")
242+
243+
assert "new-name" in request_str
244+
assert "isEnabled" not in request_str
245+
assert "webhook-source" not in request_str
246+
assert "webhook-destination" not in request_str
247+
248+
249+
def test_update_request_factory_omits_is_enabled_when_none() -> None:
250+
"""update_req should not emit isEnabled when is_enabled is None."""
251+
webhook_item = WebhookItem()
252+
webhook_item._set_values("webhook-id", "webhook-name", "https://example.com/hook", "datasource-created", None)
253+
# is_enabled is None by default
254+
255+
request_bytes = RequestFactory.Webhook.update_req(webhook_item)
256+
request_str = request_bytes.decode("utf-8")
257+
258+
assert "isEnabled" not in request_str
259+
260+
261+
def test_parse_is_enabled_false() -> None:
262+
"""isEnabled='false' in XML should parse to boolean False."""
263+
xml = (
264+
b"<?xml version='1.0' encoding='UTF-8'?>"
265+
b'<tsResponse xmlns="http://tableau.com/api">'
266+
b' <webhook id="wh-1" name="wh" isEnabled="false">'
267+
b" <webhook-source><webhook-source-event-datasource-created /></webhook-source>"
268+
b' <webhook-destination><webhook-destination-http method="POST" url="https://x.example.com/h"/>'
269+
b" </webhook-destination>"
270+
b" </webhook>"
271+
b"</tsResponse>"
272+
)
273+
ns = {"t": "http://tableau.com/api"}
274+
webhooks = WebhookItem.from_response(xml, ns)
275+
assert len(webhooks) == 1
276+
assert webhooks[0].is_enabled is False

0 commit comments

Comments
 (0)