Hello everyone.
I'm using WebTest-2.0.23 and python 2.7 and noticed a difference in *_json
(e.g. post_json) methods and real application application requests.
There is a WSGI application which accepts some data from a POST request.
Data is a json encoded object. One of it's fields contains unicode string.
Each request is logged using default logger (like 'log.info(request)')
To test the application with an external tool, I use curl:
> curl -H 'Content-Type: application/json' -d '{1:1, 2:1, 3:"擭䋰몙迋탺괶",
> 4:"test"}' http://localhost/post_test
>
In this case in logs I receive exact string posted.
The same result is observed is a request comes from any other application:
a real browser, wget, scripts.
To test the application using webtest I use a snippet like this ('app' is a
configured webtest application):
> app.post_json('/post_test', {1:1, 2:1, 3:"擭䋰몙迋탺괶", 4:"test"})
I assume this should result in the same request being formed for an
application.
Yet, I end up with the third parameter logged as a sequence of '\uXXXX'
escapes (like "\u7eea\u7c0e\u3ca5\u17e8\ub35c\uced2\u5a9b\u5da0")
If I change json_method in webtest/utils.py so that json.dumps is called
with 'ensure_ascii=False' in the 'wrapper' function I get similar behaviour
for WebTest and real applications.
This is somehow important because this results in some cases not being
tested with webtest. For example, in case of careless cast to a string
instead of a unicode type real application test causes an exception while
webtest doesn't.
Is this an intended behaviour? Should I use 'app.post' and encode json on
my own or do I provide a patch for this? Is there any other workaround?
Best regards,
Ippolitov igor.
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/pylons-discuss/df6a9477-8482-465a-a397-fdf56facdecd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.