Skip to content

Commit

Permalink
Merge pull request #137 from plonegovbr/issue_132
Browse files Browse the repository at this point in the history
Corrige teste quando usa collective.cover 1.0a11
  • Loading branch information
idgserpro committed Feb 12, 2016
2 parents f7c10d7 + 0a01c89 commit 2b7b3bf
Show file tree
Hide file tree
Showing 14 changed files with 167 additions and 142 deletions.
10 changes: 9 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@ Alterações
1.0.8 (unreleased)
^^^^^^^^^^^^^^^^^^

- Nothing changed yet.
.. 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
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.

- Corrige teste quando se utiliza collective.cover 1.0a11 (closes `#132`).
[idgserpro]

1.0.7 (2015-09-03)
^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -259,3 +266,4 @@ Alterações
.. _`#109`: https://github.com/plonegovbr/brasil.gov.tiles/issues/109
.. _`#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
8 changes: 2 additions & 6 deletions buildout.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ extends =
https://raw.github.com/collective/buildout.plonetest/master/test-4.3.x.cfg
https://raw.github.com/collective/buildout.plonetest/master/qa.cfg
https://github.com/raw/plone/plone.app.robotframework/master/versions.cfg
https://github.com/raw/collective/collective.cover/master/versions-4.3.x.cfg

package-name = brasil.gov.tiles
package-extras = [test]
Expand Down Expand Up @@ -43,12 +44,7 @@ eggs =
[versions]
# 1.0a10 possui um bug grave. Ver
# https://github.com/plonegovbr/brasil.gov.tiles/issues/130#issuecomment-117761638
collective.cover = 1.0a9
collective.js.bootstrap = 2.3.1.1
plone.app.blocks = 1.1.1
plone.app.drafts = 1.0a2
plone.app.tiles = 1.0.1
plone.tiles = 1.2
collective.cover = > 1.0a10
# createcoverage 1.4.1 requer coverage>=3.7, dando conflito com a versão
# requerida pelo plone.
createcoverage = 1.4
Expand Down
6 changes: 4 additions & 2 deletions src/brasil/gov/tiles/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class HiddenProducts(object):
def getNonInstallableProducts(self):
return [
u'brasil.gov.tiles.upgrades.v2000',
u'brasil.gov.tiles.upgrades.v3000'
u'brasil.gov.tiles.upgrades.v3000',
u'brasil.gov.tiles.upgrades.v4000'
]


Expand All @@ -25,5 +26,6 @@ def getNonInstallableProfiles(self):
u'brasil.gov.tiles:uninstall',
u'brasil.gov.tiles:testfixture',
u'brasil.gov.tiles.upgrades.v2000:default',
u'brasil.gov.tiles.upgrades.v3000:default'
u'brasil.gov.tiles.upgrades.v3000:default',
u'brasil.gov.tiles.upgrades.v4000:default',
]
2 changes: 1 addition & 1 deletion src/brasil/gov/tiles/profiles/default/metadata.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<metadata>
<version>3000</version>
<version>4000</version>
<dependencies>
<dependency>profile-collective.cover:default</dependency>
<dependency>profile-collective.nitf:default</dependency>
Expand Down
20 changes: 0 additions & 20 deletions src/brasil/gov/tiles/profiles/testfixture/registry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,6 @@
<registry xmlns:i18n="http://xml.zope.org/namespaces/i18n"
i18n:domain="plone">

<record field="layouts"
interface="collective.cover.controlpanel.ICoverSettings"
name="collective.cover.controlpanel.ICoverSettings.layouts">
<field type="plone.registry.field.Dict">
<key_type type="plone.registry.field.TextLine">
<title>Name</title>
</key_type>
<title>Layouts</title>
<value_type type="plone.registry.field.TextLine">
<title>Layout</title>
</value_type>
</field>
<value purge="true">
<element key="Layout A">[{"type": "row", "class": "row", "children": [{"id": "group1", "type": "group", "data":{"column-size":16, "layout-type":"column"}, "roles": ["Manager"], "children": [{"tile-type": "collective.cover.carousel", "type": "tile", "class": "tile", "id": "d34acf7c70084016810946f9039ffb67"}]}]}, {"type": "row", "class": "row", "children": [{"type": "group", "data":{"column-size":8, "layout-type":"column"}, "roles": ["Manager"], "children": [{"tile-type": "collective.cover.list", "type": "tile", "class": "tile", "id": "7bb03c26b2504b8a9cadf5b852cc8a2c"}]}, {"type": "group", "data":{"column-size":8, "layout-type":"column"}, "roles": ["Manager"], "children": [{"tile-type": "collective.cover.collection", "type": "tile", "class": "tile", "id": "cc6d0ff688a143b38d64db2493ca74ce"}]}]}, {"type": "row", "class": "row", "children": [{"id": "group2", "type": "group", "data":{"column-size":5, "layout-type":"column"}, "roles": ["Manager"], "children": [{"tile-type": "collective.cover.basic", "type": "tile", "class": "tile", "id": "6673d5554e934b4396790a92698e32d0"}]}, {"type": "group", "data":{"column-size":5, "layout-type":"column"}, "roles": ["Manager"], "children": [{"tile-type": "collective.cover.basic", "type": "tile", "class": "tile", "id": "db093ff0b98c4475aeb4cb7c3a78e9ba"}]}, {"type": "group", "data":{"column-size":5, "layout-type":"column"}, "roles": ["Manager"], "children": [{"tile-type": "collective.cover.basic", "type": "tile", "class": "tile", "id": "bfe62e09db9e4a538f92dbeda8db42de"}]}]}]</element>
<element key="Layout B">[{"type": "row", "class": "row", "children": [{"id": "group1", "type": "group", "data":{"column-size":8, "layout-type":"column"}, "roles": ["Manager"], "children": [{"tile-type": "collective.cover.basic", "type": "tile", "class": "tile", "id": "4ebc5e6678044918b76280ec0204041a"}]}, {"type": "group", "data":{"column-size":8, "layout-type":"column"}, "roles": ["Manager"], "children": [{"tile-type": "collective.cover.list", "type": "tile", "class": "tile", "id": "7d68fd4cf0e34073aea99568f1e8eef6"}]}]}, {"type": "row", "class": "row", "children": [{"id": "group2", "type": "group", "data":{"column-size":8, "layout-type":"column"}, "roles": ["Manager"], "children": [{"tile-type": "collective.cover.basic", "type": "tile", "class": "tile", "id": "03fbc0eccfb446debef114ebfa49a14c"}]}, {"type": "group", "data":{"column-size":8, "layout-type":"column"}, "roles": ["Manager"], "children": [{"tile-type": "collective.cover.list", "type": "tile", "class": "tile", "id": "d9892b66d47547fb99cfa4ac9802b2c3"}]}]}]</element>
<element key="Layout C">[{"type": "row", "class": "row", "children": [{"id": "group1", "type": "group", "data":{"column-size":8, "layout-type":"column"}, "roles": ["Manager"], "children": [{"tile-type": "collective.cover.basic", "type": "tile", "class": "tile", "id": "33ab4627d26a4e868bb6044d5f270633"}]}, {"type": "group", "data":{"column-size":8, "layout-type":"column"}, "roles": ["Manager"], "children": [{"tile-type": "collective.cover.basic", "type": "tile", "class": "tile", "id": "ff53063434ea4be1968c19a94ae57a29"}]}]}, {"type": "row", "class": "row", "children": [{"id": "group2", "type": "group", "data":{"column-size":8, "layout-type":"column"}, "roles": ["Manager"], "children": [{"tile-type": "collective.cover.list", "type": "tile", "class": "tile", "id": "c57800cb56dc44ccae531517af725c2e"}]}, {"type": "group", "data":{"column-size":8, "layout-type":"column"}, "roles": ["Manager"], "children": [{"tile-type": "collective.cover.list", "type": "tile", "class": "tile", "id": "81af4c0eb99343e286a4a07c15c40c2c"}]}]}]</element>
<element key="Empty layout">[{"type": "row", "class": "row", "children": [{"type": "group", "data":{"column-size":16, "layout-type":"column"}, "roles": ["Manager"]}]}]</element>
</value>
</record>

<record field="available_tiles"
interface="collective.cover.controlpanel.ICoverSettings"
name="collective.cover.controlpanel.ICoverSettings.available_tiles">
Expand Down
2 changes: 1 addition & 1 deletion src/brasil/gov/tiles/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def setUpPloneSite(self, portal):
# Prevent kss validation errors in Plone 4.2
portal_kss = getattr(portal, 'portal_kss', None)
if portal_kss:
portal_kss.getResource('++resource++plone.app.z3cform').setEnabled(False)
portal_kss.getResource('++resource++plone.app.z3cform').setEnabled(False) # NOQA

FIXTURE = Fixture()
INTEGRATION_TESTING = IntegrationTesting(
Expand Down
15 changes: 15 additions & 0 deletions src/brasil/gov/tiles/tests/test_albuns_tile.robot
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ ${footerurl_sample} http://www.plone.org
${footertext_other_sample} Google
${footerurl_other_sample} http://www.google.com

*** Keywords ***

# FIXME: Customização de cover.robot em collective cover para poder aplicar a solução
# https://github.com/collective/collective.cover/commit/0d4c0ba8ba1f7c61d77e8b766d48a74b388b6269
# Ver https://github.com/collective/collective.cover/issues/582#issuecomment-173333865
# O mais correto seria corrigir em collective.cover, daí o FIXME. Isso está em estudo.
Edit Cover Layout
[Documentation] Click on Layout tab and wait until the layout has been
... loaded. Buttons related with layout operations must be
... also visible.
Wait Until Keyword Succeeds 10 sec 2 sec Click Link link=Layout
Sleep 1s Wait for cover layout to load
Wait until page contains Export layout
Wait until page contains Saved

*** Test cases ***

Test Albuns Tile
Expand Down
15 changes: 14 additions & 1 deletion src/brasil/gov/tiles/tests/test_mediacarousel_tile.robot
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ Compose Cover
Wait Until Page Contains Element css=div#contentchooser-content-show-button
Page Should Contain Add Content

# FIXME: Customização de cover.robot em collective cover para poder aplicar a solução
# https://github.com/collective/collective.cover/commit/0d4c0ba8ba1f7c61d77e8b766d48a74b388b6269
# Ver https://github.com/collective/collective.cover/issues/582#issuecomment-173333865
# O mais correto seria corrigir em collective.cover, daí o FIXME. Isso está em estudo.
Edit Cover Layout
[Documentation] Click on Layout tab and wait until the layout has been
... loaded. Buttons related with layout operations must be
... also visible.
Wait Until Keyword Succeeds 10 sec 2 sec Click Link link=Layout
Sleep 1s Wait for cover layout to load
Wait until page contains Export layout
Wait until page contains Saved

*** Test cases ***

Test Mediacarousel Tile
Expand All @@ -43,7 +56,7 @@ Test Mediacarousel Tile

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

Expand Down
53 changes: 53 additions & 0 deletions src/brasil/gov/tiles/tests/test_setup.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# -*- coding: utf-8 -*-
from brasil.gov.tiles.config import PROJECTNAME
from brasil.gov.tiles.testing import INTEGRATION_TESTING
from collective.cover.tests.test_upgrades import Upgrade9to10TestCase
from collective.cover.tests.test_upgrades import UpgradeTestCaseBase
from plone.app.testing import TEST_USER_ID
from plone.app.testing import setRoles
from plone.browserlayer.utils import registered_layers
from plone.registry.interfaces import IRegistry
from plone.tiles.interfaces import ITileDataManager
from zope.component import getUtility


Expand Down Expand Up @@ -78,3 +81,53 @@ def test_browserlayer_removed(self):
layers = [l.getName() for l in registered_layers()]
self.assertNotIn('IBrasilGovTiles', layers,
'browser layer not removed')


class Upgrade3000to4000TestCase(Upgrade9to10TestCase):

"""
Essa classe de testes herda de Upgrade9to10TestCase, de collective.cover,
por ser o mesmo teste de novos uuids e por conter métodos de chamar
upgradeSteps. collective.cover já é dependência de brasil.gov.tiles.
brasil.gov.portal também possui métodos semelhantes que tratam de
upgradeSteps mas não é dependência.
"""

layer = INTEGRATION_TESTING

def setUp(self):
UpgradeTestCaseBase.setUp(self, u'3000', u'4000')
self.profile_id = u'brasil.gov.tiles:default'

def test_upgrade_to_4000_registrations(self):
version = self.setup.getLastVersionForProfile(self.profile_id)[0]
self.assertTrue(int(version) >= int(self.to_version))
self.assertEqual(self._how_many_upgrades_to_do(), 1)

def test_new_uuids_structure(self):
title = u'Atualiza estrutura no banco do tipo Destaque'
step = self._get_upgrade_step(title)
self.assertIsNotNone(step)

# simulate state on previous version
cover = self._create_cover('test-cover', 'Empty layout')
cover.cover_layout = (
'[{"type": "row", "children": [{"column-size": 16, "type": '
'"group", "children": [{"tile-type": '
'"destaque", "type": "tile", "id": '
'"ca6ba6675ef145e4a569c5e410af7511"}], "roles": ["Manager"]}]}]'
)

tile = cover.get_tile('ca6ba6675ef145e4a569c5e410af7511')
old_data = ITileDataManager(tile).get()
old_data['uuids'] = ['uuid1', 'uuid3', 'uuid2']
ITileDataManager(tile).set(old_data)

# run the upgrade step to validate the update
self._do_upgrade_step(step)
old_data = ITileDataManager(tile).get()
self.assertFalse(isinstance(old_data['uuids'], list))
self.assertTrue(isinstance(old_data['uuids'], dict))
self.assertEqual(old_data['uuids']['uuid1']['order'], u'0')
self.assertEqual(old_data['uuids']['uuid2']['order'], u'2')
self.assertEqual(old_data['uuids']['uuid3']['order'], u'1')
116 changes: 6 additions & 110 deletions src/brasil/gov/tiles/tiles/destaque.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,25 @@
from collective.cover.interfaces import ICoverUIDsProvider
from collective.cover.tiles.list import IListTile
from collective.cover.tiles.list import ListTile
from plone.app.uuid.utils import uuidToObject
from plone.memoize import view
from plone.namedfile.field import NamedImage
from plone.registry.interfaces import IRegistry
from plone.tiles.interfaces import ITileDataManager
from plone.tiles.interfaces import ITileType
from plone.uuid.interfaces import IUUID
from zope import schema
from zope.component import getUtility
from zope.component import queryUtility
from zope.interface import implements
from zope.schema import getFieldsInOrder


# XXX: we must refactor this tile
class IDestaqueTile(IListTile):

uuids = schema.List(
uuids = schema.Dict(
title=_(u'Elements'),
value_type=schema.TextLine(),
key_type=schema.TextLine(),
value_type=schema.Dict(
key_type=schema.TextLine(),
value_type=schema.TextLine(),
),
required=False,
)

Expand Down Expand Up @@ -58,113 +57,10 @@ class DestaqueTile(ListTile):
is_editable = False
limit = 2

def results(self):
""" Return the list of objects stored in the tile.
"""
self.set_limit()
uuids = self.data.get('uuids', None)
result = []
if uuids:
uuids = [uuids] if type(uuids) == str else uuids
for uid in uuids:
obj = uuidToObject(uid)
if obj:
result.append(obj)
else:
self.remove_item(uid)
return result[:self.limit]

def is_empty(self):
return self.results() == []

# XXX: we could get rid of this fixing the tile's schema
def set_limit(self):
for field in self.get_configured_fields():
if field and field.get('id') == 'uuids':
self.limit = int(field.get('size', self.limit))

def populate_with_object(self, obj):
super(DestaqueTile, self).populate_with_object(obj) # check permission
uids = ICoverUIDsProvider(obj).getUIDs()
if uids:
self.populate_with_uids(uids)

def populate_with_uids(self, uuids):
self.set_limit()
data_mgr = ITileDataManager(self)

old_data = data_mgr.get()
for uuid in uuids:
if old_data['uuids']:
if type(old_data['uuids']) != list:
old_data['uuids'] = [uuid]
elif uuid not in old_data['uuids']:
old_data['uuids'].append(uuid)
else:
old_data['uuids'] = [uuid]
data_mgr.set(old_data)

def replace_with_objects(self, uids):
super(DestaqueTile, self).replace_with_objects(uids) # check permission # NOQA
self.set_limit()
data_mgr = ITileDataManager(self)
old_data = data_mgr.get()
if type(uids) == list:
old_data['uuids'] = [i for i in uids][:self.limit]
else:
old_data['uuids'] = [uids]

data_mgr.set(old_data)

def remove_item(self, uid):
super(DestaqueTile, self).remove_item(uid)
data_mgr = ITileDataManager(self)
old_data = data_mgr.get()
uids = data_mgr.get()['uuids']
if uid in uids:
del uids[uids.index(uid)]
old_data['uuids'] = uids
data_mgr.set(old_data)

# XXX: are we using this function somewhere? remove?
def get_uid(self, obj):
return IUUID(obj, None)

# XXX: refactoring the tile's schema should be a way to avoid this
def get_configured_fields(self):
# Override this method, since we are not storing anything
# in the fields, we just use them for configuration
tileType = queryUtility(ITileType, name=self.__name__)
conf = self.get_tile_configuration()

fields = getFieldsInOrder(tileType.schema)

results = []
for name, obj in fields:
field = {'id': name,
'title': obj.title}
if name in conf:
field_conf = conf[name]
if ('visibility' in field_conf and field_conf['visibility'] == u'off'): # NOQA
# If the field was configured to be invisible, then just
# ignore it
continue

if 'htmltag' in field_conf:
# If this field has the capability to change its html tag
# render, save it here
field['htmltag'] = field_conf['htmltag']

if 'imgsize' in field_conf:
field['scale'] = field_conf['imgsize']

if 'size' in field_conf:
field['size'] = field_conf['size']

results.append(field)

return results

@view.memoize
def accepted_ct(self):
"""
Expand Down
1 change: 1 addition & 0 deletions src/brasil/gov/tiles/upgrades/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
<!-- Include Upgrades -->
<include package=".v2000" />
<include package=".v3000" />
<include package=".v4000" />

</configure>
1 change: 1 addition & 0 deletions src/brasil/gov/tiles/upgrades/v4000/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# -*- coding: utf-8 -*-
Loading

0 comments on commit 2b7b3bf

Please sign in to comment.