コード例 #1
0
ファイル: tests_models.py プロジェクト: Aer-o/zds-site
class GalleryTest(TestCase):

    def setUp(self):
        self.profile = ProfileFactory()
        self.gallery = GalleryFactory()
        self.image1 = ImageFactory(gallery=self.gallery)
        self.image2 = ImageFactory(gallery=self.gallery)
        self.user_gallery = UserGalleryFactory(user=self.profile.user, gallery=self.gallery)

    def tearDown(self):
        self.image1.delete()
        self.image2.delete()
        self.user_gallery.delete()
        self.gallery.delete()

    def test_unicode(self):
        self.assertEqual(self.gallery.title, self.gallery.__unicode__())

    def test_get_absolute_url(self):
        absolute_url = reverse('zds.gallery.views.gallery_details',
                args=[self.gallery.pk, self.gallery.slug])
        self.assertEqual(absolute_url, self.gallery.get_absolute_url())

    def test_get_users(self):
        self.assertEqual(1, len(self.gallery.get_users()))
        self.assertEqual(self.user_gallery, self.gallery.get_users()[0])

    def test_get_images(self):
        self.assertEqual(2, len(self.gallery.get_images()))
        self.assertEqual(self.image1, self.gallery.get_images()[0])
        self.assertEqual(self.image2, self.gallery.get_images()[1])

    def test_get_last_image(self):
        self.assertEqual(self.image2, self.gallery.get_last_image())
コード例 #2
0
 def setUp(self):
     self.gallery = GalleryFactory()
     self.profile1 = ProfileFactory()
     self.profile2 = ProfileFactory()
     self.profile3 = ProfileFactory()
     self.user_gallery1 = UserGalleryFactory(user=self.profile1.user,
                                             gallery=self.gallery,
                                             mode='W')
     self.user_gallery2 = UserGalleryFactory(user=self.profile2.user,
                                             gallery=self.gallery,
                                             mode='R')
コード例 #3
0
ファイル: tests_views.py プロジェクト: Vultik/zds-site
 def setUp(self):
     self.gallery = GalleryFactory()
     self.image = ImageFactory(gallery=self.gallery)
     self.profile1 = ProfileFactory()
     self.profile2 = ProfileFactory()
     self.profile3 = ProfileFactory()
     self.user_gallery1 = UserGalleryFactory(user=self.profile1.user,
                                             gallery=self.gallery,
                                             mode="W")
     self.user_gallery2 = UserGalleryFactory(user=self.profile2.user,
                                             gallery=self.gallery,
                                             mode="R")
コード例 #4
0
    def test_success_gallery_details_permission_authorized(self):
        gallery = GalleryFactory()
        UserGalleryFactory(gallery=gallery, user=self.profile1.user)
        UserGalleryFactory(gallery=gallery, user=self.profile2.user)

        login_check = self.client.login(username=self.profile2.user.username,
                                        password='******')
        self.assertTrue(login_check)

        response = self.client.get(
            reverse('gallery-details', args=[gallery.pk, gallery.slug]))
        self.assertEqual(200, response.status_code)
コード例 #5
0
ファイル: tests_views.py プロジェクト: maynalysa/zds-site
 def setUp(self):
     self.profile1 = ProfileFactory()
     self.profile2 = ProfileFactory()
     self.profile3 = ProfileFactory()
     self.gallery1 = GalleryFactory()
     self.gallery2 = GalleryFactory()
     self.image1 = ImageFactory(gallery=self.gallery1)
     self.image2 = ImageFactory(gallery=self.gallery1)
     self.image3 = ImageFactory(gallery=self.gallery2)
     self.user_gallery1 = UserGalleryFactory(user=self.profile1.user, gallery=self.gallery1)
     self.user_gallery2 = UserGalleryFactory(user=self.profile1.user, gallery=self.gallery2)
     self.user_gallery3 = UserGalleryFactory(user=self.profile2.user, gallery=self.gallery1, mode='R')
