Напишите тест для проверки того, было ли сообщение удалено из старой группы

Мне нужно проверить, что пост исчез со страницы старой группы. Мне нужно получить мою старую группу для ее slack.

old_group_response = self.authorized_client.get( reverse('group_list', args=(self.group.slug,)) ) И сравните это

old_group_response.context['page_obj'].paginator.count равен нулю. Это означает, что в нашей старой группе нет постов. И проверяем другую новую группу, что там есть 1 пост. Как мне правильно это написать? Я знаю, что здесь написана ерунда (я только учусь), вот что я смог набросать.

from django import forms from django.test import Client, TestCase from django.urls import reverse

from ..models import Group, Post, User

NEW_POST = reverse('posts:post_create')

class PostFormTests(TestCase): @classmethod def setUpClass(cls): super().setUpClass() cls.author_auth = User.objects.create_user(username='test auth') cls.not_author = User.objects.create_user(username='Not Author') cls.group = Group.objects.create( title='Test group_title', slug='test_slug', description='Описание теста')

def setUp(self):
    self.authorized_client = Client()
    self.authorized_client.force_login(PostFormTests.author_auth)
    self.authorized_client_not_author = Client()
    self.authorized_client_not_author.force_login(
        PostFormTests.not_author)

def test_post_old_group_response(self):
    """ Check if a post has been removed from the old group."""
    post = Post.objects.create(
        group=PostFormTests.group,
        author=PostFormTests.author_auth,
        text='test post')
    group_2 = Group.objects.create(
        title='Test group_title2',
        slug='test_slug2',
        description='Test description2')
    posts_count = Post.objects.count()
    form_data = {
        'text': 'text_post',
        'group': group_2.id}
    old_group_response = self.authorized_client.get(
        reverse('posts:group_list', args=(self.group.slug)),
        data=form_data,
        follow=True)
    self.assertEqual(
        old_group_response, reverse(
            'posts:post_detail', kwargs={'post_id': post.pk}))
    self.assertEqual(Post.objects.count(), posts_count)
    self.assertEqual(old_group_response.context[
        'page_obj'].paginator.count == 0)
Вернуться на верх