title: How to test Django's UpdateView?
body: <p>As a simplified example, I've written an <code>UpdateView</code> for a <code>Book</code> model, as well as a <code>ListView</code> to redirect to upon success:</p>
  
  <pre><code>from django.urls import reverse
  from django.views.generic import ListView
  from django.views.generic.edit import UpdateView
  from .models import Book
  
  
  class BookUpdate(UpdateView):
      model = Book
      fields = ['title', 'author']
  
  
  class BookList(ListView):
      model = Book
  </code></pre>
  
  <p>The <code>Book</code> model is defined as</p>
  
  <pre><code>class Book(models.Model):
      title = models.CharField(max_length=100)
      author = models.CharField(max_length=100, blank=True)
  
      def get_absolute_url(self):
          return reverse('books-list')
  </code></pre>
  
  <p>where <code>urls.py</code> is</p>
  
  <pre><code>from django.urls import path
  from books.views import BookUpdate, BookList
  
  
  urlpatterns = [
      path('books/', BookList.as_view(), name='books-list'),
      path('book/&lt;int:pk&gt;/', BookUpdate.as_view(), name='book-update')
  ]
  </code></pre>
  
  <p>In <code>books/tests.py</code> I've tried to write the following test:</p>
  
  <pre><code>class BookUpdateTest(TestCase):
      def test_update_book(self):
          book = Book.objects.create(title='The Catcher in the Rye')
  
          response = self.client.post(
              reverse('book-update', kwargs={'pk': book.id}), 
              {'author': 'J.D. Salinger'})
  
          self.assertEqual(response.status_code, 200)
  
          book.refresh_from_db()
          self.assertEqual(book.author, 'J.D. Salinger')
  </code></pre>
  
  <p>However, this test fails because the <code>book</code>'s <code>author</code> appears not to be updated after the <code>POST</code> request, even after refreshing from the database:</p>
  
  <pre><code>FAIL: test_update_book (books.tests.BookUpdateTest)
  ----------------------------------------------------------------------
  Traceback (most recent call last):
    File "/Users/kurtpeek/Documents/Scratch/book_project/books/tests.py", line 46, in test_update_book
      self.assertEqual(book.author, 'J.D. Salinger')
  AssertionError: '' != 'J.D. Salinger'
  + J.D. Salinger
  </code></pre>
  
  <p>On the other hand, if I run the development server and fill out the fields manually, everything seems to work as expected. How can I write a unit test for the <code>UpdateView</code> which captures the user updating the fields, submitting the form, and making changes to the corresponding objects?</p>