コード例 #6
0
ファイル: tests_models.py プロジェクト: josephcab/zds-site
class GalleryTest(TestCase):

    def setUp(self):
        self.profile = ProfileFactory()
        self.gallery = GalleryFactory()
        self.image1 = ImageFactory(gallery=self.gallery)
        self.image2 = ImageFactory(gallery=self.gallery)
        self.user_gallery = UserGalleryFactory(user=self.profile.user, gallery=self.gallery)

    def tearDown(self):
        self.image1.delete()
        self.image2.delete()
        self.user_gallery.delete()
        self.gallery.delete()

    def test_get_absolute_url(self):
        absolute_url = reverse('gallery-details',
                               args=[self.gallery.pk, self.gallery.slug])
        self.assertEqual(absolute_url, self.gallery.get_absolute_url())

    def test_get_linked_users(self):
        self.assertEqual(1, len(self.gallery.get_linked_users()))
        self.assertEqual(self.user_gallery, self.gallery.get_linked_users()[0])

    def test_get_images(self):
        self.assertEqual(2, len(self.gallery.get_images()))
        self.assertEqual(self.image1, self.gallery.get_images()[0])
        self.assertEqual(self.image2, self.gallery.get_images()[1])

    def test_get_last_image(self):
        self.assertEqual(self.image2, self.gallery.get_last_image())

    def test_delete_empty_gallery(self):
        test_gallery = GalleryFactory()
        path = test_gallery.get_gallery_path()
        test_gallery.delete()
        self.assertFalse(os.path.isdir(path))

    def test_delete_gallery_with_image(self):
        test_gallery = GalleryFactory()
        test_image = ImageFactory(gallery=test_gallery)

        path_gallery = test_gallery.get_gallery_path()
        self.assertTrue(os.path.isdir(path_gallery))
        path_image = test_image.physical.path
        self.assertTrue(os.path.isfile(path_image))

        # Destroy the gallery and the image
        test_gallery.delete()
        self.assertFalse(os.path.isdir(path_gallery))
        self.assertFalse(os.path.isfile(path_image))
コード例 #7
0
class GalleryTest(TestCase):
    def setUp(self):
        self.profile = ProfileFactory()
        self.gallery = GalleryFactory()
        self.image1 = ImageFactory(gallery=self.gallery)
        self.image2 = ImageFactory(gallery=self.gallery)
        self.user_gallery = UserGalleryFactory(user=self.profile.user,
                                               gallery=self.gallery)

    def tearDown(self):
        self.image1.delete()
        self.image2.delete()
        self.user_gallery.delete()
        self.gallery.delete()

    def test_get_absolute_url(self):
        absolute_url = reverse('gallery-details',
                               args=[self.gallery.pk, self.gallery.slug])
        self.assertEqual(absolute_url, self.gallery.get_absolute_url())

    def test_get_linked_users(self):
        self.assertEqual(1, len(self.gallery.get_linked_users()))
        self.assertEqual(self.user_gallery, self.gallery.get_linked_users()[0])

    def test_get_images(self):
        self.assertEqual(2, len(self.gallery.get_images()))
        self.assertEqual(self.image1, self.gallery.get_images()[0])
        self.assertEqual(self.image2, self.gallery.get_images()[1])

    def test_get_last_image(self):
        self.assertEqual(self.image2, self.gallery.get_last_image())

    def test_delete_empty_gallery(self):
        test_gallery = GalleryFactory()
        path = test_gallery.get_gallery_path()
        test_gallery.delete()
        self.assertFalse(os.path.isdir(path))

    def test_delete_gallery_with_image(self):
        test_gallery = GalleryFactory()
        test_image = ImageFactory(gallery=test_gallery)

        path_gallery = test_gallery.get_gallery_path()
        self.assertTrue(os.path.isdir(path_gallery))
        path_image = test_image.physical.path
        self.assertTrue(os.path.isfile(path_image))

        # Destroy the gallery and the image
        test_gallery.delete()
        self.assertFalse(os.path.isdir(path_gallery))
        self.assertFalse(os.path.isfile(path_image))
