Пример #1
0
    def test_remove_subscribed_tag(self):
        """
            When the topic is edited and a tag is added to which the user has subscribed
        """
        NewTopicSubscription.objects.toggle_follow(self.tag1, self.user2)

        topic = TopicFactory(forum=self.forum11, author=self.user1)
        topic.add_tags(['Linux'])
        PostFactory(topic=topic, author=self.user1, position=1)

        notifications = Notification.objects.filter(object_id=topic.pk,
                                                    is_read=False).all()
        self.assertEqual(1, len(notifications))

        self.client.post(reverse('topic-edit') + '?topic={0}'.format(
            topic.pk
        ), {
            'title': 'Un autre sujet',
            'subtitle': 'Encore ces lombards en plein été',
            'text':
            'C\'est tout simplement l\'histoire de la ville de Paris que je voudrais vous conter ',
            'tags': 'Windows'
        },
                         follow=False)

        self.assertEqual(
            1,
            len(
                Notification.objects.filter(object_id=topic.pk,
                                            is_read=False,
                                            is_dead=True).all()))
Пример #2
0
    def test_remove_subscribed_tag(self):
        """
        When the topic is edited and a tag is added to which the user has subscribed
        """
        NewTopicSubscription.objects.toggle_follow(self.tag1, self.user2)

        topic = TopicFactory(forum=self.forum11, author=self.user1)
        topic.add_tags(["Linux"])
        PostFactory(topic=topic, author=self.user1, position=1)

        notifications = Notification.objects.filter(object_id=topic.pk,
                                                    is_read=False).all()
        self.assertEqual(1, len(notifications))

        self.client.post(
            reverse("topic-edit") + f"?topic={topic.pk}",
            {
                "title": "Un autre sujet",
                "subtitle": "Encore ces lombards en plein été",
                "text":
                "C'est tout simplement l'histoire de la ville de Paris que je voudrais vous conter ",
                "tags": "Windows",
            },
            follow=False,
        )

        self.assertEqual(
            1,
            len(
                Notification.objects.filter(object_id=topic.pk,
                                            is_read=False,
                                            is_dead=True).all()))
Пример #3
0
    def test_mark_read_a_topic_of_a_tag_subscribed(self):
        """
        When a user has a notification on a topic, the notification should be marked as read.
        """
        NewTopicSubscription.objects.toggle_follow(self.tag1, self.user1)

        topic = TopicFactory(forum=self.forum11, author=self.user2)
        topic.add_tags(['Linux'])

        PostFactory(topic=topic, author=self.user2, position=1)
        notifications = Notification.objects.filter(object_id=topic.pk, is_read=False).all()
        self.assertEqual(1, len(notifications))

        response = self.client.get(reverse('topic-posts-list', args=[topic.pk, topic.slug()]))
        self.assertEqual(response.status_code, 200)

        notifications = Notification.objects.filter(object_id=topic.pk, is_read=False).all()
        self.assertEqual(0, len(notifications))
Пример #4
0
    def test_mark_read_a_topic_of_a_tag_subscribed(self):
        """
        When a user has a notification on a topic, the notification should be marked as read.
        """
        NewTopicSubscription.objects.toggle_follow(self.tag1, self.user1)

        topic = TopicFactory(forum=self.forum11, author=self.user2)
        topic.add_tags(['Linux'])

        PostFactory(topic=topic, author=self.user2, position=1)
        notifications = Notification.objects.filter(object_id=topic.pk, is_read=False).all()
        self.assertEqual(1, len(notifications))

        response = self.client.get(reverse('topic-posts-list', args=[topic.pk, topic.slug()]))
        self.assertEqual(response.status_code, 200)

        notifications = Notification.objects.filter(object_id=topic.pk, is_read=False).all()
        self.assertEqual(0, len(notifications))
Пример #5
0
    def test_notifications_on_a_tag_subscribed(self):
        """
        When a user subscribes to a tag, they receive a notification for each topic created.
        """
        # Subscribe.
        NewTopicSubscription.objects.toggle_follow(self.tag1, self.user1)

        topic1 = TopicFactory(forum=self.forum11, author=self.user2)
        topic1.add_tags(['Linux'])

        notifications = Notification.objects.filter(object_id=topic1.pk, is_read=False).all()
        self.assertEqual(1, len(notifications))

        # Unsubscribe.
        NewTopicSubscription.objects.toggle_follow(self.tag1, self.user1)

        topic2 = TopicFactory(forum=self.forum11, author=self.user2)
        topic2.add_tags(['Linux'])
        notifications = Notification.objects.filter(object_id=topic2.pk, is_read=False).all()
        self.assertEqual(0, len(notifications))
Пример #6
0
    def test_notifications_on_a_tag_subscribed(self):
        """
        When a user subscribes to a tag, they receive a notification for each topic created.
        """
        # Subscribe.
        NewTopicSubscription.objects.toggle_follow(self.tag1, self.user1)

        topic1 = TopicFactory(forum=self.forum11, author=self.user2)
        topic1.add_tags(['Linux'])

        notifications = Notification.objects.filter(object_id=topic1.pk, is_read=False).all()
        self.assertEqual(1, len(notifications))

        # Unsubscribe.
        NewTopicSubscription.objects.toggle_follow(self.tag1, self.user1)

        topic2 = TopicFactory(forum=self.forum11, author=self.user2)
        topic2.add_tags(['Linux'])
        notifications = Notification.objects.filter(object_id=topic2.pk, is_read=False).all()
        self.assertEqual(0, len(notifications))
