Exemplo n.º 1
0
 def setUp(self):
     self.overridden_zds_app = overridden_zds_app
     overridden_zds_app['member']['bot_account'] = ProfileFactory().user.username
     self.licence = LicenceFactory()
     overridden_zds_app['content']['default_licence_pk'] = LicenceFactory().pk
     self.user_author = ProfileFactory().user
     self.user_staff = StaffProfileFactory().user
     self.user_guest = ProfileFactory().user
Exemplo n.º 2
0
    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.participants.add(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)
Exemplo n.º 3
0
    def get_published_content(self,
                              author,
                              user_staff,
                              nb_part=1,
                              nb_chapter=1,
                              nb_extract=1):
        bigtuto = PublishableContentFactory(type='TUTORIAL')

        bigtuto.authors.add(author)
        UserGalleryFactory(gallery=bigtuto.gallery, user=author, mode='W')
        bigtuto.licence = LicenceFactory()
        bigtuto.save()

        # populate the bigtuto
        bigtuto_draft = bigtuto.load_version()
        for i in range(nb_part):
            part = ContainerFactory(parent=bigtuto_draft, db_object=bigtuto)
            for j in range(nb_chapter):
                chapter = ContainerFactory(parent=part, db_object=bigtuto)
                for k in range(nb_extract):
                    ExtractFactory(container=chapter, db_object=bigtuto)

        # connect with author:
        self.client.login(username=author, password='******')

        # ask validation
        self.client.post(reverse('validation:ask',
                                 kwargs={
                                     'pk': bigtuto.pk,
                                     'slug': bigtuto.slug
                                 }), {
                                     'text': 'ask for validation',
                                     'source': '',
                                     'version': bigtuto_draft.current_version
                                 },
                         follow=False)

        # login with staff and publish
        self.client.login(username=user_staff.username, password='******')

        validation = Validation.objects.filter(content=bigtuto).last()

        self.client.post(reverse('validation:reserve',
                                 kwargs={'pk': validation.pk}),
                         {'version': validation.version},
                         follow=False)

        # accept
        self.client.post(reverse('validation:accept',
                                 kwargs={'pk': validation.pk}), {
                                     'text': 'accept validation',
                                     'is_major': True,
                                     'source': ''
                                 },
                         follow=False)
        self.client.logout()

        published = PublishedContent.objects.filter(content=bigtuto).first()
        self.assertIsNotNone(published)
        return published
Exemplo n.º 4
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()
Exemplo n.º 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

        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)
Exemplo n.º 6
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)
Exemplo n.º 7
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)
Exemplo n.º 8
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()
        }
Exemplo n.º 9
0
 def test_move_no_slug_update(self):
     """
     this test comes from issue #3328 (https://github.com/zestedesavoir/zds-site/issues/3328)
     telling it is tricky is kind of euphemism.
     :return:
     """
     LicenceFactory(code='CC BY')
     self.assertEqual(
         self.client.login(username=self.user_author.username,
                           password='******'), True)
     draft_zip_path = join(dirname(__file__),
                           'fake_lasynchrone-et-le-multithread-en-net.zip')
     result = self.client.post(reverse('content:import-new'), {
         'archive': open(draft_zip_path, 'rb'),
         'subcategory': self.subcategory.pk
     },
                               follow=False)
     self.assertEqual(result.status_code, 302)
     tuto = PublishableContent.objects.last()
     published = publish_content(tuto, tuto.load_version(), True)
     tuto.sha_public = tuto.sha_draft
     tuto.public_version = published
     tuto.save()
     extract1 = tuto.load_version().children[0]
     # test moving up smoothly
     result = self.client.post(reverse('content:move-element'), {
         'child_slug': extract1.slug,
         'first_level_slug': '',
         'container_slug': tuto.slug,
         'moving_method': 'down',
         'pk': tuto.pk
     },
                               follow=True)
     self.assertEqual(200, result.status_code)
     self.assertTrue(isdir(tuto.get_repo_path()))
