Пример #1
0
    def setUp(self):

        settings.EMAIL_BACKEND = \
            'django.core.mail.backends.locmem.EmailBackend'

        self.category1 = CategoryFactory(position=1)
        self.category2 = CategoryFactory(position=2)
        self.category3 = CategoryFactory(position=3)
        self.forum11 = ForumFactory(category=self.category1,
                                    position_in_category=1)
        self.forum12 = ForumFactory(category=self.category1,
                                    position_in_category=2)
        self.forum13 = ForumFactory(category=self.category1,
                                    position_in_category=3)
        self.forum21 = ForumFactory(category=self.category2,
                                    position_in_category=1)
        self.forum22 = ForumFactory(category=self.category2,
                                    position_in_category=2)
        self.user = ProfileFactory().user
        self.user2 = ProfileFactory().user
        log = self.client.login(username=self.user.username,
                                password='******')
        self.assertEqual(log, True)

        settings.ZDS_APP['member']['bot_account'] = ProfileFactory(
        ).user.username
Пример #2
0
    def setUp(self):
        # prepare a user and 2 Topic (with and without tags)

        settings.EMAIL_BACKEND = \
            'django.core.mail.backends.locmem.EmailBackend'

        self.category1 = CategoryFactory(position=1)
        self.forum = ForumFactory(
            category=self.category1,
            position_in_category=1)
        self.forum2 = ForumFactory(
            category=self.category1,
            position_in_category=2)

        self.user = ProfileFactory().user
        log = self.client.login(
            username=self.user.username,
            password='******')
        self.assertEqual(log, True)

        self.tag = TagFactory()
        self.topic1 = TopicFactory(forum=self.forum, author=self.user)
        self.topic2 = TopicFactory(forum=self.forum2, author=self.user)
        self.topic2.tags.add(self.tag)
        self.topic2.save()

        self.topicfeed = LastTopicsFeedRSS()
Пример #3
0
class ForumNotification(TestCase):
    def setUp(self):
        self.user1 = ProfileFactory().user
        self.user2 = ProfileFactory().user
        self.staff = StaffProfileFactory().user
        self.assertTrue(self.staff.has_perm('forum.change_topic'))
        self.category1 = CategoryFactory(position=1)
        self.forum11 = ForumFactory(category=self.category1,
                                    position_in_category=1)
        self.forum12 = ForumFactory(category=self.category1,
                                    position_in_category=2)
        for group in self.staff.groups.all():
            self.forum12.groups.add(group)
        self.forum12.save()

    def test_no_dead_notif_on_moving(self):
        NewTopicSubscription.objects.get_or_create_active(
            self.user1, self.forum11)
        self.assertTrue(
            self.client.login(username=self.user2.username,
                              password='******'))
        result = self.client.post(reverse('topic-new') +
                                  '?forum={0}'.format(self.forum11.pk), {
                                      'title': 'Super sujet',
                                      'subtitle': 'Pour tester les notifs',
                                      'text': "En tout cas l'un abonnement",
                                      'tags': ''
                                  },
                                  follow=False)
        self.assertEqual(result.status_code, 302)

        topic = Topic.objects.filter(title='Super sujet').first()
        subscription = NewTopicSubscription.objects.get_existing(
            self.user1, self.forum11, True)
        self.assertIsNotNone(subscription,
                             'There must be an active subscription for now')
        self.assertIsNotNone(subscription.last_notification,
                             'There must be a notification for now')
        self.assertFalse(subscription.last_notification.is_read)
        self.client.logout()
        self.assertTrue(
            self.client.login(username=self.staff.username,
                              password='******'))
        data = {'move': '', 'forum': self.forum12.pk, 'topic': topic.pk}
        response = self.client.post(reverse('topic-edit'), data, follow=False)
        self.assertEqual(302, response.status_code)
        subscription = NewTopicSubscription.objects.get_existing(
            self.user1, self.forum11, True)
        self.assertIsNotNone(subscription,
                             'There must still be an active subscription')
        self.assertIsNotNone(
            subscription.last_notification,
            'There must still be a notification as object is not removed.')
        self.assertEqual(
            subscription.last_notification,
            Notification.objects.filter(sender=self.user2).first())
        self.assertTrue(subscription.last_notification.is_read,
                        'As forum is not reachable, notification is read')
Пример #4
0
    def setUp(self):
        self.user1 = ProfileFactory().user
        self.user2 = ProfileFactory().user

        self.category1 = CategoryFactory(position=1)
        self.forum11 = ForumFactory(category=self.category1, position_in_category=1)
        self.forum12 = ForumFactory(category=self.category1, position_in_category=2)

        self.assertTrue(self.client.login(username=self.user1.username, password='******'))
Пример #5
0
 def setUp(self):
     self.user1 = ProfileFactory().user
     self.user2 = ProfileFactory().user
     self.staff = StaffProfileFactory().user
     self.assertTrue(self.staff.has_perm('forum.change_topic'))
     self.category1 = CategoryFactory(position=1)
     self.forum11 = ForumFactory(category=self.category1, position_in_category=1)
     self.forum12 = ForumFactory(category=self.category1, position_in_category=2)
     for group in self.staff.groups.all():
         self.forum12.group.add(group)
     self.forum12.save()
Пример #6
0
    def setUp(self):
        self.user1 = ProfileFactory().user
        self.user2 = ProfileFactory().user

        self.category1 = ForumCategoryFactory(position=1)
        self.forum11 = ForumFactory(category=self.category1,
                                    position_in_category=1)
        self.forum12 = ForumFactory(category=self.category1,
                                    position_in_category=2)

        self.tag1 = TagFactory(title="Linux")
        self.tag2 = TagFactory(title="Windows")

        self.client.force_login(self.user1)
