How to use the spirit.core.tests.utils.create_category function in spirit

To help you get started, we’ve selected a few spirit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nitely / Spirit / spirit / topic / tests.py View on Github external
def test_topic_detail_view_paginate(self):
        """
        should display topic with comments, page 1
        """
        utils.login(self)
        category = utils.create_category()

        topic = utils.create_topic(category=category)

        comment1 = utils.create_comment(topic=topic)
        comment2 = utils.create_comment(topic=topic)
        utils.create_comment(topic=topic)  # comment3

        response = self.client.get(reverse('spirit:topic:detail', kwargs={'pk': topic.pk, 'slug': topic.slug}))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(list(response.context['comments']), [comment1, comment2])
github nitely / Spirit / spirit / topic / favorite / tests.py View on Github external
def setUp(self):
        utils.cache_clear()
        self.user = utils.create_user()
        self.category = utils.create_category()
        self.topic = utils.create_topic(category=self.category, user=self.user)
github nitely / Spirit / spirit / topic / tests.py View on Github external
def test_topic_publish_count(self):
        """
        Creating or deleting a topic updates the profile topic_count and comment_count
        """
        utils.login(self)
        category = utils.create_category()
        form_data = {'comment': 'foo', 'title': 'foobar', 'category': category.pk}
        response = self.client.post(reverse('spirit:topic:publish'),
                                    form_data)
        self.assertEqual(UserProfile.objects.get(pk=self.user.st.pk).topic_count, 1)
        self.assertEqual(UserProfile.objects.get(pk=self.user.st.pk).comment_count, 1)
        Topic.objects.get(user=self.user).delete()
        self.assertEqual(UserProfile.objects.get(pk=self.user.st.pk).topic_count, 0)
        self.assertEqual(UserProfile.objects.get(pk=self.user.st.pk).comment_count, 0)
github nitely / Spirit / spirit / comment / tests.py View on Github external
def setUp(self):
        cache.clear()
        self.user = utils.create_user()
        self.category = utils.create_category()
        self.topic = utils.create_topic(category=self.category)
github nitely / Spirit / spirit / topic / tests.py View on Github external
def test_topic_viewed(self):
        """
        * Should update/create the comment bookmark
        * Should mark the topic notification as read
        * Should create or mark the topic (unread) as read
        * Should increase the view_counter
        """
        req = RequestFactory().get('/?page=1')
        req.user = self.user

        category = utils.create_category()
        topic = utils.create_topic(category=category, user=self.user)
        comment = utils.create_comment(topic=topic)
        notification = TopicNotification.objects.create(user=topic.user, topic=topic, comment=comment, is_read=False)
        unread = TopicUnread.objects.create(user=topic.user, topic=topic, is_read=False)
        utils_topic.topic_viewed(req, topic)
        self.assertEqual(len(CommentBookmark.objects.filter(user=self.user, topic=topic)), 1)
        self.assertTrue(TopicNotification.objects.get(pk=notification.pk).is_read)
        self.assertTrue(TopicUnread.objects.get(pk=unread.pk).is_read)
        self.assertEqual(Topic.objects.get(pk=topic.pk).view_count, 1)
github nitely / Spirit / spirit / search / tests.py View on Github external
def test_indexing_text_template(self):
        """
        Should include topic title and all comments
        """
        category = utils.create_category()
        topic = utils.create_topic(category, title='my title')
        utils.create_comment(topic=topic, comment_html='<span>foo</span>')
        utils.create_comment(topic=topic, comment_html='<b>bar</b>')
        self.assertEqual(
            render_to_string(
                'search/indexes/spirit_topic/topic_text.txt',
                context={'object': topic}),
            'my title\n\nbar\n\nfoo\n\n')
