def setup_content(self, portal):
     portal.invokeFactory("News Item", "my-newsitem")
     portal.invokeFactory("Image", "my-image")
     self.newsitem = portal["my-newsitem"]
     self.newsitem.setImage(load_image(1024, 768))
     self.image = portal["my-image"]
     self.image.setImage(load_image(1024, 768))
Beispiel #2
0
 def setup_content(self, portal):
     portal.invokeFactory('News Item', 'my-newsitem')
     portal.invokeFactory('Image', 'my-image')
     self.newsitem = portal['my-newsitem']
     self.newsitem.setImage(load_image(1024, 768))
     self.image = portal['my-image']
     self.image.setImage(load_image(1024, 768))
 def setup_content(self, portal):
     portal.invokeFactory('Document', 'my-document')
     portal.invokeFactory('News Item', 'my-newsitem')
     portal.invokeFactory('News Item', 'my-newsitem-bmp')
     portal.invokeFactory('Image', 'my-image')
     portal.invokeFactory('Image', 'my-image-bmp')
     self.document = portal['my-document']
     self.newsitem = portal['my-newsitem']
     self.newsitem.setImage(load_image(1024, 768))
     self.newsitem_bmp = portal['my-newsitem-bmp']
     self.newsitem_bmp.setImage(load_image(640, 480, format='BMP'))
     self.image = portal['my-image']
     self.image.setImage(load_image(1024, 768))
     self.image_bmp = portal['my-image-bmp']
     self.image_bmp.setImage(load_image(640, 480, format='BMP'))
Beispiel #4
0
    def setUp(self):
        self.portal = self.layer['portal']
        self.request = self.layer['request']

        with api.env.adopt_roles(['Manager']):
            self.obj = api.content.create(
                self.portal, type='News Item', id='foo')
        set_image_field(self.obj, load_image(1024, 768), 'image/png')
    def setUp(self):
        self.portal = self.layer['portal']
        self.request = self.layer['request']

        with api.env.adopt_roles(['Manager']):
            self.obj = api.content.create(
                self.portal, type='News Item', id='foo')
        set_image_field(self.obj, load_image(1024, 768), 'image/png')
    def setUp(self):
        self.portal = self.layer['portal']
        self.request = self.layer['request']

        with api.env.adopt_roles(['Manager']):
            self.news_item = api.content.create(
                self.portal, 'News Item', title=u'Lorem ipsum')
        set_image_field(self.news_item, load_image(1024, 768), 'image/png')
    def setUp(self):
        self.portal = self.layer['portal']
        self.request = self.layer['request']

        with api.env.adopt_roles(['Manager']):
            self.news_item = api.content.create(self.portal,
                                                'News Item',
                                                title=u'Lorem ipsum')
        set_image_field(self.news_item, load_image(1024, 768), 'image/png')
    def test_plugin_view_image(self):
        with api.env.adopt_roles(['Manager']):
            image = api.content.create(self.portal, type='Image', title='bar')
            set_image_field(image, load_image(1024, 768), 'image/png')

        plugin_view = self.plugin.view()
        view = image.restrictedTraverse(plugin_view)

        # At image, use local image
        expected = r'http://nohost/plone/bar/@@images/[0-9a-f--]+.png'
        self.assertRegexpMatches(view.image_url(), expected)
    def test_do_not_validate_on_submit(self):
        # content don't follow best practices
        self.news_item.title = get_random_string(80)
        self.news_item.description = get_random_string(300)
        set_image_field(self.news_item, load_image(200, 150), 'image/png')

        with api.env.adopt_roles(['Manager']):
            api.content.transition(self.news_item, 'submit')

        # no feedback messages present
        messages = IStatusMessage(self.request).show()
        self.assertEqual(len(messages), 0)
    def test_do_not_validate_on_submit(self):
        # content don't follow best practices
        self.news_item.title = get_random_string(80)
        self.news_item.description = get_random_string(300)
        set_image_field(self.news_item, load_image(200, 150), 'image/png')

        with api.env.adopt_roles(['Manager']):
            api.content.transition(self.news_item, 'submit')

        # no feedback messages present
        messages = IStatusMessage(self.request).show()
        self.assertEqual(len(messages), 0)
    def test_plugin_view_image(self):
        with api.env.adopt_roles(['Manager']):
            image = api.content.create(
                self.portal, type='Image', title='bar')
            set_image_field(image, load_image(1024, 768), 'image/png')

        plugin_view = self.plugin.view()
        view = image.restrictedTraverse(plugin_view)

        # At image, use local image
        expected = r'http://nohost/plone/bar/@@images/[0-9a-f--]+.png'
        self.assertRegexpMatches(view.image_url(), expected)
    def setUp(self):
        self.portal = self.layer['portal']

        with api.env.adopt_roles(['Manager']):
            self.newsitem = api.content.create(
                self.portal, type='News Item', title='foo')
            set_image_field(self.newsitem, load_image(1024, 768), 'image/png')

        self.registry = getUtility(IRegistry)
        self.settings = self.registry.forInterface(ISocialLikeSettings)

        self.plugins = dict(getUtilitiesFor(IPlugin))
        self.plugin = self.plugins[name]