Пример #7
0
    def setUp(self):

        # Create some forum's category
        self.category1 = CategoryFactory(position=1)
        self.category2 = CategoryFactory(position=2)

        # Create forum
        self.forum11 = ForumFactory(category=self.category1, position_in_category=1)

        # Only for staff
        self.staff1 = StaffProfileFactory()

        self.forum12 = ForumFactory(category=self.category2, position_in_category=2)
        self.forum12.group.add(Group.objects.filter(name='staff').first())
        self.forum12.save()
Пример #8
0
    def test_mark_notifications_as_read(self):
        category = CategoryFactory(position=1)
        forum = ForumFactory(category=category, position_in_category=1)
        topic = TopicFactory(forum=forum, author=self.user1)
        PostFactory(topic=topic, author=self.user1, position=1)
        PostFactory(topic=topic, author=self.user2, position=2)

        self.assertTrue(
            self.client.login(username=self.user1.username,
                              password='******'))

        notifications = Notification.objects.get_unread_notifications_of(
            self.user1)
        self.assertEqual(1, len(notifications))

        self.assertFalse(is_read(topic, self.user1))

        result = self.client.post(reverse('mark-notifications-as-read'),
                                  follow=False)
        self.assertEqual(result.status_code, 302)

        notifications = Notification.objects.get_unread_notifications_of(
            self.user1)
        self.assertEqual(0, len(notifications))

        self.assertTrue(is_read(topic, self.user1))
Пример #9
0
    def setUp(self):

        self.staff = StaffProfileFactory().user

        settings.EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend'
        self.mas = ProfileFactory().user
        self.overridden_zds_app['member']['bot_account'] = self.mas.username

        self.licence = LicenceFactory()
        self.subcategory = SubCategoryFactory()

        self.user_author = ProfileFactory().user
        self.user_staff = StaffProfileFactory().user
        self.user_guest = ProfileFactory().user

        self.tuto = PublishableContentFactory(type='TUTORIAL')
        self.tuto.authors.add(self.user_author)
        UserGalleryFactory(gallery=self.tuto.gallery, user=self.user_author, mode='W')
        self.tuto.licence = self.licence
        self.tuto.subcategory.add(self.subcategory)
        self.tuto.save()

        self.beta_forum = ForumFactory(
            pk=self.overridden_zds_app['forum']['beta_forum_id'],
            category=CategoryFactory(position=1),
            position_in_category=1)  # ensure that the forum, for the beta versions, is created

        self.tuto_draft = self.tuto.load_version()
        self.part1 = ContainerFactory(parent=self.tuto_draft, db_object=self.tuto)
        self.chapter1 = ContainerFactory(parent=self.part1, db_object=self.tuto)

        self.extract1 = ExtractFactory(container=self.chapter1, db_object=self.tuto)
        bot = Group(name=self.overridden_zds_app['member']['bot_group'])
        bot.save()
Пример #10
0
    def test_subscription_deactivated_and_notification_read_when_topic_moved(self):
        """
        When a topic is moved to a forum where subscribers can't read it, the subscriptions
        should be deactivated and notifications marked as read.
        """
        topic = TopicFactory(forum=self.forum11, author=self.user1)
        PostFactory(topic=topic, author=self.user1, position=1)
        other_user = ProfileFactory().user
        TopicAnswerSubscription.objects.toggle_follow(topic, other_user)
        PostFactory(topic=topic, author=ProfileFactory().user, position=2)

        self.assertIsNotNone(TopicAnswerSubscription.objects.get_existing(self.user1, topic, is_active=True))
        self.assertIsNotNone(Notification.objects.get(subscription__user=self.user1, is_read=False))

        forum_not_read = ForumFactory(category=self.category1, position_in_category=2)
        forum_not_read.groups.add(Group.objects.create(name='DummyGroup_1'))

        self.assertTrue(self.client.login(username=StaffProfileFactory().user.username, password='******'))
        data = {
            'move': '',
            'forum': forum_not_read.pk,
            'topic': topic.pk
        }
        response = self.client.post(reverse('topic-edit'), data, follow=False)

        self.assertEqual(302, response.status_code)
        self.assertIsNotNone(TopicAnswerSubscription.objects.get_existing(self.user1, topic, is_active=False))
        self.assertIsNotNone(Notification.objects.get(subscription__user=self.user1, is_read=True))
        self.assertFalse(TopicAnswerSubscription.objects.get_existing(other_user, topic).is_active)
        self.assertIsNotNone(Notification.objects.get(subscription__user=other_user, is_read=True))
Пример #11
0
    def setUp(self):
        self.user1 = ProfileFactory().user
        self.user2 = ProfileFactory().user

        self.category1 = ForumCategoryFactory(position=1)
        self.forum11 = ForumFactory(category=self.category1,
                                    position_in_category=1)
        self.forum12 = ForumFactory(category=self.category1,
                                    position_in_category=2)

        self.tag1 = TagFactory(title='Linux')
        self.tag2 = TagFactory(title='Windows')

        self.assertTrue(
            self.client.login(username=self.user1.username,
                              password='******'))
Пример #12
0
    def test_subscribe_association(self):
        """
        To test the "subscription to the association" form.
        """
        forum_category = CategoryFactory(position=1)
        forum = ForumFactory(category=forum_category, position_in_category=1)

        # overrides the settings to avoid 404 if forum does not exist
        settings.ZDS_APP['site']['association']['forum_ca_pk'] = forum.pk

        # send form
        long_str = ''
        for i in range(3100):
            long_str += 'A'

        result = self.client.post(reverse('pages-assoc-subscribe'), {
            'full_name': 'Anne Onyme',
            'email': '*****@*****.**',
            'naissance': '01 janvier 1970',
            'adresse': '42 rue du savoir, appartement 42, 75000 Paris, France',
            'justification': long_str
        },
                                  follow=False)

        self.assertEqual(result.status_code, 200)
