Exemple #1
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()
Exemple #2
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

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

        self.user_author = ProfileFactory().user
        self.user_staff = StaffProfileFactory().user
        self.user_guest = ProfileFactory().user
        self.content = PublishableContentFactory(
            author_list=[self.user_author], light=False)
        self.part_published = ContainerFactory(
            db_object=self.content,
            light=False,
            parent=self.content.load_version())
        self.ignored_part = ContainerFactory(
            db_object=self.content,
            light=False,
            parent=self.content.load_version())
        ExtractFactory(db_object=self.content,
                       container=self.part_published,
                       light=False)
        ExtractFactory(db_object=self.content,
                       container=self.ignored_part,
                       light=False)
Exemple #3
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()
Exemple #4
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()
Exemple #5
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()
Exemple #6
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))
Exemple #7
0
    def test_failure_too_long_url(self):
        staff = StaffProfileFactory()
        login_check = self.client.login(username=staff.user.username,
                                        password='******')
        self.assertTrue(login_check)

        self.assertEqual(0, FeaturedResource.objects.all().count())
        response = self.client.post(reverse('featured-resource-create'), {
            'title': 'title',
            'type': 'type',
            'image_url': stringof2001chars,
            'url': 'http://test.com',
            'authors': staff.user.username
        },
                                    follow=True)

        self.assertEqual(200, response.status_code)
        self.assertEqual(0, FeaturedResource.objects.all().count())

        response = self.client.post(reverse('featured-resource-create'), {
            'title': 'title',
            'type': 'type',
            'image_url': 'http://test.com/image.png',
            'url': stringof2001chars,
            'authors': staff.user.username
        },
                                    follow=True)

        self.assertEqual(200, response.status_code)
        self.assertEqual(0, FeaturedResource.objects.all().count())
Exemple #8
0
    def common_test_mark_as_potential_spam_content(self, content_type):
        content_author = ProfileFactory()
        comment_author = ProfileFactory()
        staff = StaffProfileFactory()

        content: PublishableContent = PublishedContentFactory(
            author_list=[content_author.user], type=content_type)

        self.login(comment_author)
        self.client.post(
            reverse("content:add-reaction") + f"?pk={content.pk}",
            {
                "text": "Pi is not so humble",
                "last_note": "0"
            },
            follow=True,
        )
        content.refresh_from_db()
        reaction = content.last_note

        self.common_test_mark_as_potential_spam(
            url_comments_list=content.get_absolute_url_online(),
            url_comment_edit=reverse("content:update-reaction") +
            f"?message={reaction.pk}&pk={content.pk}",
            comment=reaction,
            author=comment_author,
            staff=staff,
        )
Exemple #9
0
    def test_create_only_one_message_in_system(self):
        staff = StaffProfileFactory()
        login_check = self.client.login(
            username=staff.user.username,
            password='******'
        )
        self.assertTrue(login_check)

        response = self.client.post(
            reverse('featured-message-create'),
            {
                'message': 'message',
                'url': 'url',
            },
            follow=True
        )

        self.assertEqual(200, response.status_code)
        self.assertEqual(1, FeaturedMessage.objects.count())

        response = self.client.post(
            reverse('featured-message-create'),
            {
                'message': 'message',
                'url': 'url',
            },
            follow=True
        )

        self.assertEqual(200, response.status_code)
        self.assertEqual(1, FeaturedMessage.objects.count())
Exemple #10
0
    def test_hide_post_mark_notification_as_read(self):
        """
        Ensure a notification gets deleted when the corresponding post is hidden.
        """
        topic = TopicFactory(forum=self.forum11, author=self.user1)
        PostFactory(topic=topic, author=self.user1, position=1)
        PostFactory(topic=topic, author=self.user2, position=2)
        PostFactory(topic=topic, author=ProfileFactory().user, position=3)

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

        # hide last post
        data = {'delete_message': ''}
        self.assertTrue(
            self.client.login(username=StaffProfileFactory().user.username,
                              password='******'))
        response = self.client.post(
            reverse('post-edit') + '?message={}'.format(topic.last_message.pk),
            data,
            follow=False)
        self.assertEqual(302, response.status_code)

        notifications = Notification.objects.filter(
            object_id=topic.last_message.pk, is_read=True).all()
        self.assertEqual(1, len(notifications))
