How to use spirit - 10 common examples

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_no_slug(self):
        """
        no slug
        """
        utils.login(self)
        category = utils.create_category()
        topic = utils.create_topic(category=category)
        response = self.client.get(reverse('spirit:topic:detail', kwargs={'pk': topic.pk,
                                                                          'slug': ''}))
        self.assertRedirects(response, topic.get_absolute_url(), status_code=301)
github nitely / Spirit / spirit / comment / tests.py View on Github external
def test_comment_move(self):
        """
        comment move to another topic
        """
        utils.login(self)
        self.user.st.is_moderator = True
        self.user.save()
        Topic.objects.filter(pk=self.topic.pk).update(comment_count=2)
        comment = utils.create_comment(user=self.user, topic=self.topic)
        comment2 = utils.create_comment(user=self.user, topic=self.topic)
        to_topic = utils.create_topic(category=self.category)
        form_data = {'topic': to_topic.pk,
                     'comments': [comment.pk, comment2.pk], }
        response = self.client.post(reverse('spirit:comment:move', kwargs={'topic_id': self.topic.pk, }),
                                    form_data)
        expected_url = self.topic.get_absolute_url()
        self.assertRedirects(response, expected_url, status_code=302)
        self.assertEqual(Comment.objects.filter(topic=to_topic.pk).count(), 2)
        self.assertEqual(Comment.objects.filter(topic=self.topic.pk).count(), 0)
        self.assertEqual(Topic.objects.get(pk=self.topic.pk).comment_count, 0)
github nitely / Spirit / spirit / search / tests.py View on Github external
def test_advanced_search_topics(self):
        """
        advanced search by topic
        """
        utils.login(self)
        data = {'q': 'spirit search'}
        response = self.client.get(
            reverse('spirit:search:search'), data)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            list(response.context['page']),
            [{
                'fields': {
                    'title': self.topic.title,
                    'slug': self.topic.slug,
                    'comment_count': self.topic.comment_count,
                    'last_active': self.topic.last_active,
                    'main_category_name': self.topic.main_category.title},
                'pk': str(self.topic.pk)}])
github nitely / Spirit / spirit / topic / private / tests.py View on Github external
def test_private_created_list_paginate(self):
        """
        private topic created list paginated
        """
        private = utils.create_private_topic(user=self.user)
        private.delete()
        private2 = utils.create_private_topic(user=self.user)
        private2.delete()

        utils.login(self)
        response = self.client.get(reverse('spirit:topic:private:index-author'))
        self.assertEqual(list(response.context['topics']), [private2.topic, ])
github nitely / Spirit / spirit / comment / poll / tests.py View on Github external
def test_poll_vote_post(self):
        """
        POST, poll_vote
        """
        utils.login(self)
        choice = CommentPollChoice.objects.create(poll=self.poll, number=1, description="op1")
        form_data = {'choices': choice.pk, }
        response = self.client.post(reverse('spirit:comment:poll:vote', kwargs={'pk': self.poll.pk, }),
                                    form_data)
        expected_url = self.poll.get_absolute_url()
        self.assertRedirects(response, expected_url, status_code=302, target_status_code=302)
        self.assertEqual(len(CommentPollVote.objects.filter(choice=choice)), 1)
github nitely / Spirit / spirit / topic / private / tests.py View on Github external
def test_topic_private_detail_viewed(self):
        """
        Calls utils.topic_viewed
        """
        def mocked_topic_viewed(request, topic):
            self._user = request.user
            self._topic = topic

        org_viewed, utils_topic.topic_viewed = utils_topic.topic_viewed, mocked_topic_viewed
        try:
            utils.login(self)
            category = utils.create_category()
            topic = utils.create_topic(category=category, user=self.user)
            response = self.client.get(reverse('spirit:topic:detail', kwargs={'pk': topic.pk, 'slug': topic.slug}))
            self.assertEqual(response.status_code, 200)
            self.assertEqual(self._topic, topic)
            self.assertEqual(self._user, self.user)
        finally:
            utils_topic.topic_viewed = org_viewed
github nitely / Spirit / spirit / topic / private / tests.py View on Github external
def test_private_list_bookmarks(self):
        """
        private topic list with bookmarks
        """
        private = utils.create_private_topic(user=self.user)
        bookmark = CommentBookmark.objects.create(topic=private.topic, user=self.user)

        utils.login(self)
        response = self.client.get(reverse('spirit:topic:private:index'))
        self.assertEqual(list(response.context['topics']), [private.topic, ])
        self.assertEqual(response.context['topics'][0].bookmark, bookmark)
github nitely / Spirit / spirit / comment / tests.py View on Github external
def test_comment_publish_on_closed_category(self):
        """
        should be able to create a comment on a closed category (if topic is not closed)
        """
        Category.objects.filter(pk=self.category.pk).update(is_closed=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, 302)
        self.assertEqual(len(Comment.objects.all()), 1)
github nitely / Spirit / spirit / comment / history / tests.py View on Github external
def test_comment_history_detail_no_access(self):
        """
        return Http404 if user has no access to the comment's topic
        """
        private = utils.create_private_topic(user=self.user)
        private.delete()

        comment = utils.create_comment(user=self.user, topic=private.topic)
        CommentHistory.objects.create(comment_fk=comment, comment_html=comment.comment_html)

        utils.login(self)
        response = self.client.get(reverse('spirit:comment:history:detail', kwargs={'comment_id': comment.pk, }))
        self.assertEqual(response.status_code, 404)
github nitely / Spirit / spirit / comment / tests.py View on Github external
def test_comment_update(self):
        """
        update comment
        """
        comment = utils.create_comment(user=self.user, topic=self.topic)

        utils.login(self)
        form_data = {'comment': 'barfoo', }
        response = self.client.post(reverse('spirit:comment:update', kwargs={'pk': comment.pk, }),
                                    form_data)
        expected_url = reverse('spirit:comment:find', kwargs={'pk': 1, })
        self.assertRedirects(response, expected_url, status_code=302, target_status_code=302)
        self.assertEqual(Comment.objects.get(pk=comment.pk).comment, 'barfoo')

        # next
        form_data.update({'next': '/fakepath/', })
        response = self.client.post(reverse('spirit:comment:update', kwargs={'pk': comment.pk, }),
                                    form_data)
        self.assertRedirects(response, '/fakepath/', status_code=302, target_status_code=404)