Пример #13
0
    def setUp(self):
        self.overridden_zds_app = overridden_zds_app
        # don't build PDF to speed up the tests
        overridden_zds_app["content"]["build_pdf_when_published"] = False

        self.staff = StaffProfileFactory().user

        settings.EMAIL_BACKEND = "django.core.mail.backends.locmem.EmailBackend"
        self.mas = ProfileFactory().user
        overridden_zds_app["member"]["bot_account"] = self.mas.username

        bot = Group(name=overridden_zds_app["member"]["bot_group"])
        bot.save()
        self.external = UserFactory(
            username=overridden_zds_app["member"]["external_account"],
            password="******")

        self.beta_forum = ForumFactory(
            pk=overridden_zds_app["forum"]["beta_forum_id"],
            category=ForumCategoryFactory(position=1),
            position_in_category=1,
        )  # ensure that the forum, for the beta versions, is created

        self.licence = LicenceFactory()
        self.subcategory = SubCategoryFactory()
        self.tag = TagFactory()

        self.user_author = ProfileFactory().user
        self.user_staff = StaffProfileFactory().user
        self.user_guest = ProfileFactory().user

        # create an article
        self.article = PublishableContentFactory(type="ARTICLE")
        self.article.authors.add(self.user_author)
        UserGalleryFactory(gallery=self.article.gallery,
                           user=self.user_author,
                           mode="W")
        self.article.licence = self.licence
        self.article.subcategory.add(self.subcategory)
        self.article.tags.add(self.tag)
        self.article.save()

        # fill it with one extract
        self.article_draft = self.article.load_version()
        self.extract1 = ExtractFactory(container=self.article_draft,
                                       db_object=self.article)

        # then, publish it !
        version = self.article_draft.current_version
        self.published = publish_content(self.article,
                                         self.article_draft,
                                         is_major_update=True)

        self.article.sha_public = version
        self.article.sha_draft = version
        self.article.public_version = self.published
        self.article.save()

        self.articlefeed = LastArticlesFeedRSS()
Пример #14
0
    def setUp(self):
        self.user1 = ProfileFactory()
        self.staff = StaffProfileFactory()

        # Create a forum for later test
        self.forumcat = CategoryFactory()
        self.forum = ForumFactory(category=self.forumcat)
        self.forumtopic = TopicFactory(forum=self.forum, author=self.staff.user)
Пример #15
0
    def setUp(self):

        # don't build PDF to speed up the tests
        settings.ZDS_APP['content']['build_pdf_when_published'] = False

        self.staff = StaffProfileFactory().user

        settings.EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend'
        self.mas = ProfileFactory().user
        settings.ZDS_APP['member']['bot_account'] = self.mas.username

        bot = Group(name=settings.ZDS_APP['member']['bot_group'])
        bot.save()
        self.external = UserFactory(
            username=settings.ZDS_APP['member']['external_account'],
            password='******')

        self.beta_forum = ForumFactory(
            pk=settings.ZDS_APP['forum']['beta_forum_id'],
            category=CategoryFactory(position=1),
            position_in_category=1
        )  # ensure that the forum, for the beta versions, is created

        self.licence = LicenceFactory()
        self.subcategory = SubCategoryFactory()

        self.user_author = ProfileFactory().user
        self.user_staff = StaffProfileFactory().user
        self.user_guest = ProfileFactory().user

        # create an article
        self.article = PublishableContentFactory(type='ARTICLE')
        self.article.authors.add(self.user_author)
        UserGalleryFactory(gallery=self.article.gallery,
                           user=self.user_author,
                           mode='W')
        self.article.licence = self.licence
        self.article.subcategory.add(self.subcategory)
        self.article.save()

        # fill it with one extract
        self.article_draft = self.article.load_version()
        self.extract1 = ExtractFactory(container=self.article_draft,
                                       db_object=self.article)

        # then, publish it !
        version = self.article_draft.current_version
        self.published = publish_content(self.article,
                                         self.article_draft,
                                         is_major_update=True)

        self.article.sha_public = version
        self.article.sha_draft = version
        self.article.public_version = self.published
        self.article.save()

        self.articlefeed = LastArticlesFeedRSS()
Пример #16
0
    def setUp(self):
        # prepare a user and 2 Topic (with and without tags)

        settings.EMAIL_BACKEND = \
            'django.core.mail.backends.locmem.EmailBackend'

        self.category1 = CategoryFactory(position=1)
        self.forum = ForumFactory(
            category=self.category1,
            position_in_category=1)
        self.forum2 = ForumFactory(
            category=self.category1,
            position_in_category=2)
        self.forum3 = ForumFactory(
            category=self.category1,
            position_in_category=3)

        self.user = ProfileFactory().user
        log = self.client.login(
            username=self.user.username,
            password='******')
        self.assertEqual(log, True)

        self.tag = TagFactory()
        self.topic1 = TopicFactory(forum=self.forum, author=self.user)
        self.topic2 = TopicFactory(forum=self.forum2, author=self.user)
        self.topic2.tags.add(self.tag)
        self.topic2.save()

        # create 2 posts un each forum
        PostFactory(topic=self.topic1, author=self.user, position=1)
        PostFactory(topic=self.topic1, author=self.user, position=2)
        PostFactory(topic=self.topic2, author=self.user, position=1)
        PostFactory(topic=self.topic2, author=self.user, position=2)

        # and last topic + post alone
        self.tag2 = TagFactory()
        self.topic3 = TopicFactory(forum=self.forum3, author=self.user)
        self.post3 = PostFactory(topic=self.topic3, author=self.user, position=1)
        self.topic3.tags.add(self.tag2)
        self.topic3.save()

        self.postfeed = LastPostsFeedRSS()