Exemple #11
0
    def test_failure_too_long_url(self):
        staff = StaffProfileFactory()
        self.client.force_login(staff.user)

        self.assertEqual(0, FeaturedResource.objects.all().count())
        response = self.client.post(
            reverse("featured-resource-create"),
            {
                "title": "title",
                "type": "type",
                "image_url": stringof2001chars,
                "url": "http://test.com",
                "authors": staff.user.username,
            },
            follow=True,
        )

        self.assertEqual(200, response.status_code)
        self.assertEqual(0, FeaturedResource.objects.all().count())

        response = self.client.post(
            reverse("featured-resource-create"),
            {
                "title": "title",
                "type": "type",
                "image_url": "http://test.com/image.png",
                "url": stringof2001chars,
                "authors": staff.user.username,
            },
            follow=True,
        )

        self.assertEqual(200, response.status_code)
        self.assertEqual(0, FeaturedResource.objects.all().count())
Exemple #12
0
    def test_signal_and_solve_alert_empty_message(self):
        """To test when a member signal a post and staff solve it."""
        user1 = ProfileFactory().user
        topic1 = TopicFactory(forum=self.forum11, author=self.user)
        PostFactory(topic=topic1, author=self.user, position=1)
        post2 = PostFactory(topic=topic1, author=user1, position=2)
        PostFactory(topic=topic1, author=user1, position=3)

        result = self.client.post(reverse('zds.forum.views.edit_post') +
                                  '?message={0}'.format(post2.pk), {
                                      'signal_text': u'Troll',
                                      'signal_message': 'confirmer'
                                  },
                                  follow=False)

        alert = Alert.objects.get(comment=post2.pk)
        # login as staff
        staff1 = StaffProfileFactory().user
        self.assertEqual(
            self.client.login(username=staff1.username, password='******'),
            True)
        # try again as staff
        result = self.client.post(reverse('zds.forum.views.solve_alert'), {
            'alert_pk': alert.pk,
        },
                                  follow=False)
        self.assertEqual(result.status_code, 302)
        self.assertEqual(Alert.objects.all().count(), 0)
Exemple #13
0
    def setUp(self):

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

        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.user_author = ProfileFactory().user
        self.staff = StaffProfileFactory().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.save()

        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)
Exemple #14
0
    def test_move_topic_from_forum_followed_to_forum_followed_too(self):
        NewTopicSubscription.objects.toggle_follow(self.forum11, self.user1)
        NewTopicSubscription.objects.toggle_follow(self.forum12, self.user1)

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

        # Move the topic to another forum.
        self.client.logout()
        staff = StaffProfileFactory()
        self.assertTrue(self.client.login(username=staff.user.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)

        topic = Topic.objects.get(pk=topic.pk)
        self.assertEqual(self.forum12, topic.forum)
        self.assertEqual(1, len(Notification.objects.filter(object_id=topic.pk, is_read=False, is_dead=False).all()))

        self.client.logout()
        self.assertTrue(self.client.login(username=self.user1.username, password='******'))
        response = self.client.get(reverse('topic-posts-list', args=[topic.pk, topic.slug()]))
        self.assertEqual(200, response.status_code)

        self.assertEqual(1, len(Notification.objects.filter(object_id=topic.pk, is_read=True, is_dead=False).all()))
Exemple #15
0
    def setUp(self):
        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.user_author = ProfileFactory().user
        self.staff = StaffProfileFactory().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.save()

        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)
Exemple #16
0
    def setUp(self):
        self.mas = ProfileFactory().user
        self.overridden_zds_app["member"]["bot_account"] = self.mas.username

        self.licence = LicenceFactory()

        self.user_author = ProfileFactory().user
        self.staff = StaffProfileFactory().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.save()

        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.old_registry = {key: value for key, value in PublicatorRegistry.get_all_registered()}

        class TestPdfPublicator(Publicator):
            def publish(self, md_file_path, base_name, **kwargs):
                with Path(base_name + ".pdf").open("w") as f:
                    f.write("bla")
                shutil.copy2(str(Path(base_name + ".pdf")), str(Path(md_file_path.replace("__building", "")).parent))

        PublicatorRegistry.registry["pdf"] = TestPdfPublicator()
