Ejemplo n.º 1
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.º 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 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.º 4
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.º 5
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.º 6
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))
Ejemplo n.º 7
0
    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
Ejemplo n.º 8
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))
Ejemplo n.º 9
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
Ejemplo n.º 10
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.º 11
0
 def test_success_initial_content(self):
     author = ProfileFactory().user
     author2 = ProfileFactory().user
     tutorial = PublishedContentFactory(author_list=[author, author2])
     gallery = GalleryFactory()
     image = ImageFactory(gallery=gallery)
     tutorial.image = image
     tutorial.save()
     staff = StaffProfileFactory()
     login_check = self.client.login(username=staff.user.username,
                                     password='******')
     self.assertTrue(login_check)
     response = self.client.get('{}{}'.format(
         reverse('featured-resource-create'),
         '?content_type=published_content&content_id={}'.format(
             tutorial.pk)))
     initial_dict = response.context['form'].initial
     self.assertEqual(initial_dict['title'], tutorial.title)
     self.assertEqual(initial_dict['authors'],
                      '{}, {}'.format(author, author2))
     self.assertEqual(initial_dict['type'], _('Un tutoriel'))
     self.assertEqual(
         initial_dict['url'],
         'http://testserver{}'.format(tutorial.get_absolute_url_online()))
     self.assertEqual(
         initial_dict['image_url'],
         'http://testserver{}'.format(image.physical['featured'].url))
Ejemplo n.º 12
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()
Ejemplo n.º 13
0
 def test_success_initial_content(self):
     author = ProfileFactory().user
     author2 = ProfileFactory().user
     tutorial = PublishedContentFactory(author_list=[author, author2])
     gallery = GalleryFactory()
     image = ImageFactory(gallery=gallery)
     tutorial.image = image
     tutorial.save()
     staff = StaffProfileFactory()
     login_check = self.client.login(username=staff.user.username,
                                     password="******")
     self.assertTrue(login_check)
     response = self.client.get("{}{}".format(
         reverse("featured-resource-create"),
         "?content_type=published_content&content_id={}".format(
             tutorial.pk)))
     initial_dict = response.context["form"].initial
     self.assertEqual(initial_dict["title"], tutorial.title)
     self.assertEqual(initial_dict["authors"],
                      "{}, {}".format(author, author2))
     self.assertEqual(initial_dict["type"], _("Un tutoriel"))
     self.assertEqual(
         initial_dict["url"],
         "http://testserver{}".format(tutorial.get_absolute_url_online()))
     self.assertEqual(
         initial_dict["image_url"],
         "http://testserver{}".format(image.physical["featured"].url))
Ejemplo n.º 14
0
    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
Ejemplo n.º 15
0
    def test_list_galeries_belong_to_member(self):
        profile = ProfileFactory()
        gallery = GalleryFactory()
        GalleryFactory()
        UserGalleryFactory(user=profile.user, gallery=gallery)

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

        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)[0],
            response.context['galleries'][0][0])
Ejemplo n.º 16
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.º 17
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.º 18
0
 def setUp(self):
     self.profile1 = ProfileFactory()
     self.profile2 = ProfileFactory()
     self.profile3 = ProfileFactory()
     self.gallery1 = GalleryFactory()
     self.user_gallery1 = UserGalleryFactory(user=self.profile1.user,
                                             gallery=self.gallery1)
     self.user_gallery3 = UserGalleryFactory(user=self.profile3.user,
                                             gallery=self.gallery1,
                                             mode="R")
Ejemplo n.º 19
0
    def test_valid_user_gallery_form(self):
        gallery = GalleryFactory()
        data = {
            'action': 'add',
            'user': self.profile,
            'mode': 'R'
        }
        form = UserGalleryForm(gallery=gallery, data=data)

        self.assertTrue(form.is_valid())
Ejemplo n.º 20
0
    def test_invalid_user_gallery_form_noexist_user(self):
        gallery = GalleryFactory()
        data = {
            'action': 'add',
            'user': '******',
            'mode': 'W'
        }
        form = UserGalleryForm(gallery=gallery, data=data)

        self.assertFalse(form.is_valid())
Ejemplo n.º 21
0
 def test_get_tuto_count(self):
     # Start with 0
     self.assertEqual(self.user1.get_tuto_count(), 0)
     # Create Tuto !
     minituto = PublishableContentFactory(type='TUTORIAL')
     minituto.authors.add(self.user1.user)
     minituto.gallery = GalleryFactory()
     minituto.save()
     # Should be 1
     self.assertEqual(self.user1.get_tuto_count(), 1)
Ejemplo n.º 22
0
 def test_get_tuto_count(self):
     # Start with 0
     self.assertEqual(self.user1.get_tuto_count(), 0)
     # Create Tuto !
     minituto = MiniTutorialFactory()
     minituto.authors.add(self.user1.user)
     minituto.gallery = GalleryFactory()
     minituto.save()
     # Should be 1
     self.assertEqual(self.user1.get_tuto_count(), 1)
Ejemplo n.º 23
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.º 24
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.º 25
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('zds.gallery.views.gallery_details',
            args=[gallery.pk, gallery.slug]))
        self.assertEqual(200, response.status_code)
Ejemplo n.º 26
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)

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

        response = self.client.get(reverse('zds.gallery.views.gallery_details',
            args=[gallery.pk, gallery.slug]))
        self.assertEqual(403, response.status_code)
Ejemplo n.º 27
0
 def test_get_tutos(self):
     # Start with 0
     self.assertEqual(len(self.user1.get_tutos()), 0)
     # Create Tuto !
     minituto = PublishableContentFactory(type='TUTORIAL')
     minituto.authors.add(self.user1.user)
     minituto.gallery = GalleryFactory()
     minituto.save()
     # Should be 1
     tutos = self.user1.get_tutos()
     self.assertEqual(len(tutos), 1)
     self.assertEqual(minituto, tutos[0])
Ejemplo n.º 28
0
 def test_get_tutos(self):
     # Start with 0
     self.assertEqual(len(self.user1.get_tutos()), 0)
     # Create Tuto !
     minituto = MiniTutorialFactory()
     minituto.authors.add(self.user1.user)
     minituto.gallery = GalleryFactory()
     minituto.save()
     # Should be 1
     tutos = self.user1.get_tutos()
     self.assertEqual(len(tutos), 1)
     self.assertEqual(minituto, tutos[0])
Ejemplo n.º 29
0
 def test_get_draft_tutos(self):
     # Start with 0
     self.assertEqual(len(self.user1.get_draft_tutos()), 0)
     # Create Tuto !
     drafttuto = PublishableContentFactory(type="TUTORIAL")
     drafttuto.authors.add(self.user1.user)
     drafttuto.gallery = GalleryFactory()
     drafttuto.save()
     # Should be 1
     drafttutos = self.user1.get_draft_tutos()
     self.assertEqual(len(drafttutos), 1)
     self.assertEqual(drafttuto, drafttutos[0])
Ejemplo n.º 30
0
 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")