Exemplo n.º 10
0
    def setUp(self):

        # don't build PDF to speed up the tests
        self.user1 = ProfileFactory().user
        self.user2 = ProfileFactory().user

        # create a tutorial
        self.tuto = PublishableContentFactory(type='TUTORIAL')
        self.tuto.authors.add(self.user1)
        UserGalleryFactory(gallery=self.tuto.gallery, user=self.user1, mode='W')
        self.tuto.licence = LicenceFactory()
        self.tuto.subcategory.add(SubCategoryFactory())
        self.tuto.save()
        tuto_draft = self.tuto.load_version()

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

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

        self.assertTrue(self.client.login(username=self.user1.username, password='******'))
Exemplo n.º 11
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()
Exemplo n.º 12
0
    def setUp(self):

        self.overridden_zds_app['member']['bot_account'] = ProfileFactory(
        ).user.username
        self.licence = LicenceFactory()

        self.user_author = ProfileFactory().user
        self.user_staff = StaffProfileFactory().user
        self.user_guest = ProfileFactory().user
Exemplo n.º 13
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()
Exemplo n.º 14
0
    def setUp(self):
        # Create a user
        self.author = ProfileFactory()

        # Create licenses
        self.license_1 = LicenceFactory()
        self.license_2 = LicenceFactory()

        # Create a content
        self.content = PublishableContentFactory(
            author_list=[self.author.user], add_license=False)

        # Get information to be reused in tests
        self.form_url = reverse('content:edit-license',
                                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)
Exemplo n.º 15
0
    def test_update_manifest(self):
        opts = {}
        shutil.copy(
            os.path.join(BASE_DIR, "fixtures", "tuto", "balise_audio", "manifest.json"),
            os.path.join(BASE_DIR, "fixtures", "tuto", "balise_audio", "manifest2.json")
        )
        LicenceFactory(code="CC BY")
        args = [os.path.join(BASE_DIR, "fixtures", "tuto", "balise_audio", "manifest2.json")]
        call_command('upgrade_manifest_to_v2', *args, **opts)
        manifest = open(os.path.join(BASE_DIR, "fixtures", "tuto", "balise_audio", "manifest2.json"), 'r')
        json = json_reader.loads(manifest.read())

        self.assertTrue(u"version" in json)
        self.assertTrue(u"licence" in json)
        self.assertTrue(u"children" in json)
        self.assertEqual(len(json[u"children"]), 3)
        self.assertEqual(json[u"children"][0][u"object"], u"extract")
        os.unlink(args[0])
        args = [os.path.join(BASE_DIR, "fixtures", "tuto", "big_tuto_v1", "manifest2.json")]
        shutil.copy(
            os.path.join(BASE_DIR, "fixtures", "tuto", "big_tuto_v1", "manifest.json"),
            os.path.join(BASE_DIR, "fixtures", "tuto", "big_tuto_v1", "manifest2.json")
        )
        call_command('upgrade_manifest_to_v2', *args, **opts)
        manifest = open(os.path.join(BASE_DIR, "fixtures", "tuto", "big_tuto_v1", "manifest2.json"), 'r')
        json = json_reader.loads(manifest.read())
        os.unlink(args[0])
        self.assertTrue(u"version" in json)
        self.assertTrue(u"licence" in json)
        self.assertTrue(u"children" in json)
        self.assertEqual(len(json[u"children"]), 5)
        self.assertEqual(json[u"children"][0][u"object"], u"container")
        self.assertEqual(len(json[u"children"][0][u"children"]), 3)
        self.assertEqual(len(json[u"children"][0][u"children"][0][u"children"]), 3)
        args = [os.path.join(BASE_DIR, "fixtures", "tuto", "article_v1", "manifest2.json")]
        shutil.copy(
            os.path.join(BASE_DIR, "fixtures", "tuto", "article_v1", "manifest.json"),
            os.path.join(BASE_DIR, "fixtures", "tuto", "article_v1", "manifest2.json")
        )
        call_command('upgrade_manifest_to_v2', *args, **opts)
        manifest = open(os.path.join(BASE_DIR, "fixtures", "tuto", "article_v1", "manifest2.json"), 'r')
        json = json_reader.loads(manifest.read())

        self.assertTrue(u"version" in json)
        self.assertTrue(u"licence" in json)
        self.assertTrue(u"children" in json)
        self.assertEqual(len(json[u"children"]), 1)
        os.unlink(args[0])