Пример #7
0
    def test_add_tag(self):

        TagCSharp = TagFactory(title="C#")

        TagC = TagFactory(title="C")
        self.assertEqual(TagCSharp.slug, TagC.slug)
        self.assertNotEqual(TagCSharp.title, TagC.title)
        #post a topic with a tag
        result = self.client.post(reverse(
            'zds.forum.views.new'
        ) + '?forum={0}'.format(self.forum12.pk), {
            'title':
            u'[C#]Un autre sujet',
            'subtitle':
            u'Encore ces lombards en plein ete',
            'text':
            u'C\'est tout simplement l\'histoire de la ville de Paris que je voudrais vous conter '
        },
                                  follow=False)
        self.assertEqual(result.status_code, 302)

        #test the topic is added to the good tag

        self.assertEqual(
            Topic.objects.filter(tags__in=[TagCSharp]).order_by(
                "-last_message__pubdate").prefetch_related("tags").count(), 1)
        self.assertEqual(
            Topic.objects.filter(tags__in=[TagC]).order_by(
                "-last_message__pubdate").prefetch_related("tags").count(), 0)
        topicWithConflictTags = TopicFactory(forum=self.forum11,
                                             author=self.user)
        topicWithConflictTags.title = u"[C][c][ c][C ]name"
        (tags, title) = get_tag_by_title(topicWithConflictTags.title)
        topicWithConflictTags.add_tags(tags)
        self.assertEqual(topicWithConflictTags.tags.all().count(), 1)
        topicWithConflictTags = TopicFactory(forum=self.forum11,
                                             author=self.user)
        topicWithConflictTags.title = u"[][ ][	]name"
        (tags, title) = get_tag_by_title(topicWithConflictTags.title)
        topicWithConflictTags.add_tags(tags)
        self.assertEqual(topicWithConflictTags.tags.all().count(), 0)
Пример #8
0
 def test_add_tag(self):
     
     
     TagCSharp = TagFactory(title="C#")
     
     TagC = TagFactory(title="C")
     self.assertEqual(TagCSharp.slug, TagC.slug)
     self.assertNotEqual(TagCSharp.title, TagC.title)
     #post a topic with a tag
     result = self.client.post(
         reverse('zds.forum.views.new') + '?forum={0}'
         .format(self.forum12.pk),
         {'title': u'[C#]Un autre sujet',
          'subtitle': u'Encore ces lombards en plein ete',
          'text': u'C\'est tout simplement l\'histoire de la ville de Paris que je voudrais vous conter '
          },
         follow=False)
     self.assertEqual(result.status_code, 302)
     
     #test the topic is added to the good tag
     
     self.assertEqual( Topic.objects.filter(
             tags__in=[TagCSharp])
             .order_by("-last_message__pubdate").prefetch_related(
                 "tags").count(), 1)
     self.assertEqual( Topic.objects.filter(tags__in=[TagC])
             .order_by("-last_message__pubdate").prefetch_related(
                 "tags").count(), 0)
     topicWithConflictTags = TopicFactory(
         forum=self.forum11, author=self.user)
     topicWithConflictTags.title = u"[C][c][ c][C ]name"
     (tags, title) = get_tag_by_title(topicWithConflictTags.title)
     topicWithConflictTags.add_tags(tags)
     self.assertEqual(topicWithConflictTags.tags.all().count(), 1)
     topicWithConflictTags = TopicFactory(
         forum=self.forum11, author=self.user)
     topicWithConflictTags.title = u"[][ ][	]name"
     (tags, title) = get_tag_by_title(topicWithConflictTags.title)
     topicWithConflictTags.add_tags(tags)
     self.assertEqual(topicWithConflictTags.tags.all().count(), 0)
Пример #9
0
    def test_remove_subscribed_tag(self):
        """
            When the topic is edited and a tag is added to which the user has subscribed
        """
        NewTopicSubscription.objects.toggle_follow(self.tag1, self.user2)

        topic = TopicFactory(forum=self.forum11, author=self.user1)
        topic.add_tags(['Linux'])
        PostFactory(topic=topic, author=self.user1, position=1)

        notifications = Notification.objects.filter(object_id=topic.pk, is_read=False).all()
        self.assertEqual(1, len(notifications))

        self.client.post(
            reverse('topic-edit') + '?topic={0}'.format(topic.pk),
            {
                'title': 'Un autre sujet',
                'subtitle': 'Encore ces lombards en plein été',
                'text': 'C\'est tout simplement l\'histoire de la ville de Paris que je voudrais vous conter ',
                'tags': 'Windows'
            },
            follow=False)

        self.assertEqual(1, len(Notification.objects.filter(object_id=topic.pk, is_read=False, is_dead=True).all()))
Пример #10
0
    def test_top_tags(self):
        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 = topbar_forum_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 = topbar_forum_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
        self.overridden_zds_app["forum"]["top_tag_exclu"] = {"tag-4-4"}

        # User only sees the only 'public' tag left
        top_tags = topbar_forum_categories(user).get("tags")
        self.assertEqual(top_tags[0].title, "tag-3-5")
        self.assertEqual(len(top_tags), 1)
Пример #11
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)
Пример #12
0
    def test_top_tags(self):
        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 = topbar_forum_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 = topbar_forum_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
        self.overridden_zds_app['forum']['top_tag_exclu'] = {'tag-4-4'}

        # User only sees the only 'public' tag left
        top_tags = topbar_forum_categories(user).get('tags')
        self.assertEqual(top_tags[0].title, 'tag-3-5')
        self.assertEqual(len(top_tags), 1)
Пример #13
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)