Пример #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')))
Пример #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")))
Пример #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')))
Пример #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")))
Пример #5
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())
Пример #6
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'])
Пример #7
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"])
Пример #8
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())
Пример #9
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())
Пример #10
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'])
Пример #11
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"])
Пример #12
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'])
Пример #13
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"])
Пример #14
0
class TestLazyWikiImageTags(TestCase):
    def setUp(self):
        self.d, self.r, self.p = doc_rev_parser("Test content", "Installing Firefox")
        self.img = ImageFactory(title="test.jpg")

    def tearDown(self):
        self.img.delete()

    def test_simple(self):
        """Simple image tag markup."""
        doc = pq(self.p.parse("[[Image:test.jpg]]", locale=settings.WIKI_DEFAULT_LANGUAGE))
        img = doc("img")
        eq_("test.jpg", img.attr("alt"))
        eq_(self.img.file.url, img.attr("data-original-src"))
        assert "placeholder.gif" in img.attr("src")
Пример #15
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'))
Пример #16
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"))
Пример #17
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)
Пример #18
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'])
Пример #19
0
class TestLazyWikiImageTags(TestCase):
    def setUp(self):
        self.d, self.r, self.p = doc_rev_parser(
            'Test content', 'Installing Firefox')
        self.img = ImageFactory(title='test.jpg')

    def tearDown(self):
        self.img.delete()

    def test_simple(self):
        """Simple image tag markup."""
        doc = pq(self.p.parse('[[Image:test.jpg]]',
                 locale=settings.WIKI_DEFAULT_LANGUAGE))
        img = doc('img')
        eq_('test.jpg', img.attr('alt'))
        eq_(self.img.file.url, img.attr('data-original-src'))
        assert 'placeholder.gif' in img.attr('src')
Пример #20
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)
Пример #21
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)
Пример #22
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())
Пример #23
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)
Пример #24
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())
Пример #25
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)
Пример #26
0
class TestLazyWikiImageTags(TestCase):
    def setUp(self):
        self.d, self.r, self.p = doc_rev_parser('Test content',
                                                'Installing Firefox')
        self.img = ImageFactory(title='test.jpg')

    def tearDown(self):
        self.img.delete()

    def test_simple(self):
        """Simple image tag markup."""
        doc = pq(
            self.p.parse('[[Image:test.jpg]]',
                         locale=settings.WIKI_DEFAULT_LANGUAGE))
        img = doc('img')
        eq_('test.jpg', img.attr('alt'))
        eq_(self.img.file.url, img.attr('data-original-src'))
        assert 'placeholder.gif' in img.attr('src')
Пример #27
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())
Пример #28
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())
Пример #29
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)
Пример #30
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)
Пример #31
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)
Пример #32
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
Пример #33
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)
Пример #34
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)
Пример #35
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)
Пример #36
0
 def setUp(self):
     self.d, self.r, self.p = doc_rev_parser(
         'Test content', 'Installing Firefox')
     self.img = ImageFactory(title='test.jpg')
