Django test client gets 301 redirection when accessing url

Posted by Michal Klich on Stack Overflow See other posts from Stack Overflow or by Michal Klich
Published on 2012-10-08T15:35:59Z Indexed on 2012/10/08 15:37 UTC
Read the original article Hit count: 219

Filed under:
|
|
|

I am writing unittests for django views. I have observed that one of my views returns redirection code 301, which is not expected.
Here is my views.py mentioned earlier.

def index(request):
    return render(request, 'index.html',
                  {'form': QueryForm()})

def query(request):
    if request.is_ajax():
        form = QueryForm(request.POST)
        return HttpResponse('valid')

Below is urls.py.

urlpatterns = patterns('',
         url(r'^$', 'core.views.index'),
         url(r'^query/$', 'core.views.query')
         )

And unittest that will fail.

def so_test(self):
    response = self.client.post('/')
    self.assertEquals(response.status_code, 200)

    response = self.client.post('/query', {})
    self.assertEquals(response.status_code, 200)

My question is: why there is status 301 returned?

© Stack Overflow or respective owner

Related posts about AJAX

Related posts about django