예제 #1
0
 def test_image_search(self):
     image(title='fx2-quicktimeflash.png')
     image(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_draft_shows(self):
     """The image draft is loaded for this user."""
     image(title=get_draft_title(self.u), creator=self.u)
     response = get(self.client, 'gallery.gallery', args=['image'])
     eq_(200, response.status_code)
     doc = pq(response.content)
     assert doc('.image-preview img').attr('src').endswith('098f6b.jpg')
     eq_(1, doc('.image-preview img').length)
예제 #3
0
 def test_image_draft_shows(self):
     """The image draft is loaded for this user."""
     image(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("098f6b.jpg")
     eq_(1, doc(".file.preview img").length)
예제 #4
0
 def test_image_draft_shows(self):
     """The image draft is loaded for this user."""
     image(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('098f6b.jpg')
     eq_(1, doc('.file.preview img').length)
예제 #5
0
 def test_button_image_for_nesting(self):
     """You can nest [[Image:]] inside {for} inside {button}."""
     image(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)
예제 #6
0
 def test_image_draft_post(self):
     """Posting to the page saves the field values for the image draft."""
     image(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())
     eq_("test", doc('#gallery-upload-modal input[name="title"]').val())
예제 #7
0
 def test_button_image_for_nesting(self):
     """You can nest [[Image:]] inside {for} inside {button}."""
     image(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)
예제 #8
0
 def test_button_image_for_nesting(self):
     """You can nest [[Image:]] inside {for} inside {button}."""
     image(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)
예제 #9
0
 def test_image_draft_post(self):
     """Posting to the page saves the field values for the image draft."""
     image(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())
     eq_('test', doc('#gallery-upload-modal input[name="title"]').val())
예제 #10
0
 def test_image_draft_post(self):
     """Posting to the page saves the field values for the image draft."""
     image(title=get_draft_title(self.u), 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())
     eq_('test', doc('#gallery-upload-modal input[name="title"]').val())
예제 #11
0
    def test_upload_draft(self):
        """Uploading draft works, sets locale too."""
        u = User.objects.get(username='******')
        image(creator=u, title=get_draft_title(u))

        r = post(self.client, 'gallery.upload',
                 {'locale': 'de', 'title': 'Hasta la vista',
                  'description': 'Auf wiedersehen!'},
                 args=['image'])

        eq_(200, r.status_code)
        img = Image.objects.all()[0]
        eq_('de', img.locale)
        eq_('Hasta la vista', img.title)
        eq_('Auf wiedersehen!', img.description)
예제 #12
0
    def test_edit_image_without_permissions(self):
        """Can't edit an image I didn't create."""
        u = User.objects.get(username="******")
        img = image(creator=u)
        r = post(self.client, "gallery.edit_media", {"description": "arrr"}, args=["image", img.id])

        eq_(403, r.status_code)
예제 #13
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('data-original-src'))
        eq_(placeholder_image, img.attr('src'))

        # then, create an English version
        en_img = image(title='test.jpg')
        # 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('data-original-src'))
        eq_(placeholder_image, 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('data-original-src'))
        eq_(placeholder_image, img.attr('src'))
예제 #14
0
파일: test_parser.py 프로젝트: ibai/kitsune
    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('data-original-src'))
        eq_(placeholder_image, img.attr('src'))

        # then, create an English version
        en_img = image(title='test.jpg')
        # 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('data-original-src'))
        eq_(placeholder_image, 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('data-original-src'))
        eq_(placeholder_image, img.attr('src'))
예제 #15
0
    def test_gallery_locale(self):
        """Test that images only show for their set locale."""
        image(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))
예제 #16
0
    def test_gallery_locale(self):
        """Test that images only show for their set locale."""
        image(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))
예제 #17
0
 def test_image_title_locale_unique_validation(self):
     """Posting an existing locale/title combination shows a validation
     error."""
     image(creator=self.user, is_draft=True, title='Some title')
     post(self.client, 'gallery.upload',
          {'locale': 'de', 'title': 'Hasta la vista',
           'description': 'Auf wiedersehen!'}, args=['image'])
     image(creator=self.user, is_draft=True, title='Some title')
     r = post(self.client, 'gallery.upload',
              {'locale': 'de', 'title': 'Hasta la vista',
               'description': 'Auf wiedersehen!'},
              args=['image'])
     eq_(200, r.status_code)
     doc = pq(r.content)
     msg = 'Image with this Locale and Title already exists.'
     assert doc('ul.errorlist li').text().startswith(msg)
