Esempio n. 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") + 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()))
Esempio n. 2
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))
Esempio n. 3
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))
Esempio n. 4
0
    def test_no_notification_on_a_tag_subscribed_in_hidden_forum(self):
        """
        When a user subscribes to a tag and a topic is created using that tag in a hidden forum, no notification is sent
        """
        # Subscribe.
        user1 = ProfileFactory().user
        user2 = ProfileFactory().user

        group = Group.objects.create(name="Restricted")
        user2.groups.add(group)
        user2.save()
        category, forum = create_category_and_forum(group)

        tag1 = TagFactory(title="MyTagInHiddenForum")
        NewTopicSubscription.objects.toggle_follow(tag1, user1)

        topic1 = TopicFactory(forum=forum, author=user2)
        topic1.add_tags([tag1.title])

        notifications = Notification.objects.filter(object_id=topic1.pk,
                                                    is_read=False).all()
        self.assertEqual(0, len(notifications))
Esempio n. 5
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)