Ejemplo n.º 1
0
 def test_image_search(self):
     ImageFactory(title='fx2-quicktimeflash.png')
     ImageFactory(title='another-image.png')
     url = reverse('gallery.search', args=['image'])
     response = self.client.get(url, {'q': 'quicktime'}, follow=True)
     doc = pq(response.content)
     eq_(1, len(doc('#media-list li')))
Ejemplo n.º 2
0
 def test_image_search(self):
     ImageFactory(title="fx2-quicktimeflash.png")
     ImageFactory(title="another-image.png")
     url = reverse("gallery.search", args=["image"])
     response = self.client.get(url, {"q": "quicktime"}, follow=True)
     doc = pq(response.content)
     eq_(1, len(doc("#media-list li")))
Ejemplo n.º 3
0
 def test_search_description(self):
     ImageFactory(description="This image was automatically migrated")
     ImageFactory(description="This image was automatically migrated")
     ImageFactory(description="This image was automatically")
     url = reverse("gallery.search", args=["image"])
     response = self.client.get(url, {"q": "migrated"}, follow=True)
     doc = pq(response.content)
     eq_(2, len(doc("#media-list li")))
Ejemplo n.º 4
0
 def test_search_description(self):
     ImageFactory(description='This image was automatically migrated')
     ImageFactory(description='This image was automatically migrated')
     ImageFactory(description='This image was automatically')
     url = reverse('gallery.search', args=['image'])
     response = self.client.get(url, {'q': 'migrated'}, follow=True)
     doc = pq(response.content)
     eq_(2, len(doc('#media-list li')))
Ejemplo n.º 5
0
    def test_full_fallback(self):
        """Find current locale's image, not the English one."""
        # first, pretend there is no English version
        self.img.locale = "ja"
        self.img.save()
        img = pq_img(self.p, "[[Image:test.jpg]]", selector="img", locale="ja")
        eq_("test.jpg", img.attr("alt"))
        eq_(self.img.file.url, img.attr("src"))

        # then, create an English version
        en_img = ImageFactory(title="test.jpg", locale="en-US")
        # Ensure they're not equal
        self.assertNotEqual(en_img.file.url, self.img.file.url)

        # make sure there is no fallback
        img = pq_img(self.p, "[[Image:test.jpg]]", selector="img", locale="ja")
        eq_("test.jpg", img.attr("alt"))
        eq_(self.img.file.url, img.attr("src"))

        # now delete the English version
        self.img.delete()
        self.img = en_img  # don't break tearDown
        img = pq_img(self.p, "[[Image:test.jpg]]", selector="img", locale="ja")
        eq_("test.jpg", img.attr("alt"))
        eq_(self.img.file.url, img.attr("src"))
Ejemplo n.º 6
0
    def test_full_fallback(self):
        """Find current locale's image, not the English one."""
        # first, pretend there is no English version
        self.img.locale = 'ja'
        self.img.save()
        img = pq_img(self.p, '[[Image:test.jpg]]', selector='img', locale='ja')
        eq_('test.jpg', img.attr('alt'))
        eq_(self.img.file.url, img.attr('src'))

        # then, create an English version
        en_img = ImageFactory(title='test.jpg', locale='en-US')
        # Ensure they're not equal
        self.assertNotEquals(en_img.file.url, self.img.file.url)

        # make sure there is no fallback
        img = pq_img(self.p, '[[Image:test.jpg]]', selector='img', locale='ja')
        eq_('test.jpg', img.attr('alt'))
        eq_(self.img.file.url, img.attr('src'))

        # now delete the English version
        self.img.delete()
        self.img = en_img  # don't break tearDown
        img = pq_img(self.p, '[[Image:test.jpg]]', selector='img', locale='ja')
        eq_('test.jpg', img.attr('alt'))
        eq_(self.img.file.url, img.attr('src'))
Ejemplo n.º 7
0
    def test_images(self):
        img = ImageFactory(title='image-file.png')
        d1, _, _ = doc_rev_parser('[[Image:image-file.png]]', title='D1')

        eq_(len(d1.images), 1)
        eq_(d1.images[0], img)
        eq_(len(img.documents), 1)
        eq_(img.documents[0], d1)
Ejemplo n.º 8
0
    def test_images(self):
        img = ImageFactory(title="image-file.png")
        d1, _, _ = doc_rev_parser("[[Image:image-file.png]]", title="D1")

        eq_(len(d1.images), 1)
        eq_(d1.images[0], img)
        eq_(len(img.documents), 1)
        eq_(img.documents[0], d1)
Ejemplo n.º 9
0
    def test_thumbnail_url_if_set(self):
        """thumbnail_url_if_set() returns self.thumbnail if set, or else
        returns self.file"""
        img = ImageFactory()
        eq_(img.file.url, img.thumbnail_url_if_set())

        generate_thumbnail(img, 'file', 'thumbnail')
        eq_(img.thumbnail.url, img.thumbnail_url_if_set())