Exemplo n.º 16
0
    def get_published_content(self, author, user_staff, nb_part=1, nb_chapter=1, nb_extract=1):
        bigtuto = PublishableContentFactory(type="TUTORIAL")

        bigtuto.authors.add(author)
        UserGalleryFactory(gallery=bigtuto.gallery, user=author, mode="W")
        bigtuto.licence = LicenceFactory()
        bigtuto.save()

        # populate the bigtuto
        bigtuto_draft = bigtuto.load_version()
        for i in range(nb_part):
            part = ContainerFactory(parent=bigtuto_draft, db_object=bigtuto)
            for j in range(nb_chapter):
                chapter = ContainerFactory(parent=part, db_object=bigtuto)
                for k in range(nb_extract):
                    ExtractFactory(container=chapter, db_object=bigtuto)

        # connect with author:
        self.client.login(username=author, password="******")

        # ask validation
        self.client.post(
            reverse("validation:ask", kwargs={"pk": bigtuto.pk, "slug": bigtuto.slug}),
            {"text": "ask for validation", "source": "", "version": bigtuto_draft.current_version},
            follow=False,
        )

        # login with staff and publish
        self.client.login(username=user_staff.username, password="******")

        validation = Validation.objects.filter(content=bigtuto).last()

        self.client.post(
            reverse("validation:reserve", kwargs={"pk": validation.pk}), {"version": validation.version}, follow=False
        )

        # accept
        self.client.post(
            reverse("validation:accept", kwargs={"pk": validation.pk}),
            {"text": "accept validation", "is_major": True, "source": ""},
            follow=False,
        )
        self.client.logout()

        published = PublishedContent.objects.filter(content=bigtuto).first()
        self.assertIsNotNone(published)
        return published
Exemplo n.º 17
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="******")
Exemplo n.º 18
0
    def test_update_manifest(self):
        opts = {}
        path_manifest1 = settings.BASE_DIR / 'fixtures' / 'tuto' / 'balise_audio' / 'manifest.json'
        path_manifest2 = settings.BASE_DIR / 'fixtures' / 'tuto' / 'balise_audio' / 'manifest2.json'
        args = [str(path_manifest2)]
        shutil.copy(path_manifest1, path_manifest2)
        LicenceFactory(code='CC BY')
        call_command('upgrade_manifest_to_v2', *args, **opts)
        manifest = path_manifest2.open('r')
        json = json_handler.loads(manifest.read())

        self.assertTrue('version' in json)
        self.assertTrue('licence' in json)
        self.assertTrue('children' in json)
        self.assertEqual(len(json['children']), 3)
        self.assertEqual(json['children'][0]['object'], 'extract')
        os.unlink(args[0])
        path_manifest1 = settings.BASE_DIR / 'fixtures' / 'tuto' / 'big_tuto_v1' / 'manifest.json'
        path_manifest2 = settings.BASE_DIR / 'fixtures' / 'tuto' / 'big_tuto_v1' / 'manifest2.json'
        args = [str(path_manifest2)]
        shutil.copy(path_manifest1, path_manifest2)
        call_command('upgrade_manifest_to_v2', *args, **opts)
        manifest = path_manifest2.open('r')
        json = json_handler.loads(manifest.read())
        os.unlink(args[0])
        self.assertTrue('version' in json)
        self.assertTrue('licence' in json)
        self.assertTrue('children' in json)
        self.assertEqual(len(json['children']), 5)
        self.assertEqual(json['children'][0]['object'], 'container')
        self.assertEqual(len(json['children'][0]['children']), 3)
        self.assertEqual(len(json['children'][0]['children'][0]['children']),
                         3)
        path_manifest1 = settings.BASE_DIR / 'fixtures' / 'tuto' / 'article_v1' / 'manifest.json'
        path_manifest2 = settings.BASE_DIR / 'fixtures' / 'tuto' / 'article_v1' / 'manifest2.json'
        args = [path_manifest2]
        shutil.copy(path_manifest1, path_manifest2)
        call_command('upgrade_manifest_to_v2', *args, **opts)
        manifest = path_manifest2.open('r')
        json = json_handler.loads(manifest.read())

        self.assertTrue('version' in json)
        self.assertTrue('licence' in json)
        self.assertTrue('children' in json)
        self.assertEqual(len(json['children']), 1)
        os.unlink(args[0])
