title: Django Test Client client.post() sends GET request?
body: <p>I am new to Python and Django. I did a experiment on enforcing request method (e.g. for certain url you can only use GET). Here is my code.</p>
  
  <p>tests.py</p>
  
  <pre><code>from django.test import TestCase, Client
  client = Client()
  
  class MyTests(TestCase):
      def test_request_method:
          """ Sending wrong request methods should result in 405 error """
          self.assertEqual(client.post('/mytest', follow = True).status_code, 405)
  </code></pre>
  
  <p>urls.py</p>
  
  <pre><code>from django.conf.urls import url
  from . import views
  
  urlpatterns = [
      url(r'^$', views.index, name = 'index'),
      url(r'^mytest/', views.mytest, name = 'mytest'),
  ]
  </code></pre>
  
  <p>views.py</p>
  
  <pre><code>from django.http import HttpResponse
  
  def mytest(request):
      if request.method == 'GET':
          return HttpResponse("Not implemented", status = 500)
      else:
          return HttpResponse("Only GET method allowed", status = 405)
  </code></pre>
  
  <p>But the test always returns status 500.</p>
  
  <p>I saw <a href="https://stackoverflow.com/questions/28309178/django-test-client-doesnt-call-post-but-get">here</a> that this may be related to using <code>follow=True</code> in the <code>client.post()</code> call. However if I use <code>follow=False</code> I will get status 301 instead.</p>
  
  <p>Any ideas? Thank you!</p>