Пример #17
0
    def setUp(self):

        settings.EMAIL_BACKEND = \
            'django.core.mail.backends.locmem.EmailBackend'

        self.category1 = CategoryFactory(position=1)
        self.category2 = CategoryFactory(position=2)
        self.category3 = CategoryFactory(position=3)
        self.forum11 = ForumFactory(category=self.category1,
                                    position_in_category=1)
        self.forum12 = ForumFactory(category=self.category1,
                                    position_in_category=2)
        self.forum13 = ForumFactory(category=self.category1,
                                    position_in_category=3)
        self.forum21 = ForumFactory(category=self.category2,
                                    position_in_category=1)
        self.forum22 = ForumFactory(category=self.category2,
                                    position_in_category=2)
        self.user = ProfileFactory().user
Пример #18
0
    def setUp(self):

        # Create some forum's category
        self.category1 = CategoryFactory(position=1)
        self.category2 = CategoryFactory(position=2)

        # Create forum
        self.forum11 = ForumFactory(category=self.category1,
                                    position_in_category=1)

        # Only for staff
        self.staff1 = StaffProfileFactory()

        self.forum12 = ForumFactory(category=self.category2,
                                    position_in_category=2)
        self.forum12.groups.add(Group.objects.filter(name='staff').first())
        self.forum12.save()

        # don't build PDF to speed up the tests
        settings.ZDS_APP['content']['build_pdf_when_published'] = False
Пример #19
0
 def setUp(self):
     self.user1 = ProfileFactory().user
     self.user2 = ProfileFactory().user
     self.to_be_changed_staff = StaffProfileFactory().user
     self.staff = StaffProfileFactory().user
     self.assertTrue(self.staff.has_perm('forum.change_topic'))
     self.category1 = CategoryFactory(position=1)
     self.forum11 = ForumFactory(category=self.category1, position_in_category=1)
     self.forum12 = ForumFactory(category=self.category1, position_in_category=2)
     for group in self.staff.groups.all():
         self.forum12.groups.add(group)
     self.forum12.save()
Пример #20
0
    def test_no_duplicate_subscription(self):
        """
        Creating two same subscriptions is rejected by the database.
        """
        category = CategoryFactory(position=1)
        forum = ForumFactory(category=category, position_in_category=1)
        topic = TopicFactory(forum=forum, author=self.user1)
        TopicAnswerSubscription.objects.toggle_follow(topic, self.user1, True)

        subscription = TopicAnswerSubscription(user=self.user1, content_object=topic)
        with self.assertRaises(IntegrityError):
            subscription.save()
Пример #21
0
    def setUp(self):
        # prepare a user and 2 Topic (with and without tags)

        settings.EMAIL_BACKEND = "django.core.mail.backends.locmem.EmailBackend"

        self.category1 = ForumCategoryFactory(position=1)
        self.forum = ForumFactory(category=self.category1,
                                  position_in_category=1)
        self.forum2 = ForumFactory(category=self.category1,
                                   position_in_category=2)

        self.user = ProfileFactory().user
        self.client.force_login(self.user)

        self.tag = TagFactory()
        self.topic1 = TopicFactory(forum=self.forum, author=self.user)
        self.topic2 = TopicFactory(forum=self.forum2, author=self.user)
        self.topic2.tags.add(self.tag)
        self.topic2.save()

        self.topicfeed = LastTopicsFeedRSS()
Пример #22
0
def load_forums(cli, size, fake, *_, **__):
    """
    Load forums
    """
    nb_forums = size * 8
    cli.stdout.write("Nombres de Forums à créer : {}".format(nb_forums))
    tps1 = time.time()
    nb_categories = ForumCategory.objects.count()
    if nb_categories == 0:
        cli.stdout.write(
            "Il n'y a aucune catgorie actuellement. "
            "Vous devez rajouter les categories de forum dans vos fixtures (category_forum)"
        )
    else:
        categories = list(ForumCategory.objects.all())
        for i in range(0, nb_forums):
            with contextlib.suppress(IntegrityError):
                forum = ForumFactory(category=categories[i % nb_categories],
                                     position_in_category=(i / nb_categories) +
                                     1)
                forum.title = fake.word()
                forum.subtitle = fake.sentence(nb_words=15,
                                               variable_nb_words=True)
                forum.save()
            sys.stdout.write(" Forum {}/{}  \r".format(i + 1, nb_forums))
            sys.stdout.flush()
        tps2 = time.time()
        cli.stdout.write("\nFait en {} sec".format(tps2 - tps1))
Пример #23
0
    def setUp(self):
        # Create some forum's category
        self.category1 = CategoryFactory(position=1)
        self.category2 = CategoryFactory(position=2)

        # Create forum
        self.forum11 = ForumFactory(category=self.category1, position_in_category=1)

        # Only for staff
        self.staff1 = StaffProfileFactory()

        self.forum12 = ForumFactory(category=self.category2, position_in_category=2)
        self.forum12.groups.add(Group.objects.filter(name='staff').first())
        self.forum12.save()