Exemplo n.º 19
0
    def test_update_manifest(self):
        opts = {}
        path_manifest1 = settings.BASE_DIR / "fixtures" / "tuto" / "balise_audio" / "manifest.json"
        path_manifest2 = settings.BASE_DIR / "fixtures" / "tuto" / "balise_audio" / "manifest2.json"
        args = [str(path_manifest2)]
        shutil.copy(path_manifest1, path_manifest2)
        LicenceFactory(code="CC BY")
        call_command("upgrade_manifest_to_v2", *args, **opts)
        manifest = path_manifest2.open("r")
        json = json_handler.loads(manifest.read())

        self.assertTrue("version" in json)
        self.assertTrue("licence" in json)
        self.assertTrue("children" in json)
        self.assertEqual(len(json["children"]), 3)
        self.assertEqual(json["children"][0]["object"], "extract")
        os.unlink(args[0])
        path_manifest1 = settings.BASE_DIR / "fixtures" / "tuto" / "big_tuto_v1" / "manifest.json"
        path_manifest2 = settings.BASE_DIR / "fixtures" / "tuto" / "big_tuto_v1" / "manifest2.json"
        args = [str(path_manifest2)]
        shutil.copy(path_manifest1, path_manifest2)
        call_command("upgrade_manifest_to_v2", *args, **opts)
        manifest = path_manifest2.open("r")
        json = json_handler.loads(manifest.read())
        os.unlink(args[0])
        self.assertTrue("version" in json)
        self.assertTrue("licence" in json)
        self.assertTrue("children" in json)
        self.assertEqual(len(json["children"]), 5)
        self.assertEqual(json["children"][0]["object"], "container")
        self.assertEqual(len(json["children"][0]["children"]), 3)
        self.assertEqual(len(json["children"][0]["children"][0]["children"]),
                         3)
        path_manifest1 = settings.BASE_DIR / "fixtures" / "tuto" / "article_v1" / "manifest.json"
        path_manifest2 = settings.BASE_DIR / "fixtures" / "tuto" / "article_v1" / "manifest2.json"
        args = [path_manifest2]
        shutil.copy(path_manifest1, path_manifest2)
        call_command("upgrade_manifest_to_v2", *args, **opts)
        manifest = path_manifest2.open("r")
        json = json_handler.loads(manifest.read())

        self.assertTrue("version" in json)
        self.assertTrue("licence" in json)
        self.assertTrue("children" in json)
        self.assertEqual(len(json["children"]), 1)
        os.unlink(args[0])
Exemplo n.º 20
0
 def test_publication_and_attributes_consistency(self):
     pubdate = datetime.now() - timedelta(days=1)
     article = PublishedContentFactory(type="ARTICLE",
                                       author_list=[self.user_author])
     public_version = article.public_version
     public_version.publication_date = pubdate
     public_version.save()
     # everything must come from database to have good datetime comparison
     article = PublishableContent.objects.get(pk=article.pk)
     article.public_version.load_public_version()
     old_date = article.public_version.publication_date
     old_title = article.public_version.title()
     old_description = article.public_version.description()
     article.licence = LicenceFactory()
     article.save()
     self.assertEqual(
         self.client.login(username=self.user_author.username,
                           password="******"), True)
     self.client.post(
         reverse("content:edit", args=[article.pk, article.slug]),
         {
             "title": old_title + "bla",
             "description": old_description + "bla",
             "type": "ARTICLE",
             "licence": article.licence.pk,
             "subcategory": SubCategoryFactory().pk,
             "last_hash": article.sha_draft,
         },
     )
     article = PublishableContent.objects.prefetch_related(
         "public_version").get(pk=article.pk)
     article.public_version.load_public_version()
     self.assertEqual(old_title, article.public_version.title())
     self.assertEqual(old_description, article.public_version.description())
     self.assertEqual(old_date, article.public_version.publication_date)
     publish_content(article, article.load_version(), False)
     article = PublishableContent.objects.get(pk=article.pk)
     article.public_version.load_public_version()
     self.assertEqual(old_date, article.public_version.publication_date)
     self.assertNotEqual(old_date, article.public_version.update_date)
