Exemplo n.º 1
0
    def test_forum_edit_view(self):
        user = User.objects.create_user(
            username='******',
            email='*****@*****.**',
            password='******',
        )
        category = Category.objects.create(category_title='Testing')
        forum = Forum.objects.create(
            forum_author=user.profile,
            forum_title='Test new thread.',
            forum_category=category,
            forum_content='Lorep insum dolor amet.',
        )

        payload = {
            'forum_title': 'I change my mind to change the title',
            'forum_content': 'Lorep insum dolor amet.',
            'forum_category': category.pk,
        }
        url = reverse('forum:forum_edit', args=[forum.pk])
        request = self.factory.post(path=url, data=payload)
        request.user = user
        response = forum_edit_view(request, forum.pk)
        response.client = Client()
        self.assertRedirects(response,
                             reverse('forum:forum_single', args=[forum.pk]))
Exemplo n.º 2
0
 def test_forum_edit_view_with_different_author(self):
     user = User.objects.create_user(
         username='******',
         email='*****@*****.**',
         password='******',
     )
     another_user = User.objects.create_user(
         username='******',
         email='*****@*****.**',
         password='******',
     )
     category = Category.objects.create(category_title='Testing')
     forum = Forum.objects.create(
         forum_author=user.profile,
         forum_title='Test new thread.',
         forum_category=category,
         forum_content='Lorep insum dolor amet.',
     )
     with self.assertRaises(PermissionDenied):
         url = reverse('forum:forum_edit', args=[forum.pk])
         request = self.factory.get(path=url)
         request.user = another_user
         forum_edit_view(request, forum.pk)
Exemplo n.º 3
0
    def test_retrieve_forum_edit_form_view(self):
        user = User.objects.create_user(
            username='******',
            email='*****@*****.**',
            password='******',
        )
        category = Category.objects.create(category_title='Testing')
        forum = Forum.objects.create(
            forum_author=user.profile,
            forum_title='Test new thread.',
            forum_category=category,
            forum_content='Lorep insum dolor amet.',
        )

        url = reverse('forum:forum_edit', args=[forum.pk])
        request = self.factory.get(path=url)
        request.user = user
        response = forum_edit_view(request, forum.pk)
        self.assertEqual(response.status_code, 200)