Skip to content

Commit

Permalink
Corrige testes para collective.cover 1.1b
Browse files Browse the repository at this point in the history
Principais commits em collective.cover que motivaram essas mudanças:

collective/collective.cover@adb1a67
collective/collective.cover@9db9acf
  • Loading branch information
idgserpro committed Apr 6, 2016
1 parent 007adcd commit 430e452
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 46 deletions.
15 changes: 10 additions & 5 deletions buildout.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@ eggs =
plone.app.robotframework[ride,reload]

[versions]
# O overrides.zcml de brasil.gov.tiles tem uma modificação que precisa do
# 1.0a13.
collective.cover = >= 1.0a13
plone.app.blocks = 2.2.0
# createcoverage 1.4.1 requer coverage>=3.7, dando conflito com a versão
# createcoverage 1.4.1 requer coverage>=3.7, dando conflito com a versão
# requerida pelo plone.
createcoverage = 1.4

Expand All @@ -60,6 +56,15 @@ zope.configuration = 3.8.0
# Products.PloneFormGen >= 1.8 requer Plone 5
Products.PloneFormGen = < 1.8

# XXX: Ao adicionar collective.cover[test] em setup.py (necessário para usar
# o tzlocal em collective.cover.setup.py, usado em nossos testes já que passo a
# herdar do Fixture de collective.cover em testing.py), recebemos o erro
# cop, cv = _parse_constraint(constraint).group(1, 2)
# AttributeError: 'NoneType' object has no attribute 'group'
# e a solução para isso é usar uma versão mais nova do buildout. Ver
# https://github.com/buildout/buildout/issues/99
zc.buildout = >= 2.2.5

