Django

Code

Ticket #5982 (closed: fixed)

Opened 10 months ago

Last modified 6 months ago

Different behaviour for url parameter in dev run versus test run

Reported by: Manoj Govindan <egmanoj@gmail.com> Assigned to: Leo
Milestone: Component: Unit test system
Version: SVN Keywords:
Cc: egmanoj@gmail.com Triage Stage: Ready for checkin
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

URL configuration:

   url(r'^/find_thing/(?P<thing_name>.+)/$', 'django_mi.app.views.find_thing', name = 'find_thing'),

View:

def find_thing(request, thing_name):
	print thing_name
	# perform look up of thing and return.

In the development environment (manage.py runserver) the view works well when passed a string with a space in it, say 'my thing'. The portion of the url representing the parameter shows up as 'my%20thing'.

I then wrote a test for the view using Django's test client. I used the utility reverse() method to pass the path to Client.get(). The test failed (the query set was empty) for identical input.

I added a print statement inside the view. On accessing the view in the development environment the parameter was printed as 'my thing'. However on running the test it was printed as 'my%20thing'. The latter caused the database lookup to return empty.

Why is the behaviour different in development/production and testing?

Attachments

5982-r7023.diff (2.8 kB) - added by russellm on 01/18/08 08:24:00.
Test case for bug, against r7023
5982-r7264.diff (5.3 kB) - added by Leo on 03/17/08 11:20:03.
modified test case and patch

Change History

11/24/07 06:30:37 changed by Manoj Govindan <egmanoj@gmail.com>

  • cc set to egmanoj@gmail.com.
  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

12/16/07 02:08:44 changed by SmileyChris

  • stage changed from Unreviewed to Design decision needed.

So it's probably a bug, I'm guessing the test client should be unquoting. Care to attach your test?

01/18/08 08:24:00 changed by russellm

  • attachment 5982-r7023.diff added.

Test case for bug, against r7023

01/18/08 08:25:32 changed by russellm

  • stage changed from Design decision needed to Accepted.

Bug appears to be real. I've added a test case; haven't had a chance to dig around for a fix.

03/17/08 10:14:42 changed by Leo

  • owner changed from nobody to Leo.
  • status changed from new to assigned.

03/17/08 11:20:03 changed by Leo

  • attachment 5982-r7264.diff added.

modified test case and patch

03/17/08 11:31:59 changed by Leo

  • has_patch set to 1.
  • stage changed from Accepted to Ready for checkin.

Fixing this bug by adding urllib.unquote to the spot where PATH_INFO gets set in the test client. Based on what I saw at django.core.servers.basehttp:565. That occurs for requests that come in via a normal client (on a dev server).

I've made a few minor changes to the test itself:

  • mixed space/tab indentation changed to all spaces
  • added cases to do a POST as well as a GET (since there are two separate code paths in the test client that set PATH_INFO)

Zero functional change cleanup changes in this patch:

  • removed unused imports from tests/regressiontests/test_client_regress/views.py
  • added myself to the AUTHORS file

03/17/08 11:33:40 changed by Leo

  • stage changed from Ready for checkin to Accepted.

moving back to accepted (wasn't sure if I should have moved it)

03/17/08 11:41:21 changed by jacob

  • stage changed from Accepted to Ready for checkin.

03/20/08 01:50:55 changed by mtredinnick

  • status changed from assigned to closed.
  • resolution set to fixed.

(In [7330]) Fixed #5982 -- Changed test client's URL processing to match core's (everything gets run through urllib.unquote()). Patch from Leo Shklovskii and Russell Keith-Magee.


Add/Change #5982 (Different behaviour for url parameter in dev run versus test run)




Change Properties
Action