Exemplo n.º 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')))
Exemplo n.º 2
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)
Exemplo n.º 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)
Exemplo n.º 4
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)
Exemplo n.º 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)
Exemplo n.º 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().strip())
     eq_('test', doc('#gallery-upload-modal input[name="title"]').val())
Exemplo n.º 7
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())
Exemplo n.º 8
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))
Exemplo n.º 9
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)
Exemplo n.º 10
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 = 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('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'))
Exemplo n.º 11
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 = 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('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'))
Exemplo n.º 12
0
    def test_images(self):
        img = image(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)
Exemplo n.º 13
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))
Exemplo n.º 14
0
    def test_images(self):
        img = image(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)
Exemplo n.º 15
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())
Exemplo n.º 16
0
    def test_delete_own_image(self):
        """Can delete an image I created."""
        u = user(save=True)
        self.client.login(username=u.username, password='******')
        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())
Exemplo n.º 17
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'])
Exemplo n.º 18
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)
Exemplo n.º 19
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'])
Exemplo n.º 20
0
    def test_delete_image_without_permissions(self):
        """Can't delete an image I didn't create."""
        img = image()
        u = user(save=True)
        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())
Exemplo n.º 21
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'])
Exemplo n.º 22
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'])
Exemplo n.º 23
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())
Exemplo n.º 24
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)
Exemplo n.º 25
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)
Exemplo n.º 26
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
Exemplo 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 = 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'])
Exemplo n.º 28
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'])
Exemplo n.º 29
0
 def test_search_description(self):
     image(description='This image was automatically migrated')
     image(description='This image was automatically migrated')
     image(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')))
Exemplo n.º 30
0
    def test_upload_draft_image(self):
        """Uploading draft image works, sets locale too."""
        img = image(creator=self.user, is_draft=True)
        # 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)
        eq_(None, img.is_draft)
Exemplo n.º 31
0
 def test_check_not_own_object(self):
     """tagger cannot delete an image s/he doesn't own."""
     img = image()
     # This should raise
     check_media_permissions(img, self.user, 'delete')
Exemplo n.º 32
0
 def test_new_image(self):
     """New Image is created and saved"""
     img = image(title='Some title')
     eq_('Some title', img.title)
     eq_(150, img.file.width)
     eq_(200, img.file.height)
Exemplo n.º 33
0
 def test_check_not_own_object(self):
     """tagger cannot delete an image s/he doesn't own."""
     img = image()
     # This should raise
     check_media_permissions(img, self.user, 'delete')
Exemplo n.º 34
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)
Exemplo n.º 35
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)
Exemplo n.º 36
0
 def setUp(self):
     self.d, self.r, self.p = doc_rev_parser('Test content',
                                             'Installing Firefox')
     self.img = image(title='test.jpg')
Exemplo n.º 37
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)
Exemplo n.º 38
0
 def setUp(self):
     self.d, self.r, self.p = doc_rev_parser(
         'Test content', 'Installing Firefox')
     self.img = image(title='test.jpg')