Ejemplo n.º 1
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")
Ejemplo n.º 2
0
    def setUp(self):
        self.profile = ProfileFactory()
        self.other = ProfileFactory()
        self.new_participant = ProfileFactory()
        self.client = APIClient()
        client_oauth2 = create_oauth2_client(self.profile.user)
        authenticate_client(self.client, client_oauth2,
                            self.profile.user.username, "hostel77")

        self.gallery = GalleryFactory()
        UserGalleryFactory(user=self.profile.user, gallery=self.gallery)
        self.image = ImageFactory(gallery=self.gallery)

        self.gallery_other = GalleryFactory()
        UserGalleryFactory(user=self.other.user, gallery=self.gallery_other)
        self.image_other = ImageFactory(gallery=self.gallery_other)

        self.gallery_shared = GalleryFactory()
        UserGalleryFactory(user=self.other.user, gallery=self.gallery_shared)
        UserGalleryFactory(user=self.profile.user,
                           gallery=self.gallery_shared,
                           mode=GALLERY_READ)
        self.image_shared = ImageFactory(gallery=self.gallery_shared)

        tuto = PublishableContentFactory(
            type="TUTORIAL",
            author_list=[self.profile.user, self.new_participant.user])
        self.gallery_tuto = tuto.gallery
Ejemplo n.º 3
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)

        self.client.force_login(self.profile2.user)

        response = self.client.get(reverse("gallery-details", args=[gallery.pk, gallery.slug]))
        self.assertEqual(200, response.status_code)
Ejemplo n.º 4
0
 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")
Ejemplo n.º 5
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
        })
Ejemplo n.º 6
0
    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)
Ejemplo n.º 7
0
 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)
Ejemplo n.º 8
0
    def test_opinion_publication_staff(self):
        """
        Test the publication of PublishableContent where type is OPINION (with staff).
        """

        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.client.force_login(self.user_staff)

        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, 302)

        self.assertEqual(PublishedContent.objects.count(), 1)

        opinion = PublishableContent.objects.get(pk=opinion.pk)
        self.assertIsNotNone(opinion.public_version)
        self.assertEqual(opinion.public_version.sha_public, opinion_draft.current_version)
Ejemplo n.º 9
0
 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")
     default_gallery_u1 = GalleryFactory(title="default", slug="default", subtitle="bla")
     UserGalleryFactory(user=self.profile1.user, gallery=default_gallery_u1, is_default=True)
     default_gallery_u2 = GalleryFactory(title="default", slug="default", subtitle="bla")
     UserGalleryFactory(user=self.profile2.user, gallery=default_gallery_u2, is_default=True)
Ejemplo n.º 10
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)
Ejemplo 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()
Ejemplo n.º 12
0
    def test_fail_gallery_details_no_permission(self):
        """fail when a user has no permission at all"""
        gallery = GalleryFactory()
        UserGalleryFactory(gallery=gallery, user=self.profile1.user)

        self.client.force_login(self.profile2.user)

        response = self.client.get(reverse("gallery-details", args=[gallery.pk, gallery.slug]))
        self.assertEqual(403, response.status_code)
Ejemplo n.º 13
0
    def test_get_list_of_gallery(self):

        gallery = GalleryFactory()
        UserGalleryFactory(user=self.profile.user, gallery=gallery)
        response = self.client.get(reverse("api:gallery:list"))

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data.get("count"), 1)
        self.assertIsNone(response.data.get("next"))
        self.assertIsNone(response.data.get("previous"))
Ejemplo n.º 14
0
    def test_publish_content_medium_tuto(self):
        # 3. Medium-size tutorial
        midsize_tuto = PublishableContentFactory(type="TUTORIAL")

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

        # populate with 2 chapters (1 extract each)
        midsize_tuto_draft = midsize_tuto.load_version()
        chapter1 = ContainerFactory(parent=midsize_tuto_draft,
                                    db_object=midsize_tuto)
        ExtractFactory(container=chapter1, db_object=midsize_tuto)
        chapter2 = ContainerFactory(parent=midsize_tuto_draft,
                                    db_object=midsize_tuto)
        ExtractFactory(container=chapter2, db_object=midsize_tuto)

        # publish it
        midsize_tuto = PublishableContent.objects.get(pk=midsize_tuto.pk)
        published = publish_content(midsize_tuto, midsize_tuto_draft)

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

        public = midsize_tuto.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(Path(published.get_prod_path()).is_dir())
        self.assertTrue(
            Path(published.get_prod_path(), "manifest.json").is_file())

        self.assertTrue(
            Path(public.get_prod_path(), public.introduction).is_file())
        self.assertTrue(
            Path(public.get_prod_path(), public.conclusion).is_file())

        self.assertEqual(len(public.children), 2)
        for child in public.children:
            self.assertTrue(os.path.isfile(
                child.get_prod_path()))  # an HTML file for each chapter
            self.assertIsNone(child.introduction)
            self.assertIsNone(child.conclusion)
