예제 #1
0
    def setUp(self):
        # Create a user
        self.author = ProfileFactory()

        # Create tags
        self.tag_0 = TagFactory()
        self.tag_1 = TagFactory()
        self.tag_from_other_content = TagFactory()
        self.tags_name = [
            self.tag_0.title, self.tag_1.title,
            self.tag_from_other_content.title
        ]

        # Create contents
        self.content = PublishableContentFactory(
            author_list=[self.author.user])
        self.other_content = PublishableContentFactory(
            author_list=[self.author.user])
        self.other_content.tags.add(self.tag_from_other_content)
        self.other_content.save()

        # Get information to be reused in tests
        self.form_url = reverse("content:edit-tags",
                                kwargs={"pk": self.content.pk})

        # Log in with an authorized user (e.g the author of the content) to perform the tests
        login_success = self.client.login(username=self.author.user.username,
                                          password="******")
        self.assertTrue(login_success)
예제 #2
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.tag1 = TagFactory(title='Linux')
        self.tag2 = TagFactory(title='Windows')

        self.assertTrue(self.client.login(username=self.user1.username, password='******'))
예제 #3
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)
예제 #4
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()
예제 #5
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()
예제 #6
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()
예제 #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 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()
예제 #9
0
    def test_upercase_and_lowercase_search_give_same_results(self):
        """Pretty self-explanatory function name, isn't it ?"""

        if not self.manager.connected_to_es:
            return

        # 1. Index lowercase stuffs
        text_lc = 'test'

        topic_1_lc = TopicFactory(forum=self.forum,
                                  author=self.user,
                                  title=text_lc)

        tag_lc = TagFactory(title=text_lc)
        topic_1_lc.tags.add(tag_lc)
        topic_1_lc.subtitle = text_lc
        topic_1_lc.save()

        post_1_lc = PostFactory(topic=topic_1_lc, author=self.user, position=1)
        post_1_lc.text = post_1_lc.text_html = text_lc
        post_1_lc.save()

        tuto_lc = PublishableContentFactory(type='TUTORIAL')
        tuto_draft_lc = tuto_lc.load_version()

        tuto_lc.title = text_lc
        tuto_lc.authors.add(self.user)
        subcategory_lc = SubCategoryFactory(title=text_lc)
        tuto_lc.subcategory.add(subcategory_lc)
        tuto_lc.tags.add(tag_lc)
        tuto_lc.save()

        tuto_draft_lc.description = text_lc
        tuto_draft_lc.repo_update_top_container(text_lc, tuto_lc.slug, text_lc,
                                                text_lc)

        chapter1_lc = ContainerFactory(parent=tuto_draft_lc, db_object=tuto_lc)
        extract_lc = ExtractFactory(container=chapter1_lc, db_object=tuto_lc)
        extract_lc.repo_update(text_lc, text_lc)

        published_lc = publish_content(tuto_lc,
                                       tuto_draft_lc,
                                       is_major_update=True)

        tuto_lc.sha_public = tuto_draft_lc.current_version
        tuto_lc.sha_draft = tuto_draft_lc.current_version
        tuto_lc.public_version = published_lc
        tuto_lc.save()

        # 2. Index uppercase stuffs
        text_uc = 'TEST'

        topic_1_uc = TopicFactory(forum=self.forum,
                                  author=self.user,
                                  title=text_uc)

        topic_1_uc.tags.add(
            tag_lc)  # Note: a constraint forces tags title to be unique
        topic_1_uc.subtitle = text_uc
        topic_1_uc.save()

        post_1_uc = PostFactory(topic=topic_1_uc, author=self.user, position=1)
        post_1_uc.text = post_1_uc.text_html = text_uc
        post_1_uc.save()

        tuto_uc = PublishableContentFactory(type='TUTORIAL')
        tuto_draft_uc = tuto_uc.load_version()

        tuto_uc.title = text_uc
        tuto_uc.authors.add(self.user)
        tuto_uc.subcategory.add(subcategory_lc)
        tuto_uc.tags.add(tag_lc)
        tuto_uc.save()

        tuto_draft_uc.description = text_uc
        tuto_draft_uc.repo_update_top_container(text_uc, tuto_uc.slug, text_uc,
                                                text_uc)

        chapter1_uc = ContainerFactory(parent=tuto_draft_uc, db_object=tuto_uc)
        extract_uc = ExtractFactory(container=chapter1_uc, db_object=tuto_uc)
        extract_uc.repo_update(text_uc, text_uc)

        published_uc = publish_content(tuto_uc,
                                       tuto_draft_uc,
                                       is_major_update=True)

        tuto_uc.sha_public = tuto_draft_uc.current_version
        tuto_uc.sha_draft = tuto_draft_uc.current_version
        tuto_uc.public_version = published_uc
        tuto_uc.save()

        # 3. Index and search:
        self.assertEqual(
            len(
                self.manager.setup_search(Search().query(
                    MatchAll())).execute()), 0)

        # index
        for model in self.indexable:
            if model is FakeChapter:
                continue
            self.manager.es_bulk_indexing_of_model(model)
        self.manager.refresh_index()

        result = self.client.get(reverse('search:query') + '?q=' + text_lc,
                                 follow=False)
        self.assertEqual(result.status_code, 200)

        response_lc = result.context['object_list'].execute()
        self.assertEqual(response_lc.hits.total, 8)

        result = self.client.get(reverse('search:query') + '?q=' + text_uc,
                                 follow=False)
        self.assertEqual(result.status_code, 200)

        response_uc = result.context['object_list'].execute()
        self.assertEqual(response_uc.hits.total, 8)

        for responses in zip(
                response_lc,
                response_uc):  # we should get results in the same order!
            self.assertEqual(responses[0].meta.id, responses[1].meta.id)
예제 #10
0
    def test_filters(self):
        """ Test filtering by category & tag """
        subcategory2 = SubCategoryFactory()
        subcategory3 = SubCategoryFactory()
        tag2 = TagFactory()
        tag3 = TagFactory()

        # Add a new tuto & publish it

        article2 = PublishableContentFactory(type="ARTICLE")
        article2.authors.add(self.user_author)
        article2.licence = self.licence
        article2.subcategory.add(subcategory2)
        article2.tags.add(self.tag)
        article2.tags.add(tag2)
        article2.save()

        article2_draft = article2.load_version()
        article2.sha_public = article2.sha_draft = article2_draft.current_version
        article2.public_version = publish_content(article2,
                                                  article2_draft,
                                                  is_major_update=True)
        article2.save()

        # Default view

        ret = [item.content for item in self.articlefeed.items()]
        self.assertEqual(ret, [article2, self.article])

        # Filter by subcategory

        self.articlefeed.query_params = {"subcategory": self.subcategory.slug}
        ret = [item.content for item in self.articlefeed.items()]
        self.assertEqual(ret, [self.article])

        self.articlefeed.query_params = {
            "subcategory": f" {self.subcategory.slug} "
        }
        ret = [item.content for item in self.articlefeed.items()]
        self.assertEqual(ret, [self.article])

        self.articlefeed.query_params = {"subcategory": subcategory2.slug}
        ret = [item.content for item in self.articlefeed.items()]
        self.assertEqual(ret, [article2])

        self.articlefeed.query_params = {"subcategory": subcategory3.slug}
        ret = [item.content for item in self.articlefeed.items()]
        self.assertEqual(ret, [])

        self.articlefeed.query_params = {"subcategory": "invalid"}
        self.assertRaises(Http404, self.articlefeed.items)

        # Filter by tag

        self.articlefeed.query_params = {"tag": self.tag.slug}
        ret = [item.content for item in self.articlefeed.items()]
        self.assertEqual(ret, [article2, self.article])

        self.articlefeed.query_params = {"tag": tag2.slug}
        ret = [item.content for item in self.articlefeed.items()]
        self.assertEqual(ret, [article2])

        self.articlefeed.query_params = {"tag": f" {tag2.slug} "}
        ret = [item.content for item in self.articlefeed.items()]
        self.assertEqual(ret, [article2])

        self.articlefeed.query_params = {"tag": tag3.slug}
        ret = [item.content for item in self.articlefeed.items()]
        self.assertEqual(ret, [])

        self.articlefeed.query_params = {"tag": "invalid"}
        self.assertRaises(Http404, self.articlefeed.items)