Example #1
0
 def test_does_not_change_external_id_when_already_set(self):
     meta = zeit.content.image.interfaces.IImageMetadata(self.group)
     meta.external_id = u'12345'
     self.group['6789.jpg'] = create_local_image('opernball.jpg')
     zope.event.notify(
         zope.lifecycleevent.ObjectAddedEvent(self.traverse('6789.jpg')))
     self.assertEqual('12345', meta.external_id)
Example #2
0
 def test_thumbnail_is_removed_on_delete(self):
     self.group['second'] = create_local_image('new-hampshire-450x200.jpg')
     self.thumbnails.THUMBNAIL_WIDTH = 100
     self.thumbnails.source_image(self.group['second'])
     del self.group['second']
     self.assertEqual(
         ['master-image.jpg', 'thumbnail-source-master-image.jpg'],
         self.group.keys())
 def test_getitem_can_scale_materialized_files_for_new_syntax(self):
     master = PIL.Image.open(self.group['540x304__80x80'].open())
     master_sample = master.getpixel((40, 20))
     self.group['master-image-540x304.jpg'] = create_local_image(
         'obama-clinton-120x120.jpg')
     materialized = PIL.Image.open(self.group['540x304__80x80'].open())
     materialized_sample = materialized.getpixel((40, 20))
     self.assertNotEqual(master_sample, materialized_sample)
     self.assertEqual((80, 80), materialized.size)
Example #4
0
 def test_uses_image_defined_for_viewport_mobile_when_given(self):
     self.group['master-image-mobile.jpg'] = create_local_image(
         'obama-clinton-120x120.jpg')
     with mock.patch(
             'zeit.content.image.imagegroup.ImageGroupBase.master_images',
             new_callable=mock.PropertyMock) as master_images:
         master_images.return_value = (('desktop', 'master-image.jpg'),
                                       ('mobile',
                                        'master-image-mobile.jpg'))
         self.assertEqual(self.group['master-image-mobile.jpg'],
                          self.thumbnails.master_image('square__mobile'))
    def test_gives_error_if_required_image_scale_is_missing(self):
        r = Rule(
            """
applicable(imagegroup)
error_if('120x120' not in provided_scales, u'Scale 120x120 is missing')
"""
        )
        s = r.apply(self.group, IRuleGlobs(self.group))  # error since scale is missing
        self.assertEquals(zeit.edit.rule.ERROR, s.status)

        self.repository["group"]["group-120x120.jpg"] = create_local_image("new-hampshire-artikel.jpg")
        s = r.apply(self.group, IRuleGlobs(self.group))  # added scale, no error anymore
        self.assertNotEquals(zeit.edit.rule.ERROR, s.status)
Example #6
0
 def test_getitem_chooses_master_image_using_given_viewport(self):
     """Uses master-image for desktop and master-image-mobile for mobile."""
     self.group['master-image-mobile.jpg'] = create_local_image(
         'obama-clinton-120x120.jpg')
     with mock.patch(
             'zeit.content.image.imagegroup.ImageGroupBase.master_images',
             new_callable=mock.PropertyMock) as master_images:
         master_images.return_value = (('desktop', 'master-image.jpg'),
                                       ('mobile',
                                        'master-image-mobile.jpg'))
         self.assertEqual('master-image.jpg',
                          self.group['square__desktop'].variant_source)
         self.assertEqual('master-image-mobile.jpg',
                          self.group['square__mobile'].variant_source)
Example #7
0
    def test_gives_error_if_required_image_scale_is_missing(self):
        r = Rule("""
applicable(imagegroup)
error_if('120x120' not in provided_scales, u'Scale 120x120 is missing')
""")
        s = r.apply(  # error since scale is missing
            self.group, IRuleGlobs(self.group))
        self.assertEquals(zeit.edit.rule.ERROR, s.status)

        self.repository['group']['group-120x120.jpg'] = create_local_image(
            'new-hampshire-artikel.jpg')
        s = r.apply(  # added scale, no error anymore
            self.group, IRuleGlobs(self.group))
        self.assertNotEquals(zeit.edit.rule.ERROR, s.status)
Example #8
0
    def test_imagegroup_is_only_applicable_for_IImageGroup(self):
        r = Rule("""
applicable(imagegroup)
error_if(True, u'Context is an ImageGroup')
""")
        # applicable for image group
        s = r.apply(self.group, IRuleGlobs(self.group))
        self.assertEquals(zeit.edit.rule.ERROR, s.status)

        # not applicable for image
        self.repository['group']['group-120x120.jpg'] = create_local_image(
            'new-hampshire-artikel.jpg')
        s = r.apply(self.group['group-120x120.jpg'],
                    IRuleGlobs(self.group['group-120x120.jpg']))
        self.assertNotEquals(zeit.edit.rule.ERROR, s.status)
    def test_imagegroup_is_only_applicable_for_IImageGroup(self):
        r = Rule(
            """
applicable(imagegroup)
error_if(True, u'Context is an ImageGroup')
"""
        )
        # applicable for image group
        s = r.apply(self.group, IRuleGlobs(self.group))
        self.assertEquals(zeit.edit.rule.ERROR, s.status)

        # not applicable for image
        self.repository["group"]["group-120x120.jpg"] = create_local_image("new-hampshire-artikel.jpg")
        s = r.apply(self.group["group-120x120.jpg"], IRuleGlobs(self.group["group-120x120.jpg"]))
        self.assertNotEquals(zeit.edit.rule.ERROR, s.status)
 def test_getitem_returns_materialized_files_for_new_syntax(self):
     self.group['master-image-540x304.jpg'] = create_local_image(
         'obama-clinton-120x120.jpg')
     image = self.group['540x304']
     self.assertTrue(zeit.content.image.interfaces.IImage.providedBy(image))
     self.assertEqual((120, 120), image.getImageSize())
 def test_uses_materialized_image_if_present(self):
     from zeit.content.image.testing import create_local_image
     self.group['image-540x304.jpg'] = create_local_image(
         'obama-clinton-120x120.jpg')
     self.assertEqual(self.group['image-540x304.jpg'],
                      self.thumbnail._find_image())
Example #12
0
 def test_ignores_stored_dav_mime_type(self):
     self.repository['image'] = create_local_image('opernball.jpg')
     with checked_out(self.repository['image']) as co:
         props = zeit.connector.interfaces.IWebDAVProperties(co)
         props[('getcontenttype', 'DAV:')] = 'image/png'
     self.assertEqual('image/jpeg', self.repository['image'].mimeType)
 def test_getitem_returns_materialized_files_for_new_syntax(self):
     self.group["master-image-540x304.jpg"] = create_local_image("obama-clinton-120x120.jpg")
     image = self.group["540x304"]
     self.assertTrue(zeit.content.image.interfaces.IImage.providedBy(image))
     self.assertEqual((120, 120), image.getImageSize())