github nitely / Spirit / spirit / topic / unread / tests.py View on Github external
def test_topic_unread_list_dont_show_removed_or_no_access(self):
        """
        dont show private topics if user has no access or is removed
        """
        TopicUnread.objects.all().delete()

        category = utils.create_category()
        category_removed = utils.create_category(is_removed=True)
        subcategory = utils.create_category(parent=category_removed)
        subcategory_removed = utils.create_category(parent=category, is_removed=True)
        topic_a = utils.create_private_topic()
        topic_b = utils.create_topic(category=category, is_removed=True)
        topic_c = utils.create_topic(category=category_removed)
        topic_d = utils.create_topic(category=subcategory)
        topic_e = utils.create_topic(category=subcategory_removed)
        TopicUnread.objects.create(user=self.user, topic=topic_a.topic, is_read=False)
        TopicUnread.objects.create(user=self.user, topic=topic_b, is_read=False)
        TopicUnread.objects.create(user=self.user, topic=topic_c, is_read=False)
        TopicUnread.objects.create(user=self.user, topic=topic_d, is_read=False)
        TopicUnread.objects.create(user=self.user, topic=topic_e, is_read=False)

        utils.login(self)
        response = self.client.get(reverse('spirit:topic:unread:index'))
        self.assertEqual(list(response.context['page']), [])
github nitely / Spirit / spirit / category / admin / tests.py View on Github external
# parent can not be set to a category with childrens
        category_ = utils.create_category()
        form_data = {"parent": category_.pk, }
        form = CategoryForm(data=form_data, instance=self.category)
        self.assertEqual(form.is_valid(), False)
        self.assertNotIn('parent', form.cleaned_data)

        # parent can not be removed
        category_ = utils.create_category(is_removed=True)
        form_data = {"parent": category_.pk, }
        form = CategoryForm(data=form_data)
        self.assertEqual(form.is_valid(), False)
        self.assertNotIn('parent', form.cleaned_data)

        # parent can not be private
        category_ = utils.create_category(is_private=True)
        form_data = {"parent": category_.pk, }
        form = CategoryForm(data=form_data)
        self.assertEqual(form.is_valid(), False)
        self.assertNotIn('parent', form.cleaned_data)
github nitely / Spirit / spirit / comment / tests.py View on Github external
def test_comment_publish_on_removed_topic_or_category(self):
        """
        should not be able to create a comment
        """
        # removed category
        Category.objects.all().update(is_removed=True)

        utils.login(self)
        form_data = {'comment': 'foobar', }
        response = self.client.post(reverse('spirit:comment:publish', kwargs={'topic_id': self.topic.pk, }),
                                    form_data)
        self.assertEqual(response.status_code, 404)

        # removed subcategory
        Category.objects.all().update(is_removed=False)
        subcategory = utils.create_category(parent=self.category, is_removed=True)
        topic2 = utils.create_topic(subcategory)

        utils.login(self)
        form_data = {'comment': 'foobar', }
        response = self.client.post(reverse('spirit:comment:publish', kwargs={'topic_id': topic2.pk, }),
                                    form_data)
        self.assertEqual(response.status_code, 404)

        # removed topic
        Category.objects.all().update(is_removed=False)
        Topic.objects.all().update(is_removed=True)

        utils.login(self)
        form_data = {'comment': 'foobar', }
        response = self.client.post(reverse('spirit:comment:publish', kwargs={'topic_id': self.topic.pk, }),
                                    form_data)
github nitely / Spirit / spirit / topic / tests.py View on Github external
def test_topic_updates_reindex_at(self):
        """
        Should update reindex_at field
        """
        yesterday = timezone.now() - datetime.timedelta(days=1)
        category = utils.create_category()
        topic = utils.create_topic(category, reindex_at=yesterday)
        self.assertEqual(
            topic.reindex_at,
            yesterday)

        form_data = {'title': 'foobar'}
        form = TopicForm(self.user, data=form_data, instance=topic)
        self.assertEqual(form.is_valid(), True)
        form.save()
        self.assertGreater(
            Topic.objects.get(pk=topic.pk).reindex_at,
            yesterday)