Exemple #17
0
    def test_create_only_one_message_in_system(self):
        staff = StaffProfileFactory()
        login_check = self.client.login(username=staff.user.username, password="******")
        self.assertTrue(login_check)

        response = self.client.post(
            reverse("featured-message-create"),
            {
                "message": "message",
                "url": "http://test.com",
            },
            follow=True,
        )

        self.assertEqual(200, response.status_code)
        self.assertEqual(1, FeaturedMessage.objects.count())

        response = self.client.post(
            reverse("featured-message-create"),
            {
                "message": "message",
                "url": "http://test.com",
            },
            follow=True,
        )

        self.assertEqual(200, response.status_code)
        self.assertEqual(1, FeaturedMessage.objects.count())
Exemple #18
0
 def test_success_initial_content(self):
     author = ProfileFactory().user
     author2 = ProfileFactory().user
     tutorial = PublishedContentFactory(author_list=[author, author2])
     gallery = GalleryFactory()
     image = ImageFactory(gallery=gallery)
     tutorial.image = image
     tutorial.save()
     staff = StaffProfileFactory()
     login_check = self.client.login(username=staff.user.username,
                                     password="******")
     self.assertTrue(login_check)
     response = self.client.get("{}{}".format(
         reverse("featured-resource-create"),
         "?content_type=published_content&content_id={}".format(
             tutorial.pk)))
     initial_dict = response.context["form"].initial
     self.assertEqual(initial_dict["title"], tutorial.title)
     self.assertEqual(initial_dict["authors"],
                      "{}, {}".format(author, author2))
     self.assertEqual(initial_dict["type"], _("Un tutoriel"))
     self.assertEqual(
         initial_dict["url"],
         "http://testserver{}".format(tutorial.get_absolute_url_online()))
     self.assertEqual(
         initial_dict["image_url"],
         "http://testserver{}".format(image.physical["featured"].url))
Exemple #19
0
    def test_hide_post_mark_notification_as_read(self):
        """
        Ensure a notification gets deleted when the corresponding post is hidden.
        """
        topic = TopicFactory(forum=self.forum11, author=self.user1)
        PostFactory(topic=topic, author=self.user1, position=1)
        PostFactory(topic=topic, author=self.user2, position=2)
        PostFactory(topic=topic, author=ProfileFactory().user, position=3)

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

        # hide last post
        data = {"delete_message": ""}
        self.client.force_login(StaffProfileFactory().user)
        response = self.client.post(reverse("post-edit") +
                                    f"?message={topic.last_message.pk}",
                                    data,
                                    follow=False)
        self.assertEqual(302, response.status_code)

        notifications = Notification.objects.filter(
            object_id=topic.last_message.pk, is_read=True).all()
        self.assertEqual(1, len(notifications))
Exemple #20
0
    def test_failed_bot_sanctions(self):

        staff = StaffProfileFactory()
        login_check = self.client.login(username=staff.user.username,
                                        password='******')
        self.assertEqual(login_check, True)

        bot_profile = ProfileFactory()
        bot_profile.user.groups.add(self.bot)
        bot_profile.user.save()

        # Test: LS
        result = self.client.post(
            reverse('member-modify-profile',
                    kwargs={'user_pk': bot_profile.user.id}), {
                        'ls': '',
                        'ls-text': 'Texte de test pour LS'
                    },
            follow=False)
        user = Profile.objects.get(
            id=bot_profile.id)  # Refresh profile from DB
        self.assertEqual(result.status_code, 403)
        self.assertTrue(user.can_write)
        self.assertTrue(user.can_read)
        self.assertIsNone(user.end_ban_write)
        self.assertIsNone(user.end_ban_read)