コード例 #8
0
ファイル: tests_models.py プロジェクト: josephcab/zds-site
class UserGalleryTest(TestCase):

    def setUp(self):
        self.profile = ProfileFactory()
        self.gallery = GalleryFactory()
        self.image1 = ImageFactory(gallery=self.gallery)
        self.image2 = ImageFactory(gallery=self.gallery)
        self.user_gallery = UserGalleryFactory(user=self.profile.user, gallery=self.gallery)

    def tearDown(self):
        self.image1.delete()
        self.image2.delete()
        self.user_gallery.delete()
        self.gallery.delete()

    def test_can_write(self):
        self.user_gallery.mode = 'W'

        self.assertTrue(self.user_gallery.can_write())
        self.assertFalse(self.user_gallery.can_read())

    def test_can_read(self):
        self.user_gallery.mode = 'R'

        self.assertFalse(self.user_gallery.can_write())
        self.assertTrue(self.user_gallery.can_read())

    def test_get_images(self):
        self.assertEqual(2, len(self.user_gallery.get_images()))

        self.assertEqual(self.image1, self.user_gallery.get_images()[0])
        self.assertEqual(self.image2, self.user_gallery.get_images()[1])
コード例 #9
0
class UserGalleryTest(TestCase):
    def setUp(self):
        self.profile = ProfileFactory()
        self.gallery = GalleryFactory()
        self.image1 = ImageFactory(gallery=self.gallery)
        self.image2 = ImageFactory(gallery=self.gallery)
        self.user_gallery = UserGalleryFactory(user=self.profile.user,
                                               gallery=self.gallery)

    def tearDown(self):
        self.image1.delete()
        self.image2.delete()
        self.user_gallery.delete()
        self.gallery.delete()

    def test_can_write(self):
        self.user_gallery.mode = 'W'

        self.assertTrue(self.user_gallery.can_write())
        self.assertFalse(self.user_gallery.can_read())

    def test_can_read(self):
        self.user_gallery.mode = 'R'

        self.assertFalse(self.user_gallery.can_write())
        self.assertTrue(self.user_gallery.can_read())

    def test_get_images(self):
        self.assertEqual(2, len(self.user_gallery.get_images()))

        self.assertEqual(self.image1, self.user_gallery.get_images()[0])
        self.assertEqual(self.image2, self.user_gallery.get_images()[1])
コード例 #10
0
    def test_get_gallery_read_permissions(self):
        UserGalleryFactory(user=self.other.user, gallery=self.gallery)
        UserGalleryFactory(user=self.profile.user,
                           gallery=self.gallery,
                           mode=GALLERY_READ)

        response = self.client.get(
            reverse('api:gallery:detail', kwargs={'pk': self.gallery.pk}))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data.get('id'), self.gallery.pk)
        self.assertEqual(response.data.get('permissions'), {
            'read': True,
            'write': False
        })
コード例 #11
0
    def test_get_gallery_read_permissions(self):
        UserGalleryFactory(user=self.other.user, gallery=self.gallery)
        UserGalleryFactory(user=self.profile.user,
                           gallery=self.gallery,
                           mode=GALLERY_READ)

        response = self.client.get(
            reverse("api:gallery:detail", kwargs={"pk": self.gallery.pk}))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data.get("id"), self.gallery.pk)
        self.assertEqual(response.data.get("permissions"), {
            "read": True,
            "write": False
        })
コード例 #12
0
    def test_opinion_publication_guest(self):
        """
        Test the publication of PublishableContent where type is OPINION (with guest => 403).
        """

        text_publication = 'Aussi tôt dit, aussi tôt fait !'

        opinion = PublishableContentFactory(type='OPINION')

        opinion.authors.add(self.user_author)
        UserGalleryFactory(gallery=opinion.gallery, user=self.user_author, mode='W')
        opinion.licence = self.licence
        opinion.save()

        opinion_draft = opinion.load_version()
        ExtractFactory(container=opinion_draft, db_object=opinion)
        ExtractFactory(container=opinion_draft, db_object=opinion)

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

        result = self.client.post(
            reverse('validation:publish-opinion', kwargs={'pk': opinion.pk, 'slug': opinion.slug}),
            {
                'text': text_publication,
                'source': '',
                'version': opinion_draft.current_version
            },
            follow=False)
        self.assertEqual(result.status_code, 403)

        self.assertEqual(PublishedContent.objects.count(), 0)
