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

ViewTestCases doesn't handle unicode correctly #415

Closed
glennmatthews opened this issue May 7, 2021 · 0 comments · Fixed by #416
Closed

ViewTestCases doesn't handle unicode correctly #415

glennmatthews opened this issue May 7, 2021 · 0 comments · Fixed by #416
Assignees
Labels
type: bug Something isn't working as expected type: housekeeping Changes to the application which do not directly impact the end user

Comments

@glennmatthews
Copy link
Contributor

Proposed Changes

Throughout nautobot/utilities/testing/views.py, HTTP response content is cast to an ASCII string via str(response.content). This results in any unicode characters being rendered as escape sequences (e.g. Region ɑ is rendered as Region \\xc9\\x91), which can result in test failures if the string being searched for in the content is mangled in this way and so is not detectable in the content.

A more correct pattern would be to use response.content.decode(response.charset) as this will correctly render Unicode and allow tests using Unicode strings to pass.

Justification

It's 2021, we shouldn't be enforcing ASCII anywhere, much less in our tests.

@glennmatthews glennmatthews added type: bug Something isn't working as expected type: housekeeping Changes to the application which do not directly impact the end user labels May 7, 2021
@glennmatthews glennmatthews self-assigned this May 7, 2021
glennmatthews added a commit that referenced this issue May 10, 2021
* Handle unicode in view tests (fixes #415), improve view test failure messages

* Use `msg` kwarg

Co-authored-by: Jathan McCollum <jathan@gmail.com>

Co-authored-by: Jathan McCollum <jathan@gmail.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug Something isn't working as expected type: housekeeping Changes to the application which do not directly impact the end user
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant