Skip to content

Commit

Permalink
Corrige #136.
Browse files Browse the repository at this point in the history
#136

Evita que dê erro no servidor caso o usuário cadastre um objeto do tipo
collective.nitf sem imagem no mediacarousel (Carrossel Multimídia).
  • Loading branch information
idgserpro committed Feb 16, 2016
1 parent 2b7b3bf commit 69cc0c8
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 5 deletions.
10 changes: 8 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ Alterações

.. Warning::
A estrutura de dados do tile "Destaque" foi alterada. Se você tiver algum
tile desse tipo em sua capa, ele não será renderizada até que o upgradeStep
tile desse tipo em sua capa, ele não será renderizado até que o upgradeStep
de brasil.gov.tiles seja executado. Execute também os upgradeSteps de
collective.cover uma vez que collective.cover não é mais pinado no
buildout.cfg.
buildout.cfg e as versões mais novas no momento desse release de
brasil.gov.tiles contém upgrades.

- Corrige capa quebrada quando uma notícia (collective.nitf) sem imagem é
adicionada num MediaCarouselTile. (closes `#136`).
[idgserpro]

- Corrige teste quando se utiliza collective.cover 1.0a11 (closes `#132`).
[idgserpro]
Expand Down Expand Up @@ -267,3 +272,4 @@ Alterações
.. _`#120`: https://github.com/plonegovbr/brasil.gov.tiles/issues/120
.. _`#123`: https://github.com/plonegovbr/brasil.gov.tiles/issues/123
.. _`#132`: https://github.com/plonegovbr/brasil.gov.tiles/issues/132
.. _`#136`: https://github.com/plonegovbr/brasil.gov.tiles/issues/136
38 changes: 38 additions & 0 deletions src/brasil/gov/tiles/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@
from App.Common import package_home
from PIL import Image
from StringIO import StringIO
from plone import api
from plone.app.robotframework.testing import AUTOLOGIN_LIBRARY_FIXTURE
from plone.app.testing import FunctionalTesting
from plone.app.testing import IntegrationTesting
from plone.app.testing import PLONE_FIXTURE
from plone.app.testing import PloneSandboxLayer
from plone.app.testing import TEST_USER_ID
from plone.app.testing import TEST_USER_NAME
from plone.app.testing import login
from plone.app.testing import logout
from plone.app.testing import setRoles
from plone.testing import z2

import os
Expand Down Expand Up @@ -79,6 +85,10 @@ def setUpZope(self, app, configurationContext):
self.loadZCML(name='overrides.zcml', package=brasil.gov.tiles)

def setUpPloneSite(self, portal):

setRoles(portal, TEST_USER_ID, ['Manager'])
login(portal, TEST_USER_NAME)

# Install into Plone site using portal_setup
self.applyProfile(portal, 'collective.cover:default')
self.applyProfile(portal, 'collective.cover:testfixture')
Expand All @@ -90,6 +100,32 @@ def setUpPloneSite(self, portal):
portal['my-file'].setFile(loadFile('lorem_ipsum.txt'))
portal['my-file'].reindexObject()
portal['my-news-item'].setImage(generate_jpeg(50, 50))

api.content.create(
type='Folder',
title='my-news-folder',
container=portal
)
api.content.create(
type='collective.nitf.content',
title='my-nitf-without-image',
container=portal['my-news-folder']
)
api.content.create(
type='collective.nitf.content',
title='my-nitf-with-image',
container=portal['my-news-folder']
)
api.content.create(
type='Image',
title='my-image',
container=portal['my-news-folder']['my-nitf-with-image']
).setImage(generate_jpeg(50, 50))
portal['my-news-folder'].reindexObject()
portal['my-news-folder']['my-nitf-with-image'].reindexObject()
portal['my-news-folder']['my-nitf-without-image'].reindexObject()
portal['my-news-folder']['my-nitf-with-image']['my-image'].reindexObject() # NOQA

portal_workflow = portal.portal_workflow
portal_workflow.setChainForPortalTypes(['Collection'],
['plone_workflow'],)
Expand All @@ -98,6 +134,8 @@ def setUpPloneSite(self, portal):
if portal_kss:
portal_kss.getResource('++resource++plone.app.z3cform').setEnabled(False) # NOQA

logout()

