test_forms.py:
def setUpClass(self):
super().setUpClass()
self.small2_gif = (
b'\x43\x41\x46\x38\x39\x61\x02\x00'
b'\x01\x00\x80\x00\x00\x00\x00\x00'
b'\xFF\xFF\xFF\x21\xF9\x04\x00\x00'
b'\x00\x00\x00\x2C\x00\x00\x00\x00'
b'\x02\x00\x01\x00\x00\x02\x02\x0C'
b'\x0A\x00\x3B'
)
self.uploaded2 = SimpleUploadedFile(
name='small.gif',
content=self.small2_gif,
content_type='image/gif'
)
self.user = User.objects.create_user(username=USERNAME)
self.group = Group.objects.create(
title='Тестовая группа',
slug='test-slug',
description='Тестовое описание',
)
self.group2 = Group.objects.create(
title='Тестовая группа',
slug='test-slug2'
)
self.post = Post.objects.create(
author=self.user,
text='Тестовый пост',
group=self.group
)
def test_edit_post_form(self):
"""Валидная форма редактирует запись в Post."""
posts_count = Post.objects.count()
form_data = {
'text': 'Пост изменен2',
'group': self.group2.id,
'image': self.uploaded2
}
response = self.author.post(
self.POST_EDIT_URL,
data=form_data,
follow=True
)
post = Post.objects.get(id=self.post.id)
print(Post.objects.all())
self.assertRedirects(response, self.POST_DETAIL_URL)
self.assertEqual(Post.objects.count(), posts_count)
self.assertEqual(post.text, form_data['text'])
self.assertEqual(post.text, 'posts/small2.gif')
self.assertEqual(post.group.id, form_data['group'])
self.assertEqual(post.author, self.post.author)
Ошибка:
AssertionError: [] is not true : Response didn't redirect as expected: Response code was 200 (expected 302)