Beispiel #13
0
    def test_validate_og_lead_image_invalid_aspect_ratio(self):
        from sc.social.like.utils import MSG_INVALID_OG_LEAD_IMAGE_ASPECT_RATIO

        set_image_field(self.obj, load_image(768, 768, 'JPG'), 'image/jpeg')
        image = get_content_image(self.obj)
        with self.assertRaises(ValueError):
            validate_og_lead_image(image)

        # test validation message
        try:
            validate_og_lead_image(image)
        except ValueError as e:
            self.assertEqual(str(e), MSG_INVALID_OG_LEAD_IMAGE_ASPECT_RATIO)
    def test_validate_on_edit_valid(self):
        with api.env.adopt_roles(['Manager']):
            api.content.transition(self.news_item, 'publish')

        # content follows best practices
        self.news_item.title = get_random_string(70)
        self.news_item.description = get_random_string(200)
        set_image_field(self.news_item, load_image(1920, 1080), 'image/png')
        notify(EditFinishedEvent(self.news_item))

        # no feedback messages present
        messages = IStatusMessage(self.request).show()
        self.assertEqual(len(messages), 0)
    def test_validate_on_edit_valid(self):
        with api.env.adopt_roles(['Manager']):
            api.content.transition(self.news_item, 'publish')

        # content follows best practices
        self.news_item.title = get_random_string(70)
        self.news_item.description = get_random_string(200)
        set_image_field(self.news_item, load_image(1920, 1080), 'image/png')
        notify(EditFinishedEvent(self.news_item))

        # no feedback messages present
        messages = IStatusMessage(self.request).show()
        self.assertEqual(len(messages), 0)