Exemplo n.º 21
0
    def setUp(self):
        # Create users
        self.author = ProfileFactory().user
        self.staff = StaffProfileFactory().user
        self.outsider = ProfileFactory().user

        # Create a license
        self.licence = LicenceFactory()

        # Create a content
        self.content = PublishableContentFactory(author_list=[self.author])

        # Get information to be reused in tests
        self.form_url = reverse('content:edit-license',
                                kwargs={'pk': self.content.pk})
        self.form_data = {
            'license': self.licence.pk,
            'update_preferred_license': False
        }
        self.content_data = {'pk': self.content.pk, 'slug': self.content.slug}
        self.content_url = reverse('content:view', kwargs=self.content_data)
        self.login_url = reverse('member-login') + '?next=' + self.form_url
Exemplo n.º 22
0
    def setUp(self):
        # Create users
        self.author = ProfileFactory().user
        self.staff = StaffProfileFactory().user
        self.outsider = ProfileFactory().user

        # Create a license
        self.licence = LicenceFactory()

        # Create a content
        self.content = PublishableContentFactory(author_list=[self.author])

        # Get information to be reused in tests
        self.form_url = reverse("content:edit-license",
                                kwargs={"pk": self.content.pk})
        self.form_data = {
            "license": self.licence.pk,
            "update_preferred_license": False
        }
        self.content_data = {"pk": self.content.pk, "slug": self.content.slug}
        self.content_url = reverse("content:view", kwargs=self.content_data)
        self.login_url = reverse("member-login") + "?next=" + self.form_url
Exemplo n.º 23
0
 def test_publication_and_attributes_consistency(self):
     pubdate = datetime.now() - timedelta(days=1)
     article = PublishedContentFactory(type='ARTICLE',
                                       author_list=[self.user_author])
     public_version = article.public_version
     public_version.publication_date = pubdate
     public_version.save()
     # everything must come from database to have good datetime comparison
     article = PublishableContent.objects.get(pk=article.pk)
     article.public_version.load_public_version()
     old_date = article.public_version.publication_date
     old_title = article.public_version.title()
     old_description = article.public_version.description()
     article.licence = LicenceFactory()
     article.save()
     self.assertEqual(
         self.client.login(username=self.user_author.username,
                           password='******'), True)
     self.client.post(
         reverse('content:edit', args=[article.pk, article.slug]), {
             'title': old_title + 'bla',
             'description': old_description + 'bla',
             'type': 'ARTICLE',
             'licence': article.licence.pk,
             'subcategory': SubCategoryFactory().pk,
             'last_hash': article.sha_draft
         })
     article = PublishableContent.objects.prefetch_related(
         'public_version').get(pk=article.pk)
     article.public_version.load_public_version()
     self.assertEqual(old_title, article.public_version.title())
     self.assertEqual(old_description, article.public_version.description())
     self.assertEqual(old_date, article.public_version.publication_date)
     publish_content(article, article.load_version(), False)
     article = PublishableContent.objects.get(pk=article.pk)
     article.public_version.load_public_version()
     self.assertEqual(old_date, article.public_version.publication_date)
     self.assertNotEqual(old_date, article.public_version.update_date)
