예제 #1
0
    def test_top_tags(self):
        """Unit testing top_categories method """

        user = ProfileFactory().user

        # Create 7 topics and give them tags on both public and staff topics
        # in random order to make sure it works
        # tags are named tag-X-Y, where X is the # times it's assigned to a public topic
        # and Y is the total (public + staff) it's been assigned

        topic = TopicFactory(forum=self.forum11, author=user)
        topic.add_tags({'tag-3-5'})

        topic = TopicFactory(forum=self.forum11, author=user)
        topic.add_tags({'tag-3-5'})
        topic.add_tags({'tag-4-4'})

        topic = TopicFactory(forum=self.forum12, author=self.staff1.user)
        topic.add_tags({'tag-0-1'})
        topic.add_tags({'tag-0-2'})
        topic.add_tags({'tag-3-5'})

        topic = TopicFactory(forum=self.forum12, author=self.staff1.user)
        topic.add_tags({'tag-0-2'})
        topic.add_tags({'tag-3-5'})

        topic = TopicFactory(forum=self.forum11, author=user)
        topic.add_tags({'tag-4-4'})
        topic.add_tags({'tag-3-5'})

        topic = TopicFactory(forum=self.forum11, author=user)
        topic.add_tags({'tag-4-4'})

        topic = TopicFactory(forum=self.forum11, author=user)
        topic.add_tags({'tag-4-4'})

        # Now call the function, should be "tag-4-4", "tag-3-5"
        top_tags = top_categories(user).get('tags')

        # tag-X-Y : X should be decreasing
        self.assertEqual(top_tags[0].title, 'tag-4-4')
        self.assertEqual(top_tags[1].title, 'tag-3-5')
        self.assertEqual(len(top_tags), 2)

        # Admin should see theirs specifics tags
        top_tags = top_categories(self.staff1.user).get('tags')
        # tag-X-Y : Y should be decreasing
        self.assertEqual(top_tags[0].title, 'tag-3-5')
        self.assertEqual(top_tags[1].title, 'tag-4-4')
        self.assertEqual(top_tags[2].title, 'tag-0-2')
        self.assertEqual(top_tags[3].title, 'tag-0-1')
        self.assertEqual(len(top_tags), 4)

        # Now we want to exclude a tag
        settings.ZDS_APP['forum']['top_tag_exclu'] = {'tag-4-4'}

        # User only sees the only 'public' tag left
        top_tags = top_categories(user).get('tags')
        self.assertEqual(top_tags[0].title, 'tag-3-5')
        self.assertEqual(len(top_tags), 1)
예제 #2
0
파일: views.py 프로젝트: Aer-o/zds-site
def index(request):
    """Display the category list with all their forums."""

    categories = top_categories(request.user)

    return render_template("forum/index.html", {"categories": categories,
                                                "user": request.user})
예제 #3
0
파일: views.py 프로젝트: maynalysa/zds-site
def index(request):
    """Display the category list with all their forums."""

    categories = top_categories(request.user)

    return render_template("forum/index.html", {"categories": categories,
                                                "user": request.user})
예제 #4
0
    def test_top_tags(self):
        """Unit testing top_categories method """

        user = ProfileFactory().user

        # Create some topics
        topic = TopicFactory(forum=self.forum11, author=user)
        topic.add_tags({'C#'})

        topic1 = TopicFactory(forum=self.forum11, author=user)
        topic1.add_tags({'C#'})

        topic2 = TopicFactory(forum=self.forum11, author=user)
        topic2.add_tags({'C#'})

        topic3 = TopicFactory(forum=self.forum11, author=user)
        topic3.add_tags({'PHP'})

        topic4 = TopicFactory(forum=self.forum11, author=user)
        topic4.add_tags({'PHP'})

        topic5 = TopicFactory(forum=self.forum12, author=user)
        topic5.add_tags({'stafftag'})

        # Now call the function, should be "C#", "PHP"
        top_tags = top_categories(user).get('tags')

        # Assert
        self.assertEqual(top_tags[0].title, 'c#')
        self.assertEqual(top_tags[1].title, 'php')
        self.assertEqual(len(top_tags), 2)

        # Admin should see theirs specifics tags
        top_tags_for_staff = top_categories(self.staff1.user).get('tags')
        self.assertEqual(top_tags_for_staff[2].title, 'stafftag')

        # Now we want to exclude a tag
        settings.ZDS_APP['forum']['top_tag_exclu'] = {'php'}
        top_tags = top_categories(user).get('tags')

        # Assert that we should only have one tags
        self.assertEqual(top_tags[0].title, 'c#')
        self.assertEqual(len(top_tags), 1)