Ejemplo n.º 15
0
    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)
Ejemplo n.º 16
0
    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)
Ejemplo n.º 17
0
 def get_small_opinion(self):
     """
     Returns a published opinion without extract.
     """
     opinion = PublishableContentFactory(type="OPINION")
     opinion.authors.add(self.user_author)
     UserGalleryFactory(gallery=opinion.gallery, user=self.user_author, mode="W")
     opinion.licence = LicenceFactory()
     opinion.save()
     opinion_draft = opinion.load_version()
     return publish_content(opinion, opinion_draft)
Ejemplo n.º 18
0
    def setUp(self):
        self.profile = ProfileFactory()
        self.other = ProfileFactory()
        self.client = APIClient()
        client_oauth2 = create_oauth2_client(self.profile.user)
        authenticate_client(self.client, client_oauth2,
                            self.profile.user.username, "hostel77")

        self.gallery = GalleryFactory()
        UserGalleryFactory(user=self.profile.user, gallery=self.gallery)
        self.image = ImageFactory(gallery=self.gallery)

        self.gallery_other = GalleryFactory()
        UserGalleryFactory(user=self.other.user, gallery=self.gallery_other)
        self.image_other = ImageFactory(gallery=self.gallery_other)

        self.gallery_shared = GalleryFactory()
        UserGalleryFactory(user=self.other.user, gallery=self.gallery_shared)
        UserGalleryFactory(user=self.profile.user,
                           gallery=self.gallery_shared,
                           mode=GALLERY_READ)
        self.image_shared = ImageFactory(gallery=self.gallery_shared)
Ejemplo n.º 19
0
    def test_permanently_unpublish_opinion(self):
        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.client.force_login(self.user_author)

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

        # login as staff
        self.client.force_login(self.user_staff)

        # unpublish opinion
        result = self.client.post(
            reverse("validation:ignore-opinion", kwargs={"pk": opinion.pk, "slug": opinion.slug}),
            {
                "operation": "REMOVE_PUB",
            },
            follow=False,
        )
        self.assertEqual(result.status_code, 200)

        # refresh
        opinion = PublishableContent.objects.get(pk=opinion.pk)

        # check that the opinion is not published
        self.assertFalse(opinion.in_public())

        # check that it's impossible to publish the opinion again
        result = self.client.get(opinion.get_absolute_url())
        self.assertContains(result, _("Billet modéré"))  # front

        result = self.client.post(
            reverse("validation:publish-opinion", kwargs={"pk": opinion.pk, "slug": opinion.slug}),
            {"source": "", "version": opinion_draft.current_version},
            follow=False,
        )
        self.assertEqual(result.status_code, 403)  # back
Ejemplo n.º 20
0
    def test_list_galeries_belong_to_member(self):
        profile = ProfileFactory()
        gallery = GalleryFactory()
        GalleryFactory()
        UserGalleryFactory(user=profile.user, gallery=gallery)

        self.client.force_login(profile.user)

        response = self.client.get(reverse("gallery-list"), follow=True)
        self.assertEqual(200, response.status_code)

        self.assertEqual(1, len(response.context["galleries"]))
        self.assertEqual(
            UserGallery.objects.filter(user=profile.user).first().gallery, response.context["galleries"].first()
        )
Ejemplo n.º 21
0
    def test_get_gallery(self):
        UserGalleryFactory(user=self.profile.user, gallery=self.gallery)

        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("title"), self.gallery.title)
        self.assertEqual(response.data.get("subtitle"), self.gallery.subtitle)
        self.assertIsNone(response.data.get("linked_content"))
        self.assertEqual(response.data.get("image_count"), 0)
        self.assertEqual(response.data.get("permissions"), {
            "read": True,
            "write": True
        })
