title: TypeError: 'NoneType' object is not subscriptable in Django unittests for message
body: <p>Am trying to do a unit test for a view that returns a message when some input is duplicated in the database.it gives me the error <code>TypeError: 'NoneType' object is not subscriptable</code></p>
  
  <p>Here is the <strong>view</strong></p>
  
  <pre><code>@login_required
  def worker_create(request):
      worker_create_form = WorkerCreateForm(request.POST)
      if request.method == 'POST':
          if worker_create_form.is_valid():
              form = worker_create_form.save(commit=False)
              phone = form.phone
              check_phone = Worker.objects.filter(phone=phone)
              if check_phone.count() != 0:
                  messages.error(request, 'رقم الهاتف مستخدم من قبل')
              else:
                  form.save()
                  return redirect('worker_list')
      else:
          worker_create_form = WorkerCreateForm(request.POST)
      context = {
          'worker_create_form': worker_create_form,
      }
      return render(request, 'erp_system/worker/create.html', context)
  </code></pre>
  
  <p>and here are the <strong>tests</strong> I've created for it</p>
  
  <pre><code>class WorkerCreateTest(TestCase):
      def setUp(self):
          User.objects.create_user(username='test_user', email='test@gmail.com', password='test_password')
          branch = Branch.objects.create(name='test branch')
          Worker.objects.create(name="ay btngan ", phone='01207199086', branch=branch)
  
      def test_get_request_unauthenticated(self):
          response = self.client.get(reverse('worker_create'))
          url = reverse('worker_create')
          self.assertRedirects(response, '/login/?next=' + url)
  
      def test_get_request_authenticated(self):
          self.client.login(username='test_user', password='test_password')
          response = self.client.get(reverse('worker_create'))
          self.assertEqual(response.status_code, 200)
          self.assertTemplateUsed('erp_system/worker/create.html')
  
      def test_post_request_empty_data(self):
          self.client.login(username='test_user', password='test_password')
          response = self.client.post(reverse('worker_create'), {})
          self.assertFormError(response, 'worker_create_form', 'name', 'This field is required.')
          self.assertFormError(response, 'worker_create_form', 'phone', 'This field is required.')
          self.assertFormError(response, 'worker_create_form', 'branch', 'This field is required.')
  
      def test_post_request_invalid_data(self):
          self.client.login(username='test_user', password='test_password')
          branch = Branch.objects.create(name='test again ')
          name = 'just a name'
          for i in range(300):
              name += 'h'
          response = self.client.post(reverse('worker_create'),
                                      {'name': name, 'phone': '01207199086', 'branch': branch.id})
          self.assertEqual(response.status_code, 200)
  
      def test_post_request_duplicated_phone(self):
          self.client.login(username='test_user', password='test_password')
          branch = Branch.objects.create(name='test again ')
          response = self.client.post(reverse('worker_create'),
                                      {'name': 'test worker', 'phone': '01207199086', 'branch': branch.id})
          print(response)
          messages = list(response.context['messages'])
          self.assertEqual(len(messages), 1)
          self.assertEqual(str(messages[0]), 'رقم الهاتف مستخدم من قبل')
  
      def test_post_request_valid_data(self):
          self.client.login(username='test_user', password='test_password')
          branch = Branch.objects.create(name='test branch1234')
          name = 'new valid name'
          response = self.client.post(reverse('worker_create'),
                                      {'name': name, 'branch': branch.id, 'phone': '0151951115'})
          self.assertEqual(response.status_code, 302)
  </code></pre>
  
  <p><strong>Important</strong>
  I noticed when I added <code>print(response)</code> that it gives me <code>HttpResponseRedirect</code> not just <code>HttpResponse</code> what means there is no context given. Why it using redirect in here!?</p>