Opened 12 years ago
Closed 12 years ago
#19995 closed Bug (needsinfo)
[Django Testing Framework] Client.get() and UnicodeEncodeError
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Testing framework | Version: | 1.4 |
Severity: | Normal | Keywords: | test client unicode |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Hi,
I'm use the Client API to test my views, and here is one of my test :
def test_04_edit_page(self): # Verify the page doesn't exist response = self.client.get('/wiki/wiki-test-hehe/Page') self.assertEqual(response.status_code, 302) # if the page is not found, the wiki redirect the user to an edit page # Check GET on edit page response = self.client.get('/wiki/wiki-test-hehe/Page/edit') self.assertEqual(response.status_code, 200) # Now send data response = self.client.post('/wiki/wiki-test-hehe/Page/edit', { 'path': 'Page', 'content': u'Test héhé', 'comment': u'Commentaire de test héhé', }) self.assertEqual(response.status_code, 302) # after an edit, the wiki redirect the user to the page # And now, check that the new page exists response = self.client.get('/wiki/wiki-test-hehe/Page') self.assertEqual(response.status_code, 200)
The error raise at the last get request :
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 1: ordinal not in range(128)
Here is the full traceback :
Traceback (most recent call last): File "/home/david/Documents/projects/pompadour-wiki/pompadour_wiki/pompadour_wiki/apps/wiki/tests.py", line 98, in test_05_remove_page self.test_04_edit_page() File "/home/david/Documents/projects/pompadour-wiki/pompadour_wiki/pompadour_wiki/apps/wiki/tests.py", line 93, in test_04_edit_page response = self.client.get('/wiki/wiki-test-hehe/Page') File "/home/david/Documents/projects/pompadour-wiki/pompadour_wiki/.venv/local/lib/python2.7/site-packages/django/test/client.py", line 439, in get response = super(Client, self).get(path, data=data, **extra) File "/home/david/Documents/projects/pompadour-wiki/pompadour_wiki/.venv/local/lib/python2.7/site-packages/django/test/client.py", line 244, in get return self.request(**r) File "/home/david/Documents/projects/pompadour-wiki/pompadour_wiki/.venv/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 111, in get_response response = callback(request, *callback_args, **callback_kwargs) File "/home/david/Documents/projects/pompadour-wiki/pompadour_wiki/.venv/local/lib/python2.7/site-packages/django/contrib/auth/decorators.py", line 20, in _wrapped_view return view_func(request, *args, **kwargs) File "/home/david/Documents/projects/pompadour-wiki/pompadour_wiki/pompadour_wiki/apps/utils/decorators.py", line 57, in wrapper return render_to_response(template, output, context_instance=RequestContext(request), mimetype=mimetype) File "/home/david/Documents/projects/pompadour-wiki/pompadour_wiki/.venv/local/lib/python2.7/site-packages/django/shortcuts/__init__.py", line 20, in render_to_response return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs) File "/home/david/Documents/projects/pompadour-wiki/pompadour_wiki/.venv/local/lib/python2.7/site-packages/django/template/loader.py", line 176, in render_to_string return t.render(context_instance) File "/home/david/Documents/projects/pompadour-wiki/pompadour_wiki/.venv/local/lib/python2.7/site-packages/django/template/base.py", line 140, in render return self._render(context) File "/home/david/Documents/projects/pompadour-wiki/pompadour_wiki/.venv/local/lib/python2.7/site-packages/django/test/utils.py", line 62, in instrumented_test_render return self.nodelist.render(context) File "/home/david/Documents/projects/pompadour-wiki/pompadour_wiki/.venv/local/lib/python2.7/site-packages/django/template/base.py", line 823, in render bit = self.render_node(node, context) File "/home/david/Documents/projects/pompadour-wiki/pompadour_wiki/.venv/local/lib/python2.7/site-packages/django/template/debug.py", line 74, in render_node return node.render(context) File "/home/david/Documents/projects/pompadour-wiki/pompadour_wiki/.venv/local/lib/python2.7/site-packages/django/template/loader_tags.py", line 123, in render return compiled_parent._render(context) File "/home/david/Documents/projects/pompadour-wiki/pompadour_wiki/.venv/local/lib/python2.7/site-packages/django/test/utils.py", line 62, in instrumented_test_render return self.nodelist.render(context) File "/home/david/Documents/projects/pompadour-wiki/pompadour_wiki/.venv/local/lib/python2.7/site-packages/django/template/base.py", line 823, in render bit = self.render_node(node, context) File "/home/david/Documents/projects/pompadour-wiki/pompadour_wiki/.venv/local/lib/python2.7/site-packages/django/template/debug.py", line 74, in render_node return node.render(context) File "/home/david/Documents/projects/pompadour-wiki/pompadour_wiki/.venv/local/lib/python2.7/site-packages/django/template/loader_tags.py", line 123, in render return compiled_parent._render(context) File "/home/david/Documents/projects/pompadour-wiki/pompadour_wiki/.venv/local/lib/python2.7/site-packages/django/test/utils.py", line 62, in instrumented_test_render return self.nodelist.render(context) File "/home/david/Documents/projects/pompadour-wiki/pompadour_wiki/.venv/local/lib/python2.7/site-packages/django/template/base.py", line 823, in render bit = self.render_node(node, context) File "/home/david/Documents/projects/pompadour-wiki/pompadour_wiki/.venv/local/lib/python2.7/site-packages/django/template/debug.py", line 74, in render_node return node.render(context) File "/home/david/Documents/projects/pompadour-wiki/pompadour_wiki/.venv/local/lib/python2.7/site-packages/django/template/loader_tags.py", line 62, in render result = block.nodelist.render(context) File "/home/david/Documents/projects/pompadour-wiki/pompadour_wiki/.venv/local/lib/python2.7/site-packages/django/template/base.py", line 823, in render bit = self.render_node(node, context) File "/home/david/Documents/projects/pompadour-wiki/pompadour_wiki/.venv/local/lib/python2.7/site-packages/django/template/debug.py", line 74, in render_node return node.render(context) File "/home/david/Documents/projects/pompadour-wiki/pompadour_wiki/.venv/local/lib/python2.7/site-packages/django/template/defaulttags.py", line 185, in render nodelist.append(node.render(context)) File "/home/david/Documents/projects/pompadour-wiki/pompadour_wiki/.venv/local/lib/python2.7/site-packages/django/template/debug.py", line 87, in render output = force_unicode(output) File "/home/david/Documents/projects/pompadour-wiki/pompadour_wiki/.venv/local/lib/python2.7/site-packages/django/utils/encoding.py", line 74, in force_unicode s = unicode(str(s), encoding, errors) UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 1: ordinal not in range(128)
Outside the test process, I couldn't manage to reproduce the bug.
Cordially,
David Delassus.
Change History (3)
comment:1 by , 12 years ago
comment:2 by , 12 years ago
comment:3 by , 12 years ago
Resolution: | → needsinfo |
---|---|
Status: | new → closed |
Closing as "needsinfo" - as Claude says without more specific info we can't verify if this is a bug in Django or in your code. My suspicion is that it's something related to your app's unicode handling, but if you've got more info that can help us reproduce this problem and prove it either way please feel free to reopen.
Unfortunately, there is not enough information in the report to really tell what is happening. You should place a breakpoint at line 76 of encoding.py, so as you can see what is exactly that
s
variable that produces the exception. We know at least that this is not a string at this point of the code.