Opened 6 years ago
Closed 6 years ago
#31378 closed New feature (wontfix)
Support bytes in assertXMLEqual()/assertXMLNotEqual().
| Reported by: | Joe Germuska | Owned by: | nobody |
|---|---|---|---|
| Component: | Testing framework | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description (last modified by )
In writing a test case, I found that passing the test client's response.content object into TestCase.assertXMLEqual() resulted in this error: a bytes-like object is required, not 'str'
In tracing the code, this originates from django.test.utils.compare_xml, where string literals \\n and \n are passed to replace() even though the types of want and got (particularly got) may be bytes and not str.
The workaround is to decode the response content before calling assertXMLEqual (response.content.decode('utf-8')) and to pass the assertion comparison ("want") also as a string, but if this method is going to be used in the testing framework, it seems that it should tolerate directly passing in response.content, even if that's a bytes.
Change History (2)
comment:1 by , 6 years ago
| Description: | modified (diff) |
|---|
comment:2 by , 6 years ago
| Resolution: | → wontfix |
|---|---|
| Status: | new → closed |
| Summary: | django.test.utils compare_xml assumes string, errors on bytes → Support bytes in assertXMLEqual()/assertXMLNotEqual(). |
| Type: | Uncategorized → New feature |
It's documented that
assertXMLEqual()andassertXMLNotEqual()accept strings. I don't think we would like to complicate these methods, you can always useresponse.content.decode()(as you've already pointed out).