コード例 #13
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)
コード例 #14
0
ファイル: factories.py プロジェクト: Lucas-ech/zds-site
    def _prepare(cls, create, **kwargs):

        light = kwargs.pop('light', False)
        tuto = super(BigTutorialFactory, cls)._prepare(create, **kwargs)
        path = tuto.get_path()
        real_content = content
        if light:
            real_content = content_light
        if not os.path.isdir(path):
            os.makedirs(path, mode=0o777)

        man = export_tutorial(tuto)
        repo = Repo.init(path, bare=False)
        repo = Repo(path)

        f = open(os.path.join(path, 'manifest.json'), "w")
        f.write(json_writer.dumps(man, indent=4, ensure_ascii=False).encode('utf-8'))
        f.close()
        f = open(os.path.join(path, tuto.introduction), "w")
        f.write(real_content.encode('utf-8'))
        f.close()
        f = open(os.path.join(path, tuto.conclusion), "w")
        f.write(real_content.encode('utf-8'))
        f.close()
        repo.index.add(['manifest.json', tuto.introduction, tuto.conclusion])
        cm = repo.index.commit("Init Tuto")

        tuto.sha_draft = cm.hexsha
        tuto.sha_beta = None
        tuto.gallery = GalleryFactory()
        for author in tuto.authors.all():
            UserGalleryFactory(user=author, gallery=tuto.gallery)
        return tuto
コード例 #15
0
ファイル: tests_utils.py プロジェクト: leroivi/zds-site
    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()
コード例 #16
0
ファイル: tests_basics.py プロジェクト: leroivi/zds-site
    def setUp(self):
        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.client.force_login(self.user1)
コード例 #17
0
ファイル: tests_tricky.py プロジェクト: tuxmania/site-app
    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='******'))
コード例 #18
0
def load_gallery(cli, size, fake, *_, **__):
    """
    Load galleries
    """
    nb_galleries = size * 1
    nb_images = size * 3
    cli.stdout.write(
        "Nombres de galéries à créer par utilisateur: {}".format(nb_galleries))
    cli.stdout.write(
        "Nombres d'images à créer par gallerie: {}".format(nb_images))
    tps1 = time.time()
    nb_users = User.objects.count()
    if nb_users == 0:
        cli.stdout.write(
            "Il n'y a aucun membre actuellement. "
            "Vous devez rajouter les membres dans vos fixtures (member)")
        return
    profiles = list(Profile.objects.all())
    for user_index in range(0, nb_users):
        for gallery_index in range(0, nb_galleries):
            gal = GalleryFactory(title=fake.text(max_nb_chars=80),
                                 subtitle=fake.text(max_nb_chars=200))
            UserGalleryFactory(user=profiles[user_index].user, gallery=gal)
            __push_images_into_gallery(gal, user_index, gallery_index,
                                       nb_galleries, nb_images, nb_users)
    tps2 = time.time()
    cli.stdout.write("\nFait en {} sec".format(tps2 - tps1))
コード例 #19
0
ファイル: tests_utils.py プロジェクト: pquentin/zds-site
    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)
コード例 #20
0
ファイル: factories.py プロジェクト: tuxmania/site-app
    def _prepare(cls, create, *, light=True, **kwargs):
        auths = []
        if 'author_list' in kwargs:
            auths = kwargs.pop('author_list')
        given_licence = None
        if 'licence' in kwargs:
            given_licence = kwargs.pop('licence',
                                       None) or Licence.objects.first()
        if isinstance(given_licence, str) and given_licence:
            given_licence = Licence.objects.filter(
                title=given_licence).first() or Licence.objects.first()
        licence = given_licence or LicenceFactory()

        text = text_content
        if not light:
            text = tricky_text_content

        publishable_content = super(PublishableContentFactory,
                                    cls)._prepare(create, **kwargs)
        publishable_content.gallery = GalleryFactory()
        publishable_content.licence = licence
        for auth in auths:
            publishable_content.authors.add(auth)

        publishable_content.save()

        for author in publishable_content.authors.all():
            UserGalleryFactory(user=author,
                               gallery=publishable_content.gallery,
                               mode='W')

        init_new_repo(publishable_content, text, text)

        return publishable_content
コード例 #21
0
ファイル: tests_move.py プロジェクト: sylafrs/zds-site
    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()