예제 #18
0
    def test_thumbnail_url_if_set(self):
        """thumbnail_url_if_set() returns self.thumbnail if set, or else
        returns self.file"""
        img = image()
        eq_(img.file.url, img.thumbnail_url_if_set())

        generate_thumbnail(img, 'file', 'thumbnail')
        eq_(img.thumbnail.url, img.thumbnail_url_if_set())
예제 #19
0
    def test_schedule_rebuild_kb_on_delete(self, schedule_rebuild_kb):
        """KB rebuild scheduled on delete"""
        im = image()
        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
예제 #20
0
    def test_edit_own_image(self):
        """Can edit an image I created."""
        u = User.objects.get(username="******")
        img = image(creator=u)
        r = post(self.client, "gallery.edit_media", {"description": "arrr"}, args=["image", img.id])

        eq_(200, r.status_code)
        eq_("arrr", Image.uncached.get().description)
예제 #21
0
    def test_edit_image_with_permissions(self):
        """Editing image sets the updated_by field."""
        self.client.login(username="******", password="******")
        img = image()
        r = post(self.client, "gallery.edit_media", {"description": "arrr"}, args=["image", img.id])

        eq_(200, r.status_code)
        eq_("admin", Image.objects.get().updated_by.username)
예제 #22
0
    def test_delete_image(self):
        """Deleting an uploaded image works."""
        # Upload the image first
        im = image()
        r = post(self.client, 'gallery.delete_media', args=['image', im.id])

        eq_(200, r.status_code)
        eq_(0, Image.objects.count())
예제 #23
0
    def test_thumbnail_url_if_set(self):
        """thumbnail_url_if_set() returns self.thumbnail if set, or else
        returns self.file"""
        img = image()
        eq_(img.file.url, img.thumbnail_url_if_set())

        generate_thumbnail(img, 'file', 'thumbnail')
        eq_(img.thumbnail.url, img.thumbnail_url_if_set())
예제 #24
0
    def test_delete_image_without_permissions(self):
        """Can't delete an image I didn't create."""
        self.client.login(username='******', password='******')
        img = image()
        r = post(self.client, 'gallery.delete_media', args=['image', img.id])

        eq_(403, r.status_code)
        eq_(1, Image.objects.count())
예제 #25
0
    def test_edit_image_without_permissions(self):
        """Can't edit an image I didn't create."""
        u = User.objects.get(username='******')
        img = image(creator=u)
        r = post(self.client, 'gallery.edit_media', {'description': 'arrr'},
                 args=['image', img.id])

        eq_(403, r.status_code)
예제 #26
0
 def test_image_title_locale_unique_validation(self):
     """Posting an existing locale/title combination shows a validation
     error."""
     u = User.objects.get(username='******')
     image(creator=u, title=get_draft_title(u))
     post(self.client, 'gallery.upload',
          {'locale': 'de', 'title': 'Hasta la vista',
           'description': 'Auf wiedersehen!'}, args=['image'])
     image(creator=u, title=get_draft_title(u))
     r = post(self.client, 'gallery.upload',
              {'locale': 'de', 'title': 'Hasta la vista',
               'description': 'Auf wiedersehen!'},
              args=['image'])
     eq_(200, r.status_code)
     doc = pq(r.content)
     msg = 'Image with this Locale and Title already exists.'
     assert doc('ul.errorlist li').text().startswith(msg)
예제 #27
0
 def test_image_media_page(self):
     """Test the media page."""
     img = image()
     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"])
예제 #28
0
    def test_edit_image_without_permissions(self):
        """Can't edit an image I didn't create."""
        img = image()
        u = user(save=True)
        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)
예제 #29
0
    def test_delete_own_image(self):
        """Can delete an image I created."""
        self.client.login(username='******', password='******')
        u = User.objects.get(username='******')
        img = image(creator=u)
        r = post(self.client, 'gallery.delete_media', args=['image', img.id])

        eq_(200, r.status_code)
        eq_(0, Image.objects.count())