Пример #37
0
class TestWikiImageTags(TestCase):
    def setUp(self):
        self.d, self.r, self.p = doc_rev_parser(
            'Test content', 'Installing Firefox')
        self.img = ImageFactory(title='test.jpg')

    def tearDown(self):
        self.img.delete()

    def test_empty(self):
        """Empty image tag markup does not change."""
        img = pq_img(self.p, '[[Image:]]', 'p')
        eq_('The image "" does not exist.', img.text())

    def test_simple(self):
        """Simple image tag markup."""
        img = pq_img(self.p, '[[Image:test.jpg]]', 'img')
        eq_('test.jpg', img.attr('alt'))
        eq_(self.img.file.url, img.attr('src'))

    def test_simple_fallback(self):
        """Fallback to English if current locale doesn't have the image."""
        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'))

    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'))

    def test_caption(self):
        """Give the image a caption."""
        self.img.title = 'img test.jpg'
        self.img.save()
        img_div = pq_img(self.p, '[[Image:img test.jpg|frame|my caption]]',
                         'div.img')
        img = img_div('img')
        caption = img_div.text()

        eq_(self.img.file.url, img.attr('src'))
        eq_('my caption', img.attr('alt'))
        eq_('my caption', caption)

    def test_page_link(self):
        """Link to a wiki page."""
        img_a = pq_img(self.p, '[[Image:test.jpg|page=Installing Firefox]]',
                       'a')
        img = img_a('img')

        eq_('test.jpg', img.attr('alt'))
        eq_(self.img.file.url, img.attr('src'))
        eq_('/en-US/kb/installing-firefox', img_a.attr('href'))

    def test_page_link_edit(self):
        """Link to a nonexistent wiki page."""
        img_a = pq_img(self.p, '[[Image:test.jpg|page=Article List]]', 'a')
        img = img_a('img')

        eq_('test.jpg', img.attr('alt'))
        eq_(self.img.file.url, img.attr('src'))
        assert img_a.hasClass('new')
        eq_('/en-US/kb/new?title=Article+List', img_a.attr('href'))

    def test_page_link_caption(self):
        """Link to a wiki page with caption and frame."""
        img_div = pq_img(self.p,
                         '[[Image:test.jpg|frame|page=A page|my caption]]',
                         'div.img')
        img_a = img_div('a')
        img = img_a('img')
        caption = img_div.text()

        eq_('my caption', img.attr('alt'))
        eq_('my caption', caption)
        eq_(self.img.file.url, img.attr('src'))
        assert img_a.hasClass('new')
        eq_('/en-US/kb/new?title=A+page', img_a.attr('href'))

    def test_link(self):
        """Link to an external page."""
        img_a = pq_img(self.p, '[[Image:test.jpg|link=http://test.com]]', 'a')
        img = img_a('img')

        eq_('test.jpg', img.attr('alt'))
        eq_(self.img.file.url, img.attr('src'))
        eq_('http://test.com', img_a.attr('href'))

    def test_link_caption(self):
        """Link to an external page with caption."""
        img_div = pq_img(self.p,
                         '[[Image:test.jpg|link=http://ab.us|frame|caption]]',
                         'div.img')
        img = img_div('img')
        img_a = img_div('a')

        eq_(self.img.file.url, img.attr('src'))
        eq_('http://ab.us', img_a.attr('href'))

    def test_link_align(self):
        """Link with align."""
        img_div = pq_img(self.p,
                         '[[Image:test.jpg|link=http://site.com|align=left]]',
                         'div.img')
        eq_('img align-left', img_div.attr('class'))

    def test_link_align_invalid(self):
        """Link with invalid align."""
        img = pq_img(self.p,
                     '[[Image:test.jpg|link=http://example.ro|align=inv]]')
        assert 'frameless' in img.attr('class')

    def test_link_valign(self):
        """Link with valign."""
        img = pq_img(self.p,
                     '[[Image:test.jpg|link=http://example.com|valign=top]]')
        eq_('vertical-align: top;', img.attr('style'))

    def test_link_valign_invalid(self):
        """Link with invalid valign."""
        img = pq_img(self.p,
                     '[[Image:test.jpg|link=http://example.com|valign=off]]')
        eq_(None, img.attr('style'))

    def test_alt(self):
        """Image alt attribute is overriden but caption is not."""
        img_div = pq_img(self.p,
                         '[[Image:test.jpg|alt=my alt|frame|my caption]]',
                         'div.img')
        img = img_div('img')
        caption = img_div.text()

        eq_('my alt', img.attr('alt'))
        eq_('my caption', caption)

    def test_alt_empty(self):
        """Image alt attribute can be empty."""
        img = pq_img(self.p, '[[Image:test.jpg|alt=|my caption]]')

        eq_('', img.attr('alt'))

    def test_alt_unsafe(self):
        """Potentially unsafe alt content is escaped."""
        unsafe_vals = (
            ('an"<script>alert()</script>',
             'an&quot;&amp;lt;script&amp;gt;alert()&amp;lt;/script&amp;gt;'),
            ("an'<script>alert()</script>",
             "an'&amp;lt;script&amp;gt;alert()&amp;lt;/script&amp;gt;"),
            ('single\'"double',
             "single'&quot;double"),
        )
        for alt_sent, alt_expected in unsafe_vals:
            img = pq_img(self.p, '[[Image:test.jpg|alt=' + alt_sent + ']]')

            is_true = str(img).startswith('<img alt="' + alt_expected + '"')
            assert is_true, ('Expected "%s", sent "%s"' %
                             (alt_expected, alt_sent))

    def test_width(self):
        """Image width attribute set."""
        img = pq_img(self.p, '[[Image:test.jpg|width=10]]')

        eq_('10', img.attr('width'))

    def test_width_invalid(self):
        """Invalid image width attribute set to auto."""
        img = pq_img(self.p, '[[Image:test.jpg|width=invalid]]')

        eq_(None, img.attr('width'))

    def test_height(self):
        """Image height attribute set."""
        img = pq_img(self.p, '[[Image:test.jpg|height=10]]')

        eq_('10', img.attr('height'))

    def test_height_invalid(self):
        """Invalid image height attribute set to auto."""
        img = pq_img(self.p, '[[Image:test.jpg|height=invalid]]')

        eq_(None, img.attr('height'))

    def test_frame(self):
        """Image has frame if specified."""
        img_div = pq_img(self.p, '[[Image:test.jpg|frame|caption]]', 'div.img')
        assert not img_div('img').hasClass('frameless')
        eq_('caption', img_div('img').attr('alt'))
        eq_('caption', img_div.text())
        eq_(self.img.file.url, img_div('img').attr('src'))

    def test_frameless_link(self):
        """Image has frameless class and link if specified."""
        img_a = pq_img(self.p,
                       '[[Image:test.jpg|page=Installing Firefox]]', 'a')
        img = img_a('img')
        assert 'frameless' in img.attr('class')
        eq_('/en-US/kb/installing-firefox', img_a.attr('href'))