Пример #24
0
    def test_update(self):
        # create topic and content and toggle request
        author = ProfileFactory().user
        category = ForumCategoryFactory(position=1)
        forum = ForumFactory(category=category, position_in_category=1)
        topic = TopicFactory(forum=forum, author=author)

        FeaturedRequested.objects.toogle_request(topic, author)

        # ignore
        staff = StaffProfileFactory()
        login_check = self.client.login(username=staff.user.username,
                                        password="******")
        self.assertTrue(login_check)

        content_type = ContentType.objects.get_for_model(topic)
        q = FeaturedRequested.objects.get(object_id=topic.pk,
                                          content_type__pk=content_type.pk)
        self.assertFalse(q.rejected)

        response = self.client.post(reverse("featured-resource-request-update",
                                            kwargs={"pk": q.pk}),
                                    {"operation": "REJECT"},
                                    follow=False)
        self.assertEqual(200, response.status_code)

        q = FeaturedRequested.objects.get(pk=q.pk)
        self.assertTrue(q.rejected)
        self.assertFalse(q.rejected_for_good)

        response = self.client.post(reverse("featured-resource-request-update",
                                            kwargs={"pk": q.pk}),
                                    {"operation": "CONSIDER"},
                                    follow=False)
        self.assertEqual(200, response.status_code)

        q = FeaturedRequested.objects.get(pk=q.pk)
        self.assertFalse(q.rejected)

        response = self.client.post(
            reverse("featured-resource-request-update", kwargs={"pk": q.pk}),
            {"operation": "REJECT_FOR_GOOD"},
            follow=False,
        )
        self.assertEqual(200, response.status_code)

        q = FeaturedRequested.objects.get(pk=q.pk)
        self.assertTrue(q.rejected)
        self.assertTrue(q.rejected_for_good)
Пример #25
0
 def setUp(self):
     settings.EMAIL_BACKEND = \
         'django.core.mail.backends.locmem.EmailBackend'
     self.mas = ProfileFactory()
     settings.ZDS_APP['member']['bot_account'] = self.mas.user.username
     self.anonymous = UserFactory(
         username=settings.ZDS_APP["member"]["anonymous_account"],
         password="******")
     self.external = UserFactory(
         username=settings.ZDS_APP["member"]["external_account"],
         password="******")
     self.category1 = CategoryFactory(position=1)
     self.forum11 = ForumFactory(category=self.category1,
                                 position_in_category=1)
     self.staff = StaffProfileFactory().user
Пример #26
0
 def test_success_initial_content_topic(self):
     author = ProfileFactory().user
     category = ForumCategoryFactory(position=1)
     forum = ForumFactory(category=category, position_in_category=1)
     topic = TopicFactory(forum=forum, author=author)
     staff = StaffProfileFactory()
     self.client.force_login(staff.user)
     response = self.client.get(
         "{}?content_type=topic&content_id={}".format(reverse("featured-resource-create"), topic.id)
     )
     initial_dict = response.context["form"].initial
     self.assertEqual(initial_dict["title"], topic.title)
     self.assertEqual(initial_dict["authors"], str(author))
     self.assertEqual(initial_dict["type"], _("Un sujet"))
     self.assertEqual(initial_dict["url"], f"http://testserver{topic.get_absolute_url()}")
Пример #27
0
    def setUp(self):

        # don't build PDF to speed up the tests
        settings.ZDS_APP['content']['build_pdf_when_published'] = False

        self.staff = StaffProfileFactory().user

        settings.EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend'
        self.mas = ProfileFactory().user
        settings.ZDS_APP['member']['bot_account'] = self.mas.username

        self.licence = LicenceFactory()
        self.subcategory = SubCategoryFactory()

        self.user_author = ProfileFactory().user
        self.user_staff = StaffProfileFactory().user
        self.user_guest = ProfileFactory().user

        self.tuto = PublishableContentFactory(type='TUTORIAL')
        self.tuto.authors.add(self.user_author)
        UserGalleryFactory(gallery=self.tuto.gallery,
                           user=self.user_author,
                           mode='W')
        self.tuto.licence = self.licence
        self.tuto.subcategory.add(self.subcategory)
        self.tuto.save()

        self.beta_forum = ForumFactory(
            pk=settings.ZDS_APP['forum']['beta_forum_id'],
            category=CategoryFactory(position=1),
            position_in_category=1
        )  # ensure that the forum, for the beta versions, is created

        self.tuto_draft = self.tuto.load_version()
        self.part1 = ContainerFactory(parent=self.tuto_draft,
                                      db_object=self.tuto)
        self.chapter1 = ContainerFactory(parent=self.part1,
                                         db_object=self.tuto)

        self.extract1 = ExtractFactory(container=self.chapter1,
                                       db_object=self.tuto)
        bot = Group(name=settings.ZDS_APP["member"]["bot_group"])
        bot.save()
        self.external = UserFactory(
            username=settings.ZDS_APP["member"]["external_account"],
            password="******")
Пример #28
0
    def setUp(self):
        self.staff = StaffFactory()
        self.dummy_author = ProfileFactory()

        self.category = CategoryFactory(position=1)
        self.forum = ForumFactory(category=self.category, position_in_category=1)
        self.topic = TopicFactory(forum=self.forum, author=self.dummy_author.user)
        self.post = PostFactory(topic=self.topic, author=self.dummy_author.user, position=1)

        self.alerts = []
        for i in range(20):
            alert = Alert(author=self.dummy_author.user,
                          comment=self.post,
                          scope='FORUM',
                          text=u'pouet-{}'.format(i),
                          pubdate=(datetime.now() + timedelta(minutes=i)))
            alert.save()
            self.alerts.append(alert)
Пример #29
0
    def test_mark_all_notifications_as_read_when_toggle_follow(self):
        """
        When a user unsubscribes from a content, we mark all notifications for
        this content as read.
        """
        category = CategoryFactory(position=1)
        forum = ForumFactory(category=category, position_in_category=1)
        topic = TopicFactory(forum=forum, author=self.user1)
        PostFactory(topic=topic, author=self.user1, position=1)
        PostFactory(topic=topic, author=self.user2, position=2)

        notifications = Notification.objects.get_unread_notifications_of(self.user1)
        self.assertEqual(1, len(notifications))
        self.assertIsNotNone(notifications.first())
        self.assertEqual(topic.last_message, notifications.first().content_object)

        TopicAnswerSubscription.objects.toggle_follow(topic, self.user1)

        self.assertEqual(0, len(Notification.objects.get_unread_notifications_of(self.user1)))