Ejemplo n.º 10
0
 def test_image_draft_shows(self):
     """The image draft is loaded for this user."""
     img = ImageFactory(is_draft=True, creator=self.u)
     response = get(self.client, "gallery.gallery", args=["image"])
     eq_(200, response.status_code)
     doc = pq(response.content)
     assert doc(".file.preview img").attr("src").endswith(img.file.name)
     eq_(1, doc(".file.preview img").length)
Ejemplo n.º 11
0
 def test_image_media_page(self):
     """Test the media page."""
     img = ImageFactory()
     response = self.client.get(img.get_absolute_url(), follow=True)
     eq_(200, response.status_code)
     doc = pq(response.content)
     eq_(img.title, doc("h1").text())
     eq_(img.description, doc("#media-object div.description").text())
     eq_(img.file.url, doc("#media-view img")[0].attrib["src"])
Ejemplo n.º 12
0
    def test_delete_image_without_permissions(self):
        """Can't delete an image I didn't create."""
        img = ImageFactory()
        u = UserFactory()
        self.client.login(username=u.username, password='******')
        r = post(self.client, 'gallery.delete_media', args=['image', img.id])

        eq_(403, r.status_code)
        eq_(1, Image.objects.count())
Ejemplo n.º 13
0
 def test_button_image_for_nesting(self):
     """You can nest [[Image:]] inside {for} inside {button}."""
     ImageFactory(title='image-file.png')
     text = '{button {for mac}[[Image:image-file.png]]{/for} text}'
     p = WikiParser()
     doc = pq(p.parse(text))
     assert 'frameless' in doc('img').attr('class')
     eq_(0, doc('div.caption').length)
     eq_(0, doc('div.img').length)
Ejemplo n.º 14
0
    def test_thumbnail_url_if_set(self, create_thumbnail_mock):
        """thumbnail_url_if_set() returns self.thumbnail if set, or else
        returns self.file"""
        img = ImageFactory()
        eq_(img.file.url, img.thumbnail_url_if_set())

        create_thumbnail_mock.return_value = ContentFile("the dude")
        generate_thumbnail(img, "file", "thumbnail")
        eq_(img.thumbnail.url, img.thumbnail_url_if_set())
Ejemplo n.º 15
0
 def test_button_image_for_nesting(self):
     """You can nest [[Image:]] inside {for} inside {button}."""
     ImageFactory(title="image-file.png")
     text = "{button {for mac}[[Image:image-file.png]]{/for} text}"
     p = WikiParser()
     doc = pq(p.parse(text))
     assert "frameless" in doc("img").attr("class")
     eq_(0, doc("div.caption").length)
     eq_(0, doc("div.img").length)
Ejemplo n.º 16
0
    def test_delete_own_image(self):
        """Can delete an image I created."""
        u = UserFactory()
        self.client.login(username=u.username, password='******')
        img = ImageFactory(creator=u)
        r = post(self.client, 'gallery.delete_media', args=['image', img.id])

        eq_(200, r.status_code)
        eq_(0, Image.objects.count())
Ejemplo n.º 17
0
    def test_delete_image(self):
        """Deleting an uploaded image works."""
        im = ImageFactory()
        u = UserFactory()
        add_permission(u, Image, 'delete_image')
        self.client.login(username=u.username, password='******')
        r = post(self.client, 'gallery.delete_media', args=['image', im.id])

        eq_(200, r.status_code)
        eq_(0, Image.objects.count())
Ejemplo n.º 18
0
    def test_edit_image_without_permissions(self):
        """Can't edit an image I didn't create."""
        img = ImageFactory()
        u = UserFactory()
        self.client.login(username=u.username, password='******')
        r = post(self.client,
                 'gallery.edit_media', {'description': 'arrr'},
                 args=['image', img.id])

        eq_(403, r.status_code)
Ejemplo n.º 19
0
    def test_edit_image_without_permissions(self):
        """Can't edit an image I didn't create."""
        img = ImageFactory()
        u = UserFactory()
        self.client.login(username=u.username, password="******")
        r = post(
            self.client, "gallery.edit_media", {"description": "arrr"}, args=["image", img.id]
        )

        eq_(403, r.status_code)
Ejemplo n.º 20
0
 def test_image_draft_post(self):
     """Posting to the page saves the field values for the image draft."""
     ImageFactory(is_draft=True, creator=self.u)
     response = post(self.client, 'gallery.gallery',
                     {'description': '??', 'title': 'test'}, args=['image'])
     eq_(200, response.status_code)
     doc = pq(response.content)
     # Preview for all 3 video formats: flv, ogv, webm
     eq_('??', doc('#gallery-upload-modal textarea').html().strip())
     eq_('test', doc('#gallery-upload-modal input[name="title"]').val())
Ejemplo n.º 21
0
 def test_gallery_image_list(self):
     """Test for ajax endpoint without search parameter."""
     img = ImageFactory()
     url = urlparams(reverse("gallery.async"), type="image")
     response = self.client.get(url, follow=True)
     eq_(200, response.status_code)
     doc = pq(response.content)
     imgs = doc("#media-list li img")
     eq_(1, len(imgs))
     eq_(img.thumbnail_url_if_set(), imgs[0].attrib["src"])