# É necessário ter o precompile para gerar os '*.mo' para os testes. Os '*.mo'
# só são gerados quando a instância sobe e para executar os testes a instância
# não é levantada.
Expand Down
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@
include_package_data=True,
zip_safe=False,
install_requires=[
'collective.cover',
# Após o commit 007adcde40d2031a15debd5122af8086a1db6fa6, necessito a
# partir dessa versão pois alterei o caminho dos recursos estáticos no
# overrides.zcml.
'collective.cover >= 1.0a13',
'collective.nitf',
'collective.polls',
'collective.prettydate',
Expand Down Expand Up @@ -79,6 +82,7 @@
],
extras_require={
'test': [
'collective.cover[test]',
'mock',
'five.pt',
'plone.app.robotframework',
Expand Down
36 changes: 4 additions & 32 deletions src/brasil/gov/tiles/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
from App.Common import package_home
from PIL import Image
from StringIO import StringIO
from collective.cover.testing import Fixture as CoverFixture
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.testing import z2

import os
Expand Down Expand Up @@ -57,43 +57,23 @@ def generate_jpeg(width, height):
return output.getvalue()


class Fixture(PloneSandboxLayer):
class Fixture(CoverFixture):

defaultBases = (PLONE_FIXTURE,)

def setUpZope(self, app, configurationContext):
import Products.PloneFormGen
self.loadZCML(package=Products.PloneFormGen)
z2.installProduct(app, 'Products.PloneFormGen')

# Load ZCML
import collective.cover
self.loadZCML(package=collective.cover)
if 'virtual_hosting' not in app.objectIds():
# If ZopeLite was imported, we have no default virtual
# host monster
from Products.SiteAccess.VirtualHostMonster \
import manage_addVirtualHostMonster
manage_addVirtualHostMonster(app, 'virtual_hosting')
super(Fixture, self).setUpZope(app, configurationContext)
import brasil.gov.tiles
self.loadZCML(package=brasil.gov.tiles)
self.loadZCML(name='overrides.zcml', package=brasil.gov.tiles)

def setUpPloneSite(self, portal):

super(Fixture, self).setUpPloneSite(portal)
with api.env.adopt_roles(roles=['Manager']):

# Install into Plone site using portal_setup
self.applyProfile(portal, 'collective.cover:default')
self.applyProfile(portal, 'collective.cover:testfixture')
self.applyProfile(portal, 'brasil.gov.tiles:default')
self.applyProfile(portal, 'brasil.gov.tiles:testfixture')
portal['my-image'].setImage(generate_jpeg(50, 50))
portal['my-image1'].setImage(generate_jpeg(50, 50))
portal['my-image2'].setImage(generate_jpeg(50, 50))
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',
Expand All @@ -120,14 +100,6 @@ def setUpPloneSite(self, portal):
portal['my-news-folder']['my-nitf-without-image'].reindexObject()
portal['my-news-folder']['my-nitf-with-image']['my-image'].reindexObject()

portal_workflow = portal.portal_workflow
portal_workflow.setChainForPortalTypes(['Collection'],
['plone_workflow'],)
# 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)


FIXTURE = Fixture()
INTEGRATION_TESTING = IntegrationTesting(
Expand Down
2 changes: 1 addition & 1 deletion src/brasil/gov/tiles/tests/test_banner.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_render_with_link(self):
self.tile.populate_with_object(obj)
rendered = self.tile()
self.assertNotIn('<img ', rendered)
self.assertIn('<a href="http://">Test link</a>', rendered)
self.assertIn('">Test link</a>', rendered)
self.assertFalse(self.tile.has_image)

def test_title(self):
Expand Down
4 changes: 2 additions & 2 deletions src/brasil/gov/tiles/tests/test_destaque_tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ def test_crud(self):
tile = tile['test']
self.assertTrue(tile.is_empty())

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

# now we add a couple of objects to the destaque
obj1 = self.portal['my-document']
obj2 = self.portal['my-image']
self.tile.populate_with_uids([IUUID(obj1, None),
self.tile.populate_with_uuids([IUUID(obj1, None),
IUUID(obj2, None)])

# tile's data attributed is cached so we should re-instantiate the tile
Expand Down
12 changes: 7 additions & 5 deletions src/brasil/gov/tiles/tests/test_mediacarousel_tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,27 @@ def test_delete_folder(self):
self.assertIn(msg, self.tile())

def test_collection_tile_render(self):
obj = self.portal['my-collection']
obj = self.portal['mandelbrot-set']
self.tile.populate_with_object(obj)

rendered = self.tile()
msg = u'Drag a folder or collection to populate the tile.'
msg = u'Mandelbrot set'
self.assertIn(msg, rendered)

def test_delete_collection(self):
obj = self.portal['my-collection']
obj = self.portal['mandelbrot-set']
self.tile.populate_with_object(obj)
self.tile.populate_with_object(obj)

rendered = self.tile()
msg = u'Drag a folder or collection to populate the tile.'
msg = u'Mandelbrot set'
self.assertIn(msg, rendered)

setRoles(self.portal, TEST_USER_ID, ['Manager', 'Editor', 'Reviewer'])
login(self.portal, TEST_USER_NAME)
self.portal.manage_delObjects(['my-collection'])
self.portal.manage_delObjects(['mandelbrot-set'])

msg = u'Drag a folder or collection to populate the tile.'

rendered = self.tile()
self.tile.is_compose_mode = Mock(return_value=True)
Expand Down
14 changes: 14 additions & 0 deletions src/brasil/gov/tiles/tests/test_mediacarousel_tile.robot
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ Suite Teardown Close all browsers

*** Variables ***

${filter_items} contentchooser-content-trees
${my_news_folder} my-news-folder
${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} .ui-draggable .contenttype-folder
${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
Expand Down Expand Up @@ -129,6 +132,17 @@ Test Mediacarousel Tile
# drag&drop a folder with nitf content
Open Content Chooser
Click Link link=Content tree
# Temos um bug no robots onde ele não consegue selecionar um ícone do overlay
# "Adicionar conteúdo" se for necessário usar o scroll, era como se ele não
# conseguisse "ver" o objeto: dessa forma, uso o filtro de items para mostrar
# menos itens e evitar esse problema.
# FIXME: https://github.com/robotframework/Selenium2Library/issues/591
Input Text id=${filter_items} ${my_news_folder}
# Acontece que, ao usar o filtro, o "Drag And Drop" acaba sendo executado
# ANTES do "Input Text" ter um retorno na tela, ou seja, ele é executado com
# o scroll "ainda ativo": por isso preciso desse "Sleep" logo abaixo para
# "forçar" que o "Drag And Drop" só seja executado após o "Input Text".
Sleep 1s
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}
Expand Down

0 comments on commit 430e452

Please sign in to comment.