Эй, ребята, я пытаюсь запустить некоторые тесты со следующим кодом
view
@login_required
def compose(request):
"""Form to compose a new message"""
template_name = 'messaging/compose.html'
form_class = MessageForm
if request.method == 'POST':
form = form_class(request.POST)
if form.is_valid():
form.save(sender=request.user)
messages.info(request, 'Message sent successfully', extra_tags='sent')
success_url = reverse_lazy('messaging:messages_outbox')
return redirect(success_url)
else:
form = form_class()
return render(request, template_name, {'form': form})
TestCase
class TestMessageViews(TestCase):
def setUp(self):
super().setUp()
self.user1 = get_user_model().objects.create(username='user1')
self.user2 = get_user_model().objects.create(username='user2')
self.form = create(Message, {'sender': self.user1,
'recipient': self.user2,
'subject': 'test_subject',
'body': 'test_body'})
self.client = Client()
def test_compose_message(self):
"""Test to make sure our compose is redirecting us"""
self.client.force_login(user=self.user1)
response = self.client.post(reverse('messaging:messages_compose'), {
'recipient': self.user2,
'subject': self.form.subject,
'body': self.form.body
})
self.assertEqual(response.status_code, 302)
Я получаю код состояния 200, когда это должно перенаправить нас в исходящие, который должен быть 302?