diff --git a/yatube/posts/tests/test_forms.py b/yatube/posts/tests/test_forms.py index 8f3e422..d2a6fa2 100644 --- a/yatube/posts/tests/test_forms.py +++ b/yatube/posts/tests/test_forms.py @@ -136,46 +136,45 @@ def test_edit_post(self): self.assertRedirects(response, reverse( "posts:post_detail", kwargs={"post_id": post.pk})) + def test_create_post(self): + """При отправке валидной формы со страницы создания поста + reverse('posts:create_post') + создаётся новая запись в базе данных. + """ + small_gif = ( + b'\x47\x49\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' + ) + uploaded = SimpleUploadedFile( + name='small.gif', + content=small_gif, + content_type='image/gif' + ) + form_data = { + "text": "Текст из формы", + "group": self.group.id, + "image": uploaded, + } + response = self.authorized_author.post( + reverse("posts:post_create"), + data=form_data, + follow=True + ) + self.assertEqual(Post.objects.count(), 2) + post = Post.objects.first() + post_attributes = { + post.author: self.auth, + post.text: form_data["text"], + post.group: self.group, + post.image: f"posts/{form_data['image'].name}" + } + for attribute, value in post_attributes.items(): + with self.subTest(attribute=attribute): + self.assertEqual(attribute, value) -def test_create_post(self): - """При отправке валидной формы со страницы создания поста - reverse('posts:create_post') - создаётся новая запись в базе данных. - """ - small_gif = ( - b'\x47\x49\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' - ) - uploaded = SimpleUploadedFile( - name='small.gif', - content=small_gif, - content_type='image/gif' - ) - form_data = { - "text": "Текст из формы", - "group": self.group.id, - "image": uploaded, - } - response = self.authorized_author.post( - reverse("posts:post_create"), - data=form_data, - follow=True - ) - self.assertEqual(Post.objects.count(), 2) - post = Post.objects.first() - post_attributes = { - post.author: self.auth, - post.text: form_data["text"], - post.group: self.group, - post.image: f"posts/{form_data['image'].name}" - } - for attribute, value in post_attributes.items(): - with self.subTest(attribute=attribute): - self.assertEqual(attribute, value) - - self.assertRedirects(response, reverse( - "posts:profile", kwargs={"username": self.auth})) + self.assertRedirects(response, reverse( + "posts:profile", kwargs={"username": self.auth}))