Exemplo n.º 24
0
    def setUp(self):
        # Create a user
        self.author = ProfileFactory()

        # Create a license
        self.license = LicenceFactory()

        # Create a content
        self.content = PublishableContentFactory(
            author_list=[self.author.user], add_license=False)

        # Get information to be reused in tests
        self.form_url = reverse('content:edit-license',
                                kwargs={'pk': self.content.pk})
        self.error_messages = EditContentLicenseForm.declared_fields[
            'license'].error_messages
        self.success_message_license = EditContentLicense.success_message_license
        self.success_message_profile_update = EditContentLicense.success_message_profile_update

        # 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)
Exemplo n.º 25
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 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()
Exemplo n.º 26
0
 def setUp(self):
     self.author = ProfileFactory()
     self.staff = StaffProfileFactory()
     self.licence = LicenceFactory()
     self.subcategory = SubCategoryFactory()
Exemplo n.º 27
0
    def setUp(self):
        settings.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=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 a tutorial
        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()

        # fill it with one part, containing one chapter, containing one extract
        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)

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

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

        self.tutofeed = LastTutorialsFeedRSS()
Exemplo n.º 28
0
    def test_update_manifest(self):
        opts = {}
        shutil.copy(
            os.path.join(BASE_DIR, 'fixtures', 'tuto', 'balise_audio',
                         'manifest.json'),
            os.path.join(BASE_DIR, 'fixtures', 'tuto', 'balise_audio',
                         'manifest2.json'))
        LicenceFactory(code='CC BY')
        args = [
            os.path.join(BASE_DIR, 'fixtures', 'tuto', 'balise_audio',
                         'manifest2.json')
        ]
        call_command('upgrade_manifest_to_v2', *args, **opts)
        manifest = open(
            os.path.join(BASE_DIR, 'fixtures', 'tuto', 'balise_audio',
                         'manifest2.json'), 'r')
        json = json_handler.loads(manifest.read())

        self.assertTrue('version' in json)
        self.assertTrue('licence' in json)
        self.assertTrue('children' in json)
        self.assertEqual(len(json['children']), 3)
        self.assertEqual(json['children'][0]['object'], 'extract')
        os.unlink(args[0])
        args = [
            os.path.join(BASE_DIR, 'fixtures', 'tuto', 'big_tuto_v1',
                         'manifest2.json')
        ]
        shutil.copy(
            os.path.join(BASE_DIR, 'fixtures', 'tuto', 'big_tuto_v1',
                         'manifest.json'),
            os.path.join(BASE_DIR, 'fixtures', 'tuto', 'big_tuto_v1',
                         'manifest2.json'))
        call_command('upgrade_manifest_to_v2', *args, **opts)
        manifest = open(
            os.path.join(BASE_DIR, 'fixtures', 'tuto', 'big_tuto_v1',
                         'manifest2.json'), 'r')
        json = json_handler.loads(manifest.read())
        os.unlink(args[0])
        self.assertTrue('version' in json)
        self.assertTrue('licence' in json)
        self.assertTrue('children' in json)
        self.assertEqual(len(json['children']), 5)
        self.assertEqual(json['children'][0]['object'], 'container')
        self.assertEqual(len(json['children'][0]['children']), 3)
        self.assertEqual(len(json['children'][0]['children'][0]['children']),
                         3)
        args = [
            os.path.join(BASE_DIR, 'fixtures', 'tuto', 'article_v1',
                         'manifest2.json')
        ]
        shutil.copy(
            os.path.join(BASE_DIR, 'fixtures', 'tuto', 'article_v1',
                         'manifest.json'),
            os.path.join(BASE_DIR, 'fixtures', 'tuto', 'article_v1',
                         'manifest2.json'))
        call_command('upgrade_manifest_to_v2', *args, **opts)
        manifest = open(
            os.path.join(BASE_DIR, 'fixtures', 'tuto', 'article_v1',
                         'manifest2.json'), 'r')
        json = json_handler.loads(manifest.read())

        self.assertTrue('version' in json)
        self.assertTrue('licence' in json)
        self.assertTrue('children' in json)
        self.assertEqual(len(json['children']), 1)
        os.unlink(args[0])