Пример #30
0
 def test_success_initial_content_topic(self):
     author = ProfileFactory().user
     category = CategoryFactory(position=1)
     forum = ForumFactory(category=category, position_in_category=1)
     topic = TopicFactory(forum=forum, author=author)
     staff = StaffProfileFactory()
     login_check = self.client.login(username=staff.user.username,
                                     password='******')
     self.assertTrue(login_check)
     response = self.client.get(
         '{}?content_type=topic&content_id={}'.format(
             reverse('featured-resource-create'), topic.id))
     initial_dict = response.context['form'].initial
     self.assertEqual(initial_dict['title'], topic.title)
     self.assertEqual(initial_dict['authors'], str(author))
     self.assertEqual(initial_dict['type'], _('Un sujet'))
     self.assertEqual(
         initial_dict['url'],
         'http://testserver{}'.format(topic.get_absolute_url()))
Пример #31
0
    def test_mark_notifications_as_read(self):
        category = ForumCategoryFactory(position=1)
        forum = ForumFactory(category=category, position_in_category=1)
        topic = TopicFactory(forum=forum, author=self.user1)
        PostFactory(topic=topic, author=self.user1, position=1)
        PostFactory(topic=topic, author=self.user2, position=2)

        self.client.force_login(self.user1)

        notifications = Notification.objects.get_unread_notifications_of(
            self.user1)
        self.assertEqual(1, len(notifications))

        self.assertFalse(topic.is_read)

        result = self.client.post(reverse("mark-notifications-as-read"),
                                  follow=False)
        self.assertEqual(result.status_code, 302)

        notifications = Notification.objects.get_unread_notifications_of(
            self.user1)
        self.assertEqual(0, len(notifications))

        self.assertTrue(Topic.objects.get(pk=topic.pk).is_read)
