def test_update_book(self): """ Test updating book """ book = BookFactory() url = reverse('books:books-detail', kwargs={'pk': book.pk}) response = self.client.patch(url, {'title': 'new_title'}) book.refresh_from_db() self.assertEqual(book.title, 'new_title') self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_update_is_not_allowed(self): """ Make sure that put action is not allowed. """ book = BookFactory() new_title = 'new title' url = '{0}{1}'.format(BASE_URL, book.id) request = self.factory.put(url, {'title': new_title}, format='json') response = self.view(request, pk=book.id) # Assert that method is not allowed, no data has been returned and the object was not changed. self.assertEquals(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED) self.assertEquals(response.data, {'detail': 'Method "PUT" not allowed.'}) book.refresh_from_db() self.assertNotEquals(book.title, new_title)