コード例 #22
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
コード例 #23
0
    def _prepare(cls, create, **kwargs):
        auths = []
        if 'author_list' in kwargs:
            auths = kwargs.pop('author_list')

        light = True
        if 'light' in kwargs:
            light = kwargs.pop('light')
        text = text_content
        if not light:
            text = tricky_text_content

        publishable_content = super(PublishableContentFactory,
                                    cls)._prepare(create, **kwargs)
        publishable_content.gallery = GalleryFactory()

        for auth in auths:
            publishable_content.authors.add(auth)

        publishable_content.save()

        for author in publishable_content.authors.all():
            UserGalleryFactory(user=author,
                               gallery=publishable_content.gallery,
                               mode='W')

        init_new_repo(publishable_content, text, text)

        return publishable_content
コード例 #24
0
    def test_delete_image_from_other_user(self):
        """ if user try to remove images from another user without permission"""
        profile4 = ProfileFactory()
        gallery4 = GalleryFactory()
        image4 = ImageFactory(gallery=gallery4)
        UserGalleryFactory(user=profile4.user, gallery=gallery4)
        self.assertEqual(1, Image.objects.filter(pk=image4.pk).count())

        login_check = self.client.login(username=self.profile1.user.username,
                                        password='******')
        self.assertTrue(login_check)

        self.client.post(
            reverse('gallery-image-delete',
                    kwargs={'pk_gallery': self.gallery1.pk}),
            {
                'gallery': self.gallery1.pk,
                'delete': '',
                'image': image4.pk
            },
            follow=True,
        )

        self.assertEqual(1, Image.objects.filter(pk=image4.pk).count())
        image4.delete()
コード例 #25
0
def load_gallery(cli, size, fake):
    """
    Load galleries
    """
    nb_galleries = size * 3
    nb_images = size * 5
    cli.stdout.write(u"Nombres de galéries à créer par utilisateur: {}".format(nb_galleries))
    cli.stdout.write(u"Nombres d'images à créer par gallerie: {}".format(nb_images))
    tps1 = time.time()
    nb_users = User.objects.count()
    if nb_users == 0:
        cli.stdout.write(u"Il n'y a aucun membre actuellement. "
                         u"Vous devez rajouter les membres dans vos fixtures (member)")
    else:
        profiles = list(Profile.objects.all())
        for i in range(0, nb_users):
            for j in range(0, nb_galleries):
                gal = GalleryFactory(title=fake.text(max_nb_chars=80), subtitle=fake.text(max_nb_chars=200))
                UserGalleryFactory(user=profiles[i].user, gallery=gal)
                for k in range(0, nb_images):
                    ImageFactory(gallery=gal)
                    sys.stdout.write(" User {}/{}  \tGallery {}/{}  \tImage {}/{}  \r".
                                     format(i + 1, nb_users, j + 1, nb_galleries, k + 1, nb_images))
                    sys.stdout.flush()
        tps2 = time.time()
        cli.stdout.write(u"\nFait en {} sec".format(tps2 - tps1))
コード例 #26
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()
        }
コード例 #27
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()
コード例 #28
0
ファイル: tests.py プロジェクト: leroivi/zds-site
    def test_delete(self):
        UserGalleryFactory(user=self.profile.user, gallery=self.gallery)

        response = self.client.delete(reverse("api:gallery:detail", kwargs={"pk": self.gallery.pk}))

        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)

        self.assertEqual(Gallery.objects.filter(pk=self.gallery.pk).count(), 0)
        self.assertEqual(UserGallery.objects.filter(gallery=self.gallery).count(), 0)
コード例 #29
0
ファイル: tests.py プロジェクト: leroivi/zds-site
    def test_delete_fail_no_right(self):
        UserGalleryFactory(user=self.other.user, gallery=self.gallery)

        response = self.client.delete(reverse("api:gallery:detail", kwargs={"pk": self.gallery.pk}))

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

        self.assertEqual(Gallery.objects.filter(pk=self.gallery.pk).count(), 1)
        self.assertEqual(UserGallery.objects.filter(gallery=self.gallery).count(), 1)