Пример #32
0
class ForumNotification(TestCase):
    def setUp(self):
        self.user1 = ProfileFactory().user
        self.user2 = ProfileFactory().user
        self.to_be_changed_staff = StaffProfileFactory().user
        self.staff = StaffProfileFactory().user
        self.assertTrue(self.staff.has_perm('forum.change_topic'))
        self.category1 = CategoryFactory(position=1)
        self.forum11 = ForumFactory(category=self.category1, position_in_category=1)
        self.forum12 = ForumFactory(category=self.category1, position_in_category=2)
        for group in self.staff.groups.all():
            self.forum12.groups.add(group)
        self.forum12.save()

    def test_ping_unknown(self):
        overridden_zds_app['comment']['enable_pings'] = True
        self.assertTrue(self.client.login(username=self.user2.username, password='******'))
        result = self.client.post(
            reverse('topic-new') + '?forum={0}'.format(self.forum11.pk),
            {
                'title': 'Super sujet',
                'subtitle': 'Pour tester les notifs',
                'text': '@anUnExistingUser is pinged, also a special chars user @{}',
                'tags': ''
            },
            follow=False)
        self.assertEqual(result.status_code, 302, 'Request must succeed')
        self.assertEqual(0, PingSubscription.objects.count(),
                         'As one user is pinged, only one subscription is created.')

    def test_no_auto_ping(self):
        overridden_zds_app['comment']['enable_pings'] = True
        self.assertTrue(self.client.login(username=self.user2.username, password='******'))
        result = self.client.post(
            reverse('topic-new') + '?forum={0}'.format(self.forum11.pk),
            {
                'title': 'Super sujet',
                'subtitle': 'Pour tester les notifs',
                'text': '@{} is pinged, not @{}'.format(self.user1.username, self.user2.username),
                'tags': ''
            },
            follow=False)
        self.assertEqual(result.status_code, 302)
        self.assertEqual(1, PingSubscription.objects.count(),
                         'As one user is pinged, only one subscription is created.')

    def test_no_reping_on_edition(self):
        """
        to be more accurate : on edition, only ping **new** members
        """
        overridden_zds_app['comment']['enable_pings'] = True
        self.assertTrue(self.client.login(username=self.user2.username, password='******'))
        result = self.client.post(
            reverse('topic-new') + '?forum={0}'.format(self.forum11.pk),
            {
                'title': 'Super sujet',
                'subtitle': 'Pour tester les notifs',
                'text': '@{} is pinged'.format(self.user1.username),
                'tags': ''
            },
            follow=False)
        self.assertEqual(result.status_code, 302)
        self.assertEqual(1, PingSubscription.objects.count(),
                         'As one user is pinged, only one subscription is created.')
        self.assertEqual(1, Notification.objects.count())
        user3 = ProfileFactory().user
        post = Topic.objects.last().last_message
        result = self.client.post(
            reverse('post-edit') + '?message={0}'.format(post.pk),
            {
                'title': 'Super sujet',
                'subtitle': 'Pour tester les notifs',
                'text': '@{} is pinged even twice @{}'.format(self.user1.username, self.user1.username),
                'tags': ''
            },
            follow=False)
        self.assertEqual(result.status_code, 302)
        self.assertEqual(1, PingSubscription.objects.count(),
                         'No added subscription.')
        self.assertEqual(1, Notification.objects.count())
        result = self.client.post(
            reverse('post-edit') + '?message={0}'.format(post.pk),
            {
                'title': 'Super sujet',
                'subtitle': 'Pour tester les notifs',
                'text': '@{} is pinged even twice @{} and add @{}'.format(self.user1.username,
                                                                          self.user1.username, user3.username),
                'tags': ''
            },
            follow=False)
        self.assertEqual(result.status_code, 302)
        self.assertEqual(2, PingSubscription.objects.count())
        self.assertEqual(2, Notification.objects.count())

    def test_loose_ping_on_edition(self):
        """
        to be more accurate : on edition, only ping **new** members
        """
        overridden_zds_app['comment']['enable_pings'] = True
        self.assertTrue(self.client.login(username=self.user2.username, password='******'))
        result = self.client.post(
            reverse('topic-new') + '?forum={0}'.format(self.forum11.pk),
            {
                'title': 'Super sujet',
                'subtitle': 'Pour tester les notifs',
                'text': '@{} is pinged'.format(self.user1.username),
                'tags': ''
            },
            follow=False)
        self.assertEqual(result.status_code, 302)
        self.assertEqual(1, PingSubscription.objects.count(),
                         'As one user is pinged, only one subscription is created.')
        self.assertEqual(1, Notification.objects.count())
        post = Topic.objects.last().last_message
        result = self.client.post(
            reverse('post-edit') + '?message={0}'.format(post.pk),
            {
                'title': 'Super sujet',
                'subtitle': 'Pour tester les notifs',
                'text': '@ {} is no more pinged '.format(self.user1.username),
                'tags': ''
            },
            follow=False)
        self.assertEqual(result.status_code, 302)
        self.assertEqual(1, PingSubscription.objects.count(),
                         'No added subscription.')
        self.assertFalse(PingSubscription.objects.first().is_active)
        self.assertEqual(1, Notification.objects.count())
        self.assertTrue(Notification.objects.first().is_read)

    def test_no_dead_notif_on_moving(self):
        NewTopicSubscription.objects.get_or_create_active(self.user1, self.forum11)
        self.assertTrue(self.client.login(username=self.user2.username, password='******'))
        result = self.client.post(
            reverse('topic-new') + '?forum={0}'.format(self.forum11.pk),
            {
                'title': 'Super sujet',
                'subtitle': 'Pour tester les notifs',
                'text': "En tout cas l'un abonnement",
                'tags': ''
            },
            follow=False)
        self.assertEqual(result.status_code, 302)

        topic = Topic.objects.filter(title='Super sujet').first()
        subscription = NewTopicSubscription.objects.get_existing(self.user1, self.forum11, True)
        self.assertIsNotNone(subscription, 'There must be an active subscription for now')
        self.assertIsNotNone(subscription.last_notification, 'There must be a notification for now')
        self.assertFalse(subscription.last_notification.is_read)
        self.client.logout()
        self.assertTrue(self.client.login(username=self.staff.username, password='******'))
        data = {
            'move': '',
            'forum': self.forum12.pk,
            'topic': topic.pk
        }
        response = self.client.post(reverse('topic-edit'), data, follow=False)
        self.assertEqual(302, response.status_code)
        subscription = NewTopicSubscription.objects.get_existing(self.user1, self.forum11, True)
        self.assertIsNotNone(subscription, 'There must still be an active subscription')
        self.assertIsNotNone(subscription.last_notification,
                             'There must still be a notification as object is not removed.')
        self.assertEqual(subscription.last_notification,
                         Notification.objects.filter(sender=self.user2).first())
        self.assertTrue(subscription.last_notification.is_read, 'As forum is not reachable, notification is read')

    def test_no_ping_on_private_forum(self):
        self.assertTrue(self.client.login(username=self.staff.username, password='******'))
        result = self.client.post(
            reverse('topic-new') + '?forum={0}'.format(self.forum12.pk),
            {
                'title': 'Super sujet',
                'subtitle': 'Pour tester les notifs',
                'text': 'ping @{}'.format(self.user1.username),
                'tags': ''
            },
            follow=False)
        self.assertEqual(result.status_code, 302)

        topic = Topic.objects.filter(title='Super sujet').first()
        subscription = PingSubscription.objects.get_existing(self.user1, topic.last_message, True)
        self.assertIsNone(subscription, 'There must be no active subscription for now')

    def test_no_dead_ping_notif_on_moving_to_private_forum(self):
        self.assertTrue(self.client.login(username=self.user2.username, password='******'))
        result = self.client.post(
            reverse('topic-new') + '?forum={0}'.format(self.forum11.pk),
            {
                'title': 'Super sujet',
                'subtitle': 'Pour tester les notifs',
                'text': 'ping @{}'.format(self.user1.username),
                'tags': ''
            },
            follow=False)
        self.assertEqual(result.status_code, 302)

        topic = Topic.objects.filter(title='Super sujet').first()
        subscription = PingSubscription.objects.get_existing(self.user1, topic.last_message, True)
        self.assertIsNotNone(subscription, 'There must be an active subscription for now')
        self.assertIsNotNone(subscription.last_notification, 'There must be a notification for now')
        self.assertFalse(subscription.last_notification.is_read)
        self.client.logout()
        self.assertTrue(self.client.login(username=self.staff.username, password='******'))
        data = {
            'move': '',
            'forum': self.forum12.pk,
            'topic': topic.pk
        }
        response = self.client.post(reverse('topic-edit'), data, follow=False)
        self.assertEqual(302, response.status_code)
        subscription = PingSubscription.objects.get_existing(self.user1, topic.last_message, True)
        self.assertIsNotNone(subscription, 'There must still be an active subscription')
        self.assertIsNotNone(subscription.last_notification,
                             'There must still be a notification as object is not removed.')
        self.assertEqual(subscription.last_notification,
                         Notification.objects.filter(sender=self.user2).first())
        self.assertTrue(subscription.last_notification.is_read, 'As forum is not reachable, notification is read')

    def test_no_more_notif_on_losing_all_groups(self):
        NewTopicSubscription.objects.get_or_create_active(self.to_be_changed_staff, self.forum12)
        self.assertTrue(self.client.login(username=self.staff.username, password='******'))
        self.client.post(
            reverse('topic-new') + '?forum={0}'.format(self.forum12.pk),
            {
                'title': 'Super sujet',
                'subtitle': 'Pour tester les notifs',
                'text': "En tout cas l'un abonnement",
                'tags': ''
            },
            follow=False)
        subscription = NewTopicSubscription.objects.get_existing(self.to_be_changed_staff, self.forum12, True)
        self.assertIsNotNone(subscription, 'There must be an active subscription for now')
        self.to_be_changed_staff.groups.clear()
        self.to_be_changed_staff.save()
        subscription = NewTopicSubscription.objects.get_existing(self.to_be_changed_staff, self.forum12, False)
        self.assertIsNotNone(subscription, 'There must be an active subscription for now')
        self.assertFalse(subscription.is_active)

    def test_no_more_notif_on_losing_one_group(self):
        NewTopicSubscription.objects.get_or_create_active(self.to_be_changed_staff, self.forum12)
        self.assertTrue(self.client.login(username=self.staff.username, password='******'))
        self.client.post(
            reverse('topic-new') + '?forum={0}'.format(self.forum12.pk),
            {
                'title': 'Super sujet',
                'subtitle': 'Pour tester les notifs',
                'text': "En tout cas l'un abonnement",
                'tags': ''
            },
            follow=False)
        subscription = NewTopicSubscription.objects.get_existing(self.to_be_changed_staff, self.forum12, True)
        self.assertIsNotNone(subscription, 'There must be an active subscription for now')
        self.to_be_changed_staff.groups.remove(list(self.to_be_changed_staff.groups.all())[0])
        self.to_be_changed_staff.save()
        subscription = NewTopicSubscription.objects.get_existing(self.to_be_changed_staff, self.forum12, False)
        self.assertIsNotNone(subscription, 'There must be an active subscription for now')
        self.assertFalse(subscription.is_active)