Ejemplo n.º 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.force_login(author)

        # 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.force_login(user_staff)

        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
Ejemplo n.º 23
0
    def test_put_fail_no_right(self):
        title = "Ma super galerie"
        subtitle = "... A été mise à jour !"

        UserGalleryFactory(user=self.other.user, gallery=self.gallery)

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

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

        gallery = Gallery.objects.get(pk=self.gallery.pk)
        self.assertNotEqual(gallery.title, title)
        self.assertNotEqual(gallery.subtitle, subtitle)
Ejemplo n.º 24
0
    def _generate(cls, create, attrs):
        # These parameters are only used inside _generate() and won't be saved in the database,
        # which is why we use attrs.pop() (they are removed from attrs).
        light = attrs.pop("light", True)
        author_list = attrs.pop("author_list", None)
        add_license = attrs.pop("add_license", True)
        add_category = attrs.pop("add_category", True)

        # This parameter will be saved in the database,
        # which is why we use attrs.get() (it stays in attrs).
        licence = attrs.get("licence", None)

        auths = author_list or []
        if add_license:
            given_licence = licence 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

        intro_content = attrs.pop("intro", text)
        conclusion_content = attrs.pop("conclusion", text)

        publishable_content = super()._generate(create, attrs)
        publishable_content.gallery = GalleryFactory()
        publishable_content.licence = licence
        for auth in auths:
            publishable_content.authors.add(auth)

        if add_category:
            publishable_content.subcategory.add(SubCategoryFactory())

        publishable_content.save()

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

        init_new_repo(publishable_content, intro_content, conclusion_content)

        return publishable_content
Ejemplo n.º 25
0
    def create_content(self):
        """
        Returns a content and its draft used in following tests.
        """
        tuto = PublishableContentFactory(type="TUTORIAL",
                                         intro="Intro tuto",
                                         conclusion="Conclusion tuto")
        tuto.authors.add(self.user_author)
        UserGalleryFactory(gallery=tuto.gallery,
                           user=self.user_author,
                           mode="W")
        tuto.licence = self.licence
        tuto.save()

        tuto_draft = tuto.load_version()

        return tuto, tuto_draft
Ejemplo n.º 26
0
    def test_delete_participant(self):
        UserGalleryFactory(user=self.new_participant.user,
                           gallery=self.gallery)

        response = self.client.delete(
            reverse(
                "api:gallery:detail-participant",
                kwargs={
                    "pk_gallery": self.gallery.pk,
                    "user__pk": self.new_participant.user.pk
                },
            ))

        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
        self.assertEqual(
            UserGallery.objects.filter(gallery=self.gallery,
                                       user=self.new_participant.user).count(),
            0)
Ejemplo n.º 27
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())

        self.client.force_login(self.profile1.user)

        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()
Ejemplo n.º 28
0
    def test_delete_participant_fail_no_permissions(self):
        UserGalleryFactory(user=self.new_participant.user,
                           gallery=self.gallery_other)

        response = self.client.delete(
            reverse(
                "api:gallery:detail-participant",
                kwargs={
                    "pk_gallery": self.gallery_other.pk,
                    "user__pk": self.new_participant.user.pk
                },
            ))

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
        self.assertEqual(
            UserGallery.objects.filter(gallery=self.gallery_other,
                                       user=self.new_participant.user).count(),
            1)
Ejemplo n.º 29
0
    def test_post_fail_add_participant_already_in(self):
        user_gallery = UserGalleryFactory(user=self.new_participant.user,
                                          gallery=self.gallery,
                                          mode=GALLERY_READ)

        response = self.client.post(
            reverse("api:gallery:list-participants",
                    kwargs={"pk_gallery": self.gallery.pk}),
            {
                "id": self.new_participant.user.pk,
                "can_write": True
            },
        )

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

        user_gallery = UserGallery.objects.get(pk=user_gallery.pk)
        self.assertEqual(user_gallery.mode, GALLERY_READ)
Ejemplo n.º 30
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=ForumCategoryFactory(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()
        self.external = UserFactory(
            username=self.overridden_zds_app["member"]["external_account"],
            password="******")