コード例 #30
0
ファイル: tests_utils.py プロジェクト: leroivi/zds-site
    def test_publish_content_article(self):
        """test and ensure the behavior of ``publish_content()`` and ``unpublish_content()``"""

        # 1. Article:
        article = PublishableContentFactory(type="ARTICLE")

        article.authors.add(self.user_author)
        UserGalleryFactory(gallery=article.gallery, user=self.user_author, mode="W")
        article.licence = self.licence
        article.save()

        # populate the article
        article_draft = article.load_version()
        ExtractFactory(container=article_draft, db_object=article)
        ExtractFactory(container=article_draft, db_object=article)

        self.assertEqual(len(article_draft.children), 2)

        # publish !
        article = PublishableContent.objects.get(pk=article.pk)
        published = publish_content(article, article_draft)

        self.assertEqual(published.content, article)
        self.assertEqual(published.content_pk, article.pk)
        self.assertEqual(published.content_type, article.type)
        self.assertEqual(published.content_public_slug, article_draft.slug)
        self.assertEqual(published.sha_public, article.sha_draft)

        public = article.load_version(sha=published.sha_public, public=published)
        self.assertIsNotNone(public)
        self.assertTrue(public.PUBLIC)  # it's a PublicContent object
        self.assertEqual(public.type, published.content_type)
        self.assertEqual(public.current_version, published.sha_public)

        # test object created in database
        self.assertEqual(PublishedContent.objects.filter(content=article).count(), 1)
        published = PublishedContent.objects.filter(content=article).last()

        self.assertEqual(published.content_pk, article.pk)
        self.assertEqual(published.content_public_slug, article_draft.slug)
        self.assertEqual(published.content_type, article.type)
        self.assertEqual(published.sha_public, public.current_version)

        # test creation of files:
        self.assertTrue(os.path.isdir(published.get_prod_path()))
        self.assertTrue(os.path.isfile(os.path.join(published.get_prod_path(), "manifest.json")))
        prod_path = public.get_prod_path()
        self.assertTrue(prod_path.endswith(".html"), prod_path)
        self.assertTrue(os.path.isfile(prod_path), prod_path)  # normally, an HTML file should exists
        self.assertIsNone(public.introduction)  # since all is in the HTML file, introduction does not exists anymore
        self.assertIsNone(public.conclusion)
        article.public_version = published
        article.save()
        # depublish it !
        unpublish_content(article)
        self.assertEqual(PublishedContent.objects.filter(content=article).count(), 0)  # published object disappear
        self.assertFalse(os.path.exists(public.get_prod_path()))  # article was removed
コード例 #31
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()
コード例 #32
0
class UserGalleryTest(TestCase):
    def setUp(self):
        self.profile = ProfileFactory()
        self.gallery = GalleryFactory()
        self.image1 = ImageFactory(gallery=self.gallery)
        self.image2 = ImageFactory(gallery=self.gallery)
        self.user_gallery = UserGalleryFactory(user=self.profile.user,
                                               gallery=self.gallery)

    def tearDown(self):
        self.image1.delete()
        self.image2.delete()
        self.user_gallery.delete()
        self.gallery.delete()

    def test_unicode(self):
        result = u'Galerie "{0}" envoye par {1}'.format(
            self.gallery, self.profile.user)

        self.assertEqual(result, self.user_gallery.__unicode__())

    def test_is_write(self):
        self.user_gallery.mode = 'W'

        self.assertTrue(self.user_gallery.is_write())
        self.assertFalse(self.user_gallery.is_read())

    def test_is_read(self):
        self.user_gallery.mode = 'R'

        self.assertFalse(self.user_gallery.is_write())
        self.assertTrue(self.user_gallery.is_read())

    def test_get_images(self):
        self.assertEqual(2, len(self.user_gallery.get_images()))

        self.assertEqual(self.image1, self.user_gallery.get_images()[0])
        self.assertEqual(self.image2, self.user_gallery.get_images()[1])

    def test_get_gallery(self):
        gallery_results = self.user_gallery.get_gallery(self.profile.user)

        self.assertEqual(1, len(gallery_results))
        self.assertEqual(self.gallery, gallery_results[0])