FIXTURE = Fixture()
INTEGRATION_TESTING = IntegrationTesting(
bases=(FIXTURE,),
Expand Down
48 changes: 48 additions & 0 deletions src/brasil/gov/tiles/tests/test_mediacarousel_tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
from brasil.gov.tiles.tiles.mediacarousel import MediaCarouselTile
from collective.cover.tests.base import TestTileMixin
from mock import Mock
from plone import api
from plone.app.imaging.interfaces import IImageScale
from plone.app.testing import TEST_USER_ID
from plone.app.testing import TEST_USER_NAME
from plone.app.testing import login
from plone.app.testing import setRoles
from zope.component import getMultiAdapter

import unittest

Expand Down Expand Up @@ -101,6 +103,24 @@ def test_thumbnail(self):
obj = self.portal['my-file']
self.assertFalse(self.tile.thumbnail(obj))

# nitf with Image, we should have a thumbnail
obj = self.portal['my-news-folder']['my-nitf-with-image']
[image_child] = [i for i in api.content.find(context=obj,
depth=1, portal_type='Image')]
thumbnail = self.tile.thumbnail(image_child.getObject())
self.assertTrue(thumbnail)
# the thumbnail is an ImageScale
self.assertTrue(IImageScale.providedBy(thumbnail))

# nitf without Image, we shouldn't have a thumbnail
obj = self.portal['my-news-folder']['my-nitf-without-image']
[image_child] = [i for i in api.content.find(context=obj,
depth=1, portal_type='Image')] or [None]
thumbnail = self.tile.thumbnail(image_child)
self.assertFalse(thumbnail)
# the thumbnail is an ImageScale
self.assertFalse(IImageScale.providedBy(thumbnail))

# as an Image does have an image field, we should have a thumbnail
obj = self.portal['my-image']
thumbnail = self.tile.thumbnail(obj)
Expand All @@ -118,3 +138,31 @@ def test_thumbnail(self):
self.assertTrue(self.tile.thumbnail(obj))

# TODO: test against Dexterity-based content types

def test_crud_nitf(self):
# we start with an empty tile
self.assertTrue(self.tile.is_empty())

# now we add a couple of nitf objects in a folder to the carousel
obj1 = self.portal['my-news-folder']
self.tile.populate_with_object(obj1)

# tile's data attributed is cached so we should re-instantiate the tile
tile = getMultiAdapter(
(self.cover, self.request),
name=self.tile.__name__
)
tile = tile['test']

self.assertEqual(len(tile.data['uuids']), 1)
self.assertTrue(obj1 in tile.results())

# finally, we remove it from the carousel; the tile must be empty again
tile.remove_item(obj1.UID())
# tile's data attributed is cached so we should re-instantiate the tile
tile = getMultiAdapter(
(self.cover, self.request),
name=self.tile.__name__
)
tile = tile['test']
self.assertTrue(tile.is_empty())
31 changes: 31 additions & 0 deletions src/brasil/gov/tiles/tests/test_mediacarousel_tile.robot
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ Suite Teardown Close all browsers

${mediacarousel_tile_location} 'mediacarousel'
${collection_selector} .ui-draggable .contenttype-collection
# This xpath selector is for the <a> father of <span>my-news-folder</span>
${my_news_folder_selector} //span[contains(text(),'my-news-folder')]/..
${title_nitf_with_image} my-nitf-with-image
${title_nitf_without_image} my-nitf-without-image
${tile_selector} div.tile-container div.tile
${edit_link_selector} a.edit-tile-link
${title_field_id} mediacarousel-header
Expand Down Expand Up @@ -111,3 +115,30 @@ Test Mediacarousel Tile
Edit Cover Layout
Delete Tile
Save Cover Layout

# add a mediacarousel tile to the layout
Edit Cover Layout
Wait until page contains Export layout
Add Tile ${mediacarousel_tile_location}
Save Cover Layout

# as tile is empty, we see default message
Compose Cover
Page Should Contain Drag a folder or collection to populate the tile.

# drag&drop a folder with nitf content
Open Content Chooser
Click Link link=Content tree
Drag And Drop xpath=${my_news_folder_selector} css=${tile_selector}
Wait Until Page Contains Element css=div.mediacarousel.tile-content h2.mediacarousel-tile+div
Wait Until Page Contains ${title_nitf_with_image}
Page Should Not Contain ${title_nitf_without_image}

# move to the default view and check tile persisted
Click Link link=View
Page Should Contain Element css=div.mediacarousel.tile-content h2.mediacarousel-tile

# delete the tile
Edit Cover Layout
Delete Tile
Save Cover Layout
9 changes: 6 additions & 3 deletions src/brasil/gov/tiles/tiles/mediacarousel.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class MediaCarouselTile(ListTile):
is_editable = True

def populate_with_object(self, obj):
super(ListTile, self).populate_with_object(obj) # check permission
super(ListTile, self).populate_with_object(obj) # check permission # NOQA

# here we should check if the embeded item has its a video
# XXX
Expand Down Expand Up @@ -123,7 +123,10 @@ def get_media_url(self, obj):
url = obj.absolute_url() + '/@@images/image'
elif portal_type == 'collective.nitf.content':
scale = self.scale(obj)
url = scale.url
if scale is not None:
url = scale.url
else:
url = obj.absolute_url()

return url

Expand All @@ -137,7 +140,7 @@ def show_header(self):
def get_title(self, item):
title = ''
if self._field_is_visible('title'):
title = '<a href="' + item.absolute_url() + '/view">' + item.title + '</a>'
title = '<a href="' + item.absolute_url() + '/view">' + item.title + '</a>' # NOQA
return title

def get_description(self, item):
Expand Down

0 comments on commit 69cc0c8

Please sign in to comment.