Ejemplo n.º 22
0
    def test_edit_own_image(self):
        """Can edit an image I created."""
        u = UserFactory()
        img = ImageFactory(creator=u)
        self.client.login(username=u.username, password="******")
        r = post(
            self.client, "gallery.edit_media", {"description": "arrr"}, args=["image", img.id]
        )

        eq_(200, r.status_code)
        eq_("arrr", Image.objects.get().description)
Ejemplo n.º 23
0
    def test_schedule_rebuild_kb_on_delete(self, schedule_rebuild_kb):
        """KB rebuild scheduled on delete"""
        im = ImageFactory()
        u = UserFactory()
        add_permission(u, Image, 'delete_image')
        self.client.login(username=u.username, password='******')
        r = post(self.client, 'gallery.delete_media', args=['image', im.id])

        eq_(200, r.status_code)
        eq_(0, Image.objects.count())
        assert schedule_rebuild_kb.called
Ejemplo n.º 24
0
    def test_edit_own_image(self):
        """Can edit an image I created."""
        u = UserFactory()
        img = ImageFactory(creator=u)
        self.client.login(username=u.username, password='******')
        r = post(self.client,
                 'gallery.edit_media', {'description': 'arrr'},
                 args=['image', img.id])

        eq_(200, r.status_code)
        eq_('arrr', Image.objects.get().description)
Ejemplo n.º 25
0
    def test_edit_image_with_permissions(self):
        """Editing image sets the updated_by field."""
        img = ImageFactory()
        u = UserFactory()
        add_permission(u, Image, 'change_image')
        self.client.login(username=u.username, password='******')
        r = post(self.client,
                 'gallery.edit_media', {'description': 'arrr'},
                 args=['image', img.id])

        eq_(200, r.status_code)
        eq_(u.username, Image.objects.get().updated_by.username)
Ejemplo n.º 26
0
    def test_edit_image_with_permissions(self):
        """Editing image sets the updated_by field."""
        img = ImageFactory()
        u = UserFactory()
        add_permission(u, Image, "change_image")
        self.client.login(username=u.username, password="******")
        r = post(
            self.client, "gallery.edit_media", {"description": "arrr"}, args=["image", img.id]
        )

        eq_(200, r.status_code)
        eq_(u.username, Image.objects.get().updated_by.username)
Ejemplo n.º 27
0
    def test_gallery_images(self):
        """Test that all images show up on images gallery page.

        Also, Make sure they don't show up on videos page.

        """
        img = ImageFactory()
        response = get(self.client, "gallery.gallery", args=["image"])
        eq_(200, response.status_code)
        doc = pq(response.content)
        imgs = doc("#media-list li img")
        eq_(1, len(imgs))
        eq_(img.thumbnail_url_if_set(), imgs[0].attrib["src"])
Ejemplo n.º 28
0
    def test_gallery_locale(self):
        """Test that images only show for their set locale."""
        ImageFactory(locale="es")
        url = reverse("gallery.gallery", args=["image"])
        response = self.client.get(url, follow=True)
        eq_(200, response.status_code)
        doc = pq(response.content)
        imgs = doc("#media-list li img")
        eq_(0, len(imgs))

        locale_url = reverse("gallery.gallery", locale="es", args=["image"])
        response = self.client.get(locale_url, follow=True)
        eq_(200, response.status_code)
        doc = pq(response.content)
        imgs = doc("#media-list li img")
        eq_(1, len(imgs))
Ejemplo n.º 29
0
    def test_gallery_image_search(self):
        """Test for ajax endpoint with search parameter."""
        img = ImageFactory()
        url = urlparams(reverse('gallery.async'), type='image', q='foobar')
        response = self.client.get(url, follow=True)
        eq_(200, response.status_code)
        doc = pq(response.content)
        imgs = doc('#media-list li img')
        eq_(0, len(imgs))

        url = urlparams(reverse('gallery.async'), type='image', q=img.title)
        response = self.client.get(url, follow=True)
        eq_(200, response.status_code)
        doc = pq(response.content)
        imgs = doc('#media-list li img')
        eq_(1, len(imgs))
        eq_(img.thumbnail_url_if_set(), imgs[0].attrib['src'])
Ejemplo n.º 30
0
 def test_image_draft_post(self):
     """Posting to the page saves the field values for the image draft."""
     ImageFactory(is_draft=True, creator=self.u)
     response = post(
         self.client,
         "gallery.gallery",
         {
             "description": "??",
             "title": "test"
         },
         args=["image"],
     )
     eq_(200, response.status_code)
     doc = pq(response.content)
     # Preview for all 3 video formats: flv, ogv, webm
     eq_("??", doc("#gallery-upload-modal textarea").html().strip())
     eq_("test", doc('#gallery-upload-modal input[name="title"]').val())