コード例 #33
0
ファイル: tests_utils.py プロジェクト: leroivi/zds-site
    def test_publish_content_big_tuto(self):
        # 4. Big tutorial:
        bigtuto = PublishableContentFactory(type="TUTORIAL")

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

        # populate with 2 part (1 chapter with 1 extract each)
        bigtuto_draft = bigtuto.load_version()
        part1 = ContainerFactory(parent=bigtuto_draft, db_object=bigtuto)
        chapter1 = ContainerFactory(parent=part1, db_object=bigtuto)
        ExtractFactory(container=chapter1, db_object=bigtuto)
        part2 = ContainerFactory(parent=bigtuto_draft, db_object=bigtuto)
        chapter2 = ContainerFactory(parent=part2, db_object=bigtuto)
        ExtractFactory(container=chapter2, db_object=bigtuto)

        # publish it
        bigtuto = PublishableContent.objects.get(pk=bigtuto.pk)
        published = publish_content(bigtuto, bigtuto_draft)

        self.assertEqual(published.content, bigtuto)
        self.assertEqual(published.content_pk, bigtuto.pk)
        self.assertEqual(published.content_type, bigtuto.type)
        self.assertEqual(published.content_public_slug, bigtuto_draft.slug)
        self.assertEqual(published.sha_public, bigtuto.sha_draft)

        public = bigtuto.load_version(sha=published.sha_public, public=published)
        self.assertIsNotNone(public)
        self.assertTrue(public.PUBLIC)  # it's a PublicContent object
        self.assertEqual(public.type, published.content_type)
        self.assertEqual(public.current_version, published.sha_public)

        # test creation of files:
        self.assertTrue(os.path.isdir(published.get_prod_path()))
        self.assertTrue(os.path.isfile(os.path.join(published.get_prod_path(), "manifest.json")))

        self.assertTrue(os.path.isfile(os.path.join(public.get_prod_path(), public.introduction)))
        self.assertTrue(os.path.isfile(os.path.join(public.get_prod_path(), public.conclusion)))

        self.assertEqual(len(public.children), 2)
        for part in public.children:
            self.assertTrue(os.path.isdir(part.get_prod_path()))  # a directory for each part
            # ... and an HTML file for introduction and conclusion
            self.assertTrue(os.path.isfile(os.path.join(public.get_prod_path(), part.introduction)))
            self.assertTrue(os.path.isfile(os.path.join(public.get_prod_path(), part.conclusion)))

            self.assertEqual(len(part.children), 1)

            for chapter in part.children:
                # the HTML file is located in the good directory:
                self.assertEqual(part.get_prod_path(), os.path.dirname(chapter.get_prod_path()))
                self.assertTrue(os.path.isfile(chapter.get_prod_path()))  # an HTML file for each chapter
                self.assertIsNone(chapter.introduction)
                self.assertIsNone(chapter.conclusion)
コード例 #34
0
ファイル: tests_models.py プロジェクト: Aer-o/zds-site
class UserGalleryTest(TestCase):

    def setUp(self):
        self.profile = ProfileFactory()
        self.gallery = GalleryFactory()
        self.image1 = ImageFactory(gallery=self.gallery)
        self.image2 = ImageFactory(gallery=self.gallery)
        self.user_gallery = UserGalleryFactory(user=self.profile.user, gallery=self.gallery)

    def tearDown(self):
        self.image1.delete()
        self.image2.delete()
        self.user_gallery.delete()
        self.gallery.delete()

    def test_unicode(self):
        result = u'Galerie "{0}" envoye par {1}'.format(self.gallery, self.profile.user)

        self.assertEqual(result, self.user_gallery.__unicode__())

    def test_is_write(self):
        self.user_gallery.mode = 'W'

        self.assertTrue(self.user_gallery.is_write())
        self.assertFalse(self.user_gallery.is_read())

    def test_is_read(self):
        self.user_gallery.mode = 'R'

        self.assertFalse(self.user_gallery.is_write())
        self.assertTrue(self.user_gallery.is_read())

    def test_get_images(self):
        self.assertEqual(2, len(self.user_gallery.get_images()))

        self.assertEqual(self.image1, self.user_gallery.get_images()[0])
        self.assertEqual(self.image2, self.user_gallery.get_images()[1])

    def test_get_gallery(self):
        gallery_results = self.user_gallery.get_gallery(self.profile.user)

        self.assertEqual(1, len(gallery_results))
        self.assertEqual(self.gallery, gallery_results[0])
コード例 #35
0
ファイル: tests_models.py プロジェクト: Aer-o/zds-site
 def setUp(self):
     self.profile = ProfileFactory()
     self.gallery = GalleryFactory()
     self.image1 = ImageFactory(gallery=self.gallery)
     self.image2 = ImageFactory(gallery=self.gallery)
     self.user_gallery = UserGalleryFactory(user=self.profile.user, gallery=self.gallery)