예제 #30
0
    def test_delete_own_image(self):
        """Can delete an image I created."""
        self.client.login(username="******", password="******")
        u = User.objects.get(username="******")
        img = image(creator=u)
        r = post(self.client, "gallery.delete_media", args=["image", img.id])

        eq_(200, r.status_code)
        eq_(0, Image.objects.count())
예제 #31
0
 def test_image_media_page(self):
     """Test the media page."""
     img = image()
     response = self.client.get(img.get_absolute_url(), follow=True)
     eq_(200, response.status_code)
     doc = pq(response.content)
     eq_(img.title, doc('#media-object h1').text())
     eq_(img.description, doc('#media-object div.description').text())
     eq_(img.file.url, doc('#media-view img')[0].attrib['src'])
예제 #32
0
    def test_edit_own_image(self):
        """Can edit an image I created."""
        u = User.objects.get(username='******')
        img = image(creator=u)
        r = post(self.client, 'gallery.edit_media', {'description': 'arrr'},
                 args=['image', img.id])

        eq_(200, r.status_code)
        eq_('arrr', Image.uncached.get().description)
예제 #33
0
    def test_edit_image_with_permissions(self):
        """Editing image sets the updated_by field."""
        self.client.login(username='******', password='******')
        img = image()
        r = post(self.client, 'gallery.edit_media', {'description': 'arrr'},
                 args=['image', img.id])

        eq_(200, r.status_code)
        eq_('admin', Image.objects.get().updated_by.username)
예제 #34
0
 def test_gallery_image_list(self):
     """Test for ajax endpoint without search parameter."""
     img = image()
     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'])
예제 #35
0
    def test_delete_image(self):
        """Deleting an uploaded image works."""
        im = image()
        u = user(save=True)
        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())
예제 #36
0
    def test_edit_own_image(self):
        """Can edit an image I created."""
        u = user(save=True)
        img = image(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.uncached.get().description)
예제 #37
0
 def test_gallery_image_list(self):
     """Test for ajax endpoint without search parameter."""
     img = image()
     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"])
예제 #38
0
    def test_edit_image_with_permissions(self):
        """Editing image sets the updated_by field."""
        img = image()
        u = user(save=True)
        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)
예제 #39
0
    def test_schedule_rebuild_kb_on_delete(self, schedule_rebuild_kb):
        """KB rebuild scheduled on delete"""
        im = image()
        u = user(save=True)
        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
예제 #40
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 = image()
        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'])
예제 #41
0
    def test_upload_draft_image(self):
        """Uploading draft image works, sets locale too."""
        u = User.objects.get(username='******')
        img = image(creator=u, title=get_draft_title(u))
        # No thumbnail yet.
        eq_(None, img.thumbnail)

        r = post(self.client, 'gallery.upload',
                 {'locale': 'de', 'title': 'Hasta la vista',
                  'description': 'Auf wiedersehen!'},
                 args=['image'])

        eq_(200, r.status_code)
        img = Image.objects.all()[0]
        eq_('de', img.locale)
        eq_('Hasta la vista', img.title)
        eq_('Auf wiedersehen!', img.description)
        # Thumbnail generated after form is saved.
        eq_(90, img.thumbnail.width)
예제 #42
0
 def test_new_image(self):
     """New Image is created and saved"""
     img = image()
     eq_('Some title', img.title)
     eq_(150, img.file.width)
     eq_(200, img.file.height)
예제 #43
0
 def test_check_not_own_object(self):
     """tagger cannot delete an image s/he doesn't own."""
     img = image()
     fn = lambda: check_media_permissions(img, self.user, 'delete')
     self.assertRaises(PermissionDenied, fn)
예제 #44
0
파일: test_parser.py 프로젝트: ibai/kitsune
 def setUp(self):
     self.d, self.r, self.p = doc_rev_parser('Test content',
                                             'Installing Firefox')
     self.img = image(title='test.jpg')
예제 #45
0
 def test_get_media_info_image(self):
     """Gets image and format info."""
     img = image()
     info_img, info_format = _get_media_info(img.pk, 'image')
     eq_(img.pk, info_img.pk)
     eq_('jpeg', info_format)