Skip to content

Commit abb41b2

Browse files
jacalataclaude
andcommitted
Refactor subscription case-preservation tests to parse XML
Copilot noted that substring-matching the serialized XML is brittle: attribute quoting (single vs double), whitespace, and entity escaping can vary without changing meaning. Parse the request with defusedxml (matching the existing test_encoding_attr_capture style at line 361) and assert on the parsed attribute value instead. The load-bearing check is still "the value is not lowercased", which is what site_elem.attrib["customSubscriptionEmail"] == "Sales@Company.com" verifies. Test now survives serialization-format changes and still fails if the .lower() regression comes back. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent a501ac7 commit abb41b2

1 file changed

Lines changed: 10 additions & 12 deletions

File tree

test/test_site.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,12 @@ def test_update_subscription_email_and_footer_preserve_case() -> None:
213213
site.custom_subscription_email = "Sales@Company.com"
214214
site.custom_subscription_footer = "Sent by Tableau -- Confidential. See https://Example.com/Legal"
215215

216-
xml_bytes = RequestFactory.Site.update_req(site)
217-
xml_text = xml_bytes.decode("utf-8")
218-
219-
assert 'customSubscriptionEmail="Sales@Company.com"' in xml_text, xml_text
220-
assert (
221-
'customSubscriptionFooter="Sent by Tableau -- Confidential. See https://Example.com/Legal"' in xml_text
222-
), xml_text
216+
site_elem = ET.fromstring(RequestFactory.Site.update_req(site)).find(".//site")
217+
assert site_elem is not None
218+
assert site_elem.attrib["customSubscriptionEmail"] == "Sales@Company.com"
219+
assert site_elem.attrib["customSubscriptionFooter"] == (
220+
"Sent by Tableau -- Confidential. See https://Example.com/Legal"
221+
)
223222

224223

225224
def test_create_subscription_email_and_footer_preserve_case() -> None:
@@ -228,11 +227,10 @@ def test_create_subscription_email_and_footer_preserve_case() -> None:
228227
site.custom_subscription_email = "Support@Company.com"
229228
site.custom_subscription_footer = "COMPANY, Inc. -- All Rights Reserved."
230229

231-
xml_bytes = RequestFactory.Site.create_req(site)
232-
xml_text = xml_bytes.decode("utf-8")
233-
234-
assert 'customSubscriptionEmail="Support@Company.com"' in xml_text, xml_text
235-
assert 'customSubscriptionFooter="COMPANY, Inc. -- All Rights Reserved."' in xml_text, xml_text
230+
site_elem = ET.fromstring(RequestFactory.Site.create_req(site)).find(".//site")
231+
assert site_elem is not None
232+
assert site_elem.attrib["customSubscriptionEmail"] == "Support@Company.com"
233+
assert site_elem.attrib["customSubscriptionFooter"] == "COMPANY, Inc. -- All Rights Reserved."
236234

237235

238236
def test_null_site_quota(server: TSC.Server) -> None:

0 commit comments

Comments
 (0)