#34947: assertContains fails when there is unicode in the response json
-------------------------------------+-------------------------------------
     Reporter:  ideesnoires          |                    Owner:  nobody
         Type:  Bug                  |                   Status:  closed
    Component:  Testing framework    |                  Version:  4.2
     Severity:  Normal               |               Resolution:  invalid
     Keywords:  unicode, testing,    |             Triage Stage:
  assertcontains                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by David Sanders):

 * status:  new => closed
 * resolution:   => invalid


Comment:

 Hi ideesnoires,

 Thanks for your report though, the problem here isn't `assertContains()`,
 it's json serialisation in Python:
 https://docs.python.org/3/library/json.html#character-encodings

 By default json.dumps() sets `ensure_ascii=True`. This should be false for
 unicode.

 Here's the correct way to respond with unicode:

 {{{
 def äuuuß(request):
     return JsonResponse({"uml": "äuuuß"},
 json_dumps_params={"ensure_ascii": False})
 }}}

 With that your test will pass :)

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34947#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018ba520ca6f-5290394c-7784-453b-abd2-77096db3ea04-000000%40eu-central-1.amazonses.com.

Reply via email to