Пример #33
0
class TopBarTests(TutorialTestMixin, TestCase):

    def setUp(self):
        # Create some forum's category
        self.category1 = CategoryFactory(position=1)
        self.category2 = CategoryFactory(position=2)

        # Create forum
        self.forum11 = ForumFactory(category=self.category1, position_in_category=1)

        # Only for staff
        self.staff1 = StaffProfileFactory()

        self.forum12 = ForumFactory(category=self.category2, position_in_category=2)
        self.forum12.groups.add(Group.objects.filter(name='staff').first())
        self.forum12.save()

        # don't build PDF to speed up the tests

    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)

    def test_top_tags_content(self):
        tags_tuto = ['a', 'b', 'c']
        tags_article = ['a', 'd', 'e']

        content = PublishedContentFactory(type='TUTORIAL', author_list=[ProfileFactory().user])
        content.add_tags(tags_tuto)
        content.save()
        tags_tuto = content.tags.all()

        content = PublishedContentFactory(type='ARTICLE', author_list=[ProfileFactory().user])
        content.add_tags(tags_article)
        content.save()
        tags_article = content.tags.all()

        top_tags_tuto = topbar_publication_categories('TUTORIAL').get('tags')
        top_tags_article = topbar_publication_categories('ARTICLE').get('tags')

        self.assertEqual(list(top_tags_tuto), list(tags_tuto))
        self.assertEqual(list(top_tags_article), list(tags_article))

    def test_content_ordering(self):
        category_1 = ContentCategoryFactory()
        category_2 = ContentCategoryFactory()
        subcategory_1 = SubCategoryFactory(category=category_1)
        subcategory_1.position = 5
        subcategory_1.save()
        subcategory_2 = SubCategoryFactory(category=category_1)
        subcategory_2.position = 1
        subcategory_2.save()
        subcategory_3 = SubCategoryFactory(category=category_2)

        tuto_1 = PublishableContentFactory(type='TUTORIAL')
        tuto_1.subcategory.add(subcategory_1)
        tuto_1_draft = tuto_1.load_version()
        publish_content(tuto_1, tuto_1_draft, is_major_update=True)

        top_categories_tuto = topbar_publication_categories('TUTORIAL').get('categories')
        expected = [(subcategory_1.title, subcategory_1.slug, category_1.slug)]
        self.assertEqual(top_categories_tuto[category_1.title], expected)

        tuto_2 = PublishableContentFactory(type='TUTORIAL')
        tuto_2.subcategory.add(subcategory_2)
        tuto_2_draft = tuto_2.load_version()
        publish_content(tuto_2, tuto_2_draft, is_major_update=True)

        top_categories_tuto = topbar_publication_categories('TUTORIAL').get('categories')
        # New subcategory is now first is the list
        expected.insert(0, (subcategory_2.title, subcategory_2.slug, category_1.slug))
        self.assertEqual(top_categories_tuto[category_1.title], expected)

        article_1 = PublishableContentFactory(type='TUTORIAL')
        article_1.subcategory.add(subcategory_3)
        article_1_draft = tuto_2.load_version()
        publish_content(article_1, article_1_draft, is_major_update=True)

        # New article has no impact
        top_categories_tuto = topbar_publication_categories('TUTORIAL').get('categories')
        self.assertEqual(top_categories_tuto[category_1.title], expected)

        top_categories_contents = topbar_publication_categories(['TUTORIAL', 'ARTICLE']).get('categories')
        expected_2 = [(subcategory_3.title, subcategory_3.slug, category_2.slug)]
        self.assertEqual(top_categories_contents[category_1.title], expected)
        self.assertEqual(top_categories_contents[category_2.title], expected_2)