From 72d6578688fe7219da13d5c33630cc899a9022f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=BA=D0=B0=D1=82=D0=B5=D1=80=D0=B8=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=A1=D0=B0=D0=B2=D1=87=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Fri, 13 Jan 2023 09:08:14 +0200 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=B8=D0=BD=D0=B0=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D0=BE=D0=B5=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yatube/posts/tests/test_forms.py | 83 ++++++++++++++++---------------- 1 file changed, 41 insertions(+), 42 deletions(-) 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}))