Beispiel #16
0
    def test_validate_og_lead_image_invalid_aspect_ratio(self):
        from sc.social.like.utils import MSG_INVALID_OG_LEAD_IMAGE_ASPECT_RATIO

        set_image_field(self.obj, load_image(768, 768, 'JPG'), 'image/jpeg')
        image = get_content_image(self.obj)
        with self.assertRaises(ValueError):
            validate_og_lead_image(image)

        # test validation message
        try:
            validate_og_lead_image(image)
        except ValueError as e:
            self.assertEqual(str(e), MSG_INVALID_OG_LEAD_IMAGE_ASPECT_RATIO)
    def setUp(self):
        self.portal = self.layer['portal']

        with api.env.adopt_roles(['Manager']):
            self.newsitem = api.content.create(self.portal,
                                               type='News Item',
                                               title='foo')
            set_image_field(self.newsitem, load_image(1024, 768), 'image/png')

        self.registry = getUtility(IRegistry)
        self.settings = self.registry.forInterface(ISocialLikeSettings)

        self.plugins = dict(getUtilitiesFor(IPlugin))
        self.plugin = self.plugins[name]
    def test_plugin_view_newsitem_large(self):
        plugin = self.plugin
        newsitem = self.newsitem
        newsitem.setImage(load_image(1920, 1080))

        plugin_view = plugin.view()
        view = newsitem.restrictedTraverse(plugin_view)

        # At newsitem, use image
        image_url = view.image_url()
        self.assertNotIn('logo.png', image_url)

        self.assertEqual(view.image_width(), 1200)
        self.assertEqual(view.image_height(), 675)
    def test_validate_on_publish_invalid(self):
        # content don't follow best practices
        self.news_item.title = get_random_string(80)
        self.news_item.description = get_random_string(300)
        set_image_field(self.news_item, load_image(200, 150), 'image/png')

        with api.env.adopt_roles(['Manager']):
            api.content.transition(self.news_item, 'publish')

        # feedback messages present
        messages = IStatusMessage(self.request).show()
        self.assertEqual(len(messages), 3)
        self.assertEqual(messages[0].message, MSG_INVALID_OG_TITLE)
        self.assertEqual(messages[0].type, u'warning')
        self.assertEqual(messages[1].message, MSG_INVALID_OG_DESCRIPTION)
        self.assertEqual(messages[1].type, u'warning')
        self.assertEqual(messages[2].message, MSG_INVALID_OG_LEAD_IMAGE_DIMENSIONS)
        self.assertEqual(messages[2].type, u'warning')
    def test_validate_on_no_workflow(self):
        # image and files have no associated workflow
        with api.env.adopt_roles(['Manager']):
            image = api.content.create(self.portal, 'Image', id='foo')

        # content don't follow best practices
        image.title = get_random_string(80)
        image.description = get_random_string(300)
        set_image_field(image, load_image(200, 150), 'image/png')
        notify(EditFinishedEvent(image))

        # feedback messages present
        messages = IStatusMessage(self.request).show()
        self.assertEqual(messages[0].message, MSG_INVALID_OG_TITLE)
        self.assertEqual(messages[0].type, u'warning')
        self.assertEqual(messages[1].message, MSG_INVALID_OG_DESCRIPTION)
        self.assertEqual(messages[1].type, u'warning')
        self.assertEqual(messages[2].message, MSG_INVALID_OG_LEAD_IMAGE_DIMENSIONS)
        self.assertEqual(messages[2].type, u'warning')
    def test_validate_on_publish_invalid(self):
        # content don't follow best practices
        self.news_item.title = get_random_string(80)
        self.news_item.description = get_random_string(300)
        set_image_field(self.news_item, load_image(200, 150), 'image/png')

        with api.env.adopt_roles(['Manager']):
            api.content.transition(self.news_item, 'publish')

        # feedback messages present
        messages = IStatusMessage(self.request).show()
        self.assertEqual(len(messages), 3)
        self.assertEqual(messages[0].message, MSG_INVALID_OG_TITLE)
        self.assertEqual(messages[0].type, u'warning')
        self.assertEqual(messages[1].message, MSG_INVALID_OG_DESCRIPTION)
        self.assertEqual(messages[1].type, u'warning')
        self.assertEqual(messages[2].message,
                         MSG_INVALID_OG_LEAD_IMAGE_DIMENSIONS)
        self.assertEqual(messages[2].type, u'warning')
    def test_validate_on_no_workflow(self):
        # image and files have no associated workflow
        with api.env.adopt_roles(['Manager']):
            image = api.content.create(self.portal, 'Image', id='foo')

        # content don't follow best practices
        image.title = get_random_string(80)
        image.description = get_random_string(300)
        set_image_field(image, load_image(200, 150), 'image/png')
        notify(EditFinishedEvent(image))

        # feedback messages present
        messages = IStatusMessage(self.request).show()
        self.assertEqual(messages[0].message, MSG_INVALID_OG_TITLE)
        self.assertEqual(messages[0].type, u'warning')
        self.assertEqual(messages[1].message, MSG_INVALID_OG_DESCRIPTION)
        self.assertEqual(messages[1].type, u'warning')
        self.assertEqual(messages[2].message,
                         MSG_INVALID_OG_LEAD_IMAGE_DIMENSIONS)
        self.assertEqual(messages[2].type, u'warning')
    def test_plugin_view_image_bmp(self):
        plugin = self.plugin
        image = self.image_bmp

        plugin_view = plugin.view()
        view = image.restrictedTraverse(plugin_view)

        # At image, use local image
        image_url = view.image_url()
        self.assertNotIn('logo.png', image_url)
        self.assertEqual(view.image_width(), 640)
        self.assertEqual(view.image_height(), 480)

        # Set a larger image
        image.setImage(load_image(1920, 1080))

        plugin_view = plugin.view()
        view = image.restrictedTraverse(plugin_view)

        self.assertEqual(view.image_width(), 1200)
        self.assertEqual(view.image_height(), 675)