Exemple #21
0
    def test_create_only_one_message_in_system(self):
        staff = StaffProfileFactory()
        self.client.force_login(staff.user)

        response = self.client.post(
            reverse("featured-message-create"),
            {
                "message": "message",
                "url": "http://test.com",
            },
            follow=True,
        )

        self.assertEqual(200, response.status_code)
        self.assertEqual(1, FeaturedMessage.objects.count())

        response = self.client.post(
            reverse("featured-message-create"),
            {
                "message": "message",
                "url": "http://test.com",
            },
            follow=True,
        )

        self.assertEqual(200, response.status_code)
        self.assertEqual(1, FeaturedMessage.objects.count())
Exemple #22
0
    def setUp(self):
        self.overridden_zds_app = overridden_zds_app
        self.mas = ProfileFactory().user
        overridden_zds_app['member']['bot_account'] = self.mas.username

        self.licence = LicenceFactory()

        self.user_author = ProfileFactory().user
        self.staff = StaffProfileFactory().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.save()

        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.old_registry = {
            key: value
            for key, value in PublicatorRegistery.get_all_registered()
        }
Exemple #23
0
    def test_success_list(self):
        staff = StaffProfileFactory()
        self.client.force_login(staff.user)

        response = self.client.get(reverse("featured-resource-requests"))

        self.assertEqual(200, response.status_code)
    def setUp(self):
        self.licence = LicenceFactory()
        self.subcategory = SubCategoryFactory()

        self.author = ProfileFactory()
        self.user = ProfileFactory()
        self.staff = StaffProfileFactory()

        self.tuto = PublishableContentFactory(type="TUTORIAL")
        self.tuto.authors.add(self.author.user)
        self.tuto.licence = self.licence
        self.tuto.subcategory.add(self.subcategory)
        self.tuto.save()

        self.validation = Validation(
            content=self.tuto,
            version=self.tuto.sha_draft,
            comment_authors="bla",
            date_proposition=datetime.now(),
        )
        self.validation.save()

        self.topic = send_mp(author=self.author.user, users=[], title="Title", text="Testing", subtitle="", leave=False)
        self.topic.add_participant(self.user.user)
        send_message_mp(self.user.user, self.topic, "Testing")

        # humane_delta test
        periods = ((1, 0), (2, 1), (3, 7), (4, 30), (5, 360))
        cont = dict()
        cont["date_today"] = periods[0][0]
        cont["date_yesterday"] = periods[1][0]
        cont["date_last_week"] = periods[2][0]
        cont["date_last_month"] = periods[3][0]
        cont["date_last_year"] = periods[4][0]
        self.context = Context(cont)
Exemple #25
0
 def test_success_initial_content(self):
     author = ProfileFactory().user
     author2 = ProfileFactory().user
     tutorial = PublishedContentFactory(author_list=[author, author2])
     gallery = GalleryFactory()
     image = ImageFactory(gallery=gallery)
     tutorial.image = image
     tutorial.save()
     staff = StaffProfileFactory()
     login_check = self.client.login(username=staff.user.username,
                                     password='******')
     self.assertTrue(login_check)
     response = self.client.get('{}{}'.format(
         reverse('featured-resource-create'),
         '?content_type=published_content&content_id={}'.format(
             tutorial.pk)))
     initial_dict = response.context['form'].initial
     self.assertEqual(initial_dict['title'], tutorial.title)
     self.assertEqual(initial_dict['authors'],
                      '{}, {}'.format(author, author2))
     self.assertEqual(initial_dict['type'], _('Un tutoriel'))
     self.assertEqual(
         initial_dict['url'],
         'http://testserver{}'.format(tutorial.get_absolute_url_online()))
     self.assertEqual(
         initial_dict['image_url'],
         'http://testserver{}'.format(image.physical['featured'].url))
Exemple #26
0
    def test_move_topic(self):
        """Test topic move."""
        user1 = ProfileFactory().user
        topic1 = TopicFactory(forum=self.forum11, author=self.user)
        PostFactory(topic=topic1, author=self.user, position=1)
        PostFactory(topic=topic1, author=user1, position=2)
        PostFactory(topic=topic1, author=self.user, position=3)

        # not staff member can't move topic
        result = self.client.post(reverse('zds.forum.views.move_topic') +
                                  '?sujet={0}'.format(topic1.pk),
                                  {'forum': self.forum12},
                                  follow=False)

        self.assertEqual(result.status_code, 403)

        # test with staff
        staff1 = StaffProfileFactory().user
        self.assertEqual(
            self.client.login(username=staff1.username, password='******'),
            True)

        result = self.client.post(reverse('zds.forum.views.move_topic') +
                                  '?sujet={0}'.format(topic1.pk),
                                  {'forum': self.forum12.pk},
                                  follow=False)

        self.assertEqual(result.status_code, 302)

        # check value
        self.assertEqual(
            Topic.objects.get(pk=topic1.pk).forum.pk, self.forum12.pk)
Exemple #27
0
 def test_forbidden_email_provider_user_form(self):
     moderator = StaffProfileFactory().user
     if not BannedEmailProvider.objects.filter(provider="yopmail.com").exists():
         BannedEmailProvider.objects.create(provider="yopmail.com", moderator=moderator)
     data = {"username": self.user1.user.username, "email": "*****@*****.**"}
     form = ChangeUserForm(data=data, user=self.user1.user)
     self.assertFalse(form.is_valid())
Exemple #28
0
def load_staff(cli, size, fake, root):
    """
    Load staff
    """
    nb_staffs = size * 3
    cli.stdout.write(u"Nombres de staffs à créer : {}".format(nb_staffs))
    tps1 = time.time()
    cpt = 1
    for i in range(0, nb_staffs):
        while Profile.objects.filter(user__username="******".format(root, cpt)).count() > 0:
            cpt += 1
        profile = StaffProfileFactory(user__username="******".format(root, cpt))
        profile.user.first_name = fake.first_name()
        profile.user.last_name = fake.last_name()
        profile.user.email = fake.free_email()
        profile.user.save()
        profile.site = fake.url()
        profile.biography = fake.paragraph()
        profile.sign = fake.text(max_nb_chars=80)
        profile.last_ip_address = fake.ipv6()
        profile.save()
        cpt += 1
        sys.stdout.write(" Staff {}/{}  \r".format(i + 1, nb_staffs))
        sys.stdout.flush()
    tps2 = time.time()
    cli.stdout.write(u"\nFait en {} sec".format(tps2 - tps1))
Exemple #29
0
    def setUp(self):

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

        self.user_author = ProfileFactory().user
        self.user = ProfileFactory().user
        self.staff = StaffProfileFactory().user

        self.licence = LicenceFactory()

        self.article = ArticleFactory()
        self.article.authors.add(self.user_author)
        self.article.licence = self.licence
        self.article.save()

        # connect with user
        login_check = self.client.login(username=self.user_author.username,
                                        password='******')
        self.assertEqual(login_check, True)

        # ask public article
        pub = self.client.post(reverse('zds.article.views.modify'), {
            'article': self.article.pk,
            'comment': u'Valides moi ce bébé',
            'pending': 'Demander validation',
            'version': self.article.sha_draft,
            'is_major': True
        },
                               follow=False)
        self.assertEqual(pub.status_code, 302)
        self.assertEqual(Validation.objects.count(), 1)

        login_check = self.client.login(username=self.staff.username,
                                        password='******')
        self.assertEqual(login_check, True)

        # reserve tutorial
        validation = Validation.objects.get(article__pk=self.article.pk)
        pub = self.client.post(reverse('zds.article.views.reservation',
                                       args=[validation.pk]),
                               follow=False)
        self.assertEqual(pub.status_code, 302)

        # publish article
        pub = self.client.post(reverse('zds.article.views.modify'), {
            'article': self.article.pk,
            'comment-v': u'Cet article est excellent',
            'valid-article': 'Demander validation',
            'is_major': True
        },
                               follow=False)
        self.assertEqual(pub.status_code, 302)
        self.assertEquals(len(mail.outbox), 1)
        mail.outbox = []

        self.articlefeed = LastArticlesFeedRSS()
Exemple #30
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)