Django中更新视图测试期间的AssertionError

我在django 2.2中有一个应用程序,正在尝试用factory-boy测试更新。 我收到一个错误:

AssertionError: 302 != 200 : Couldn't retrieve content: Response code was 302 (expected 200)

我会很感激每一个提示

查看代码:

class SpotUpdateView(UpdateView):
    model = Spot
    fields = ['title', 'description']
    template_name = 'spot/spot_update.html'
    context_object_name = 'spot_detal'

    def get_success_url(self):
        return reverse('spot_detail_url', kwargs={'slug': self.object.slug, 'id': self.object.id})

网址:

path('post/update/<str:slug>/<int:id>/', login_required(SpotUpdateView.as_view()), name='spot_update_url'),

单元测试代码

def test_spot_update(self):
    self.client.login(username='user', password='123!')
    spot_object = SpotFactory.create()
    response = self.client.post(reverse('spot_update_url', kwargs={'id': spot_object.id, 'slug': spot_object.slug}), {'title': 'My new title', 'description': 'After update'})
    self.assertEqual(response.status_code, 302)
    spot_object.refresh_from_db()
    self.assertContains(response, 'After update')