diff --git a/setup.py b/setup.py
index 3e8bba4..7e37b2d 100644
--- a/setup.py
+++ b/setup.py
@@ -42,6 +42,7 @@
zip_safe=False,
install_requires=[
'Plone >=4.2',
+ 'plone.api',
'collective.z3cform.widgets',
'raptus.autocompletewidget',
'rdflib',
diff --git a/src/brasil/gov/vcge/at/extender.py b/src/brasil/gov/vcge/at/extender.py
index 4ed7381..7d6b1a9 100644
--- a/src/brasil/gov/vcge/at/extender.py
+++ b/src/brasil/gov/vcge/at/extender.py
@@ -6,8 +6,8 @@
from Products.Archetypes import public as atapi
from Products.Archetypes.interfaces import IBaseContent
from raptus.autocompletewidget.widget import AutocompleteMultiSelectionWidget
-from zope.component import adapts
-from zope.interface import implements
+from zope.component import adapter
+from zope.interface import implementer
AcMSW = AutocompleteMultiSelectionWidget
@@ -18,17 +18,15 @@ class ExtensionLinesField(ExtensionField, atapi.LinesField):
"""
+# Este adaptador sera aplicado a todos os tipos baseados em Archetypes
+@adapter(IBaseContent)
+# We use both orderable and browser layer aware sensitive properties
+@implementer(IBrowserLayerAwareExtender)
class VCGEExtender(object):
""" Adaptador que extende os tipos de conteudo base do Plone
com o campo skos (representando o VCGE)
"""
- # Este adaptador sera aplicado a todos os tipos baseados em Archetypes
- adapts(IBaseContent)
-
- # We use both orderable and browser layer aware sensitive properties
- implements(IBrowserLayerAwareExtender)
-
layer = IVCGEInstalado
fields = [
diff --git a/src/brasil/gov/vcge/browser/viewlets.py b/src/brasil/gov/vcge/browser/viewlets.py
index 20c8210..bbae99a 100644
--- a/src/brasil/gov/vcge/browser/viewlets.py
+++ b/src/brasil/gov/vcge/browser/viewlets.py
@@ -3,6 +3,7 @@
from Acquisition import aq_base
from Acquisition import aq_inner
from plone.app.layout.viewlets import ViewletBase
+from Products.CMFPlone.utils import safe_hasattr
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from urllib import urlencode
from zope.component import queryUtility
@@ -27,7 +28,7 @@ def skos(self):
'''
context = aq_base(aq_inner(self.context))
uris = []
- if hasattr(context, 'skos'):
+ if safe_hasattr(context, 'skos'):
uris = self.context.skos or []
name = 'brasil.gov.vcge'
util = queryUtility(IVocabularyFactory, name)
@@ -38,8 +39,10 @@ def skos(self):
params = urlencode({'skos:list': uri})
skos.append({'id': uri,
'title': title,
- 'url': '%s/@@search?%s' % (self.nav_root_url,
- params)})
+ 'url': '{0}/@@search?{1}'.format(
+ self.nav_root_url,
+ params
+ )})
return skos
def rel(self):
diff --git a/src/brasil/gov/vcge/config.py b/src/brasil/gov/vcge/config.py
index a14fb82..e55570d 100644
--- a/src/brasil/gov/vcge/config.py
+++ b/src/brasil/gov/vcge/config.py
@@ -1,7 +1,7 @@
# -*- coding:utf-8 -*-
from Products.CMFPlone import interfaces as plone_interfaces
from Products.CMFQuickInstallerTool import interfaces as qi_interfaces
-from zope.interface import implements
+from zope.interface import implementer
PROJECTNAME = 'brasil.gov.vcge'
@@ -10,9 +10,9 @@
NAMESPACE = 'http://www.w3.org/2004/02/skos/core#'
+@implementer(qi_interfaces.INonInstallable)
class HiddenProducts(object):
""" Oculta produtos do QuickInstaller """
- implements(qi_interfaces.INonInstallable)
def getNonInstallableProducts(self):
return [
@@ -20,9 +20,9 @@ def getNonInstallableProducts(self):
]
+@implementer(plone_interfaces.INonInstallable)
class HiddenProfiles(object):
""" Oculta profiles da tela inicial de criacao do site """
- implements(plone_interfaces.INonInstallable)
def getNonInstallableProfiles(self):
return [
diff --git a/src/brasil/gov/vcge/contentrules/action.py b/src/brasil/gov/vcge/contentrules/action.py
index 7d6e58d..0746ad8 100644
--- a/src/brasil/gov/vcge/contentrules/action.py
+++ b/src/brasil/gov/vcge/contentrules/action.py
@@ -7,9 +7,9 @@
from plone.app.contentrules.browser.formhelper import EditForm
from plone.contentrules.rule.interfaces import IExecutable
from plone.contentrules.rule.interfaces import IRuleElementData
-from zope.component import adapts
+from zope.component import adapter
from zope.formlib import form
-from zope.interface import implements
+from zope.interface import implementer
from zope.interface import Interface
from zope.schema import Bool
from zope.schema import Choice
@@ -41,10 +41,10 @@ class IVCGEAction(Interface):
value_type=Choice(vocabulary=VOCAB))
+@implementer(IVCGEAction, IRuleElementData)
class VCGEAction(SimpleItem):
""" A implementacao persistente para a acao VCGE
"""
- implements(IVCGEAction, IRuleElementData)
element = 'brasil.gov.vcge.actions.VCGE'
same_as_parent = False
@@ -62,12 +62,12 @@ def summary(self):
return msg
+@adapter(Interface, IVCGEAction, Interface)
+@implementer(IExecutable)
class VCGEActionExecutor(object):
""" O executor para esta acao.
Este codigo esta registrado como adaptador no configure.zcml
"""
- implements(IExecutable)
- adapts(Interface, IVCGEAction, Interface)
def __init__(self, context, element, event):
self.context = context
diff --git a/src/brasil/gov/vcge/contentrules/condition.py b/src/brasil/gov/vcge/contentrules/condition.py
index 947d2b4..c290a83 100644
--- a/src/brasil/gov/vcge/contentrules/condition.py
+++ b/src/brasil/gov/vcge/contentrules/condition.py
@@ -7,9 +7,9 @@
from plone.app.contentrules.browser.formhelper import EditForm
from plone.contentrules.rule.interfaces import IExecutable
from plone.contentrules.rule.interfaces import IRuleElementData
-from zope.component import adapts
+from zope.component import adapter
from zope.formlib import form
-from zope.interface import implements
+from zope.interface import implementer
from zope.interface import Interface
from zope.schema import Choice
from zope.schema import Set
@@ -37,10 +37,10 @@ class IVCGECondition(Interface):
value_type=Choice(vocabulary=VOCAB))
+@implementer(IVCGECondition, IRuleElementData)
class VCGECondition(SimpleItem):
""" A implementacao persistente para a condicao VCGE
"""
- implements(IVCGECondition, IRuleElementData)
skos = []
element = 'brasil.gov.vcge.conditions.VCGE'
@@ -56,12 +56,12 @@ def summary(self):
return msg
+@adapter(Interface, IVCGECondition, Interface)
+@implementer(IExecutable)
class VCGEConditionExecutor(object):
""" O executor para esta condicao.
Este codigo esta registrado como adaptador no configure.zcml
"""
- implements(IExecutable)
- adapts(Interface, IVCGECondition, Interface)
def __init__(self, context, element, event):
self.context = context
diff --git a/src/brasil/gov/vcge/contentrules/utils.py b/src/brasil/gov/vcge/contentrules/utils.py
index 9128bef..6d21afd 100644
--- a/src/brasil/gov/vcge/contentrules/utils.py
+++ b/src/brasil/gov/vcge/contentrules/utils.py
@@ -1,12 +1,13 @@
# -*- coding:utf-8 -*-
from Acquisition import aq_base
+from Products.CMFPlone.utils import safe_hasattr
def vcge_available(obj):
""" Valida se o objeto tem o atributo de
armazenamento do VCGE
"""
- return hasattr(aq_base(obj), 'skos')
+ return safe_hasattr(aq_base(obj), 'skos')
def vcge_for_object(obj):
@@ -14,7 +15,7 @@ def vcge_for_object(obj):
VCGE de um objeto
"""
skos = []
- if hasattr(aq_base(obj), 'skos'):
+ if safe_hasattr(aq_base(obj), 'skos'):
skos = obj.skos
return skos
@@ -23,6 +24,6 @@ def set_vcge(obj, skos):
""" Armazena valores no atributo
VCGE de um objeto
"""
- if hasattr(aq_base(obj), 'skos'):
+ if safe_hasattr(aq_base(obj), 'skos'):
obj.skos = skos
return True
diff --git a/src/brasil/gov/vcge/dx/widget.py b/src/brasil/gov/vcge/dx/widget.py
index c5f3b4b..4130fc4 100644
--- a/src/brasil/gov/vcge/dx/widget.py
+++ b/src/brasil/gov/vcge/dx/widget.py
@@ -26,56 +26,72 @@ class SkosWidget(widget.SequenceWidget):
maxResults = 10
mustMatch = False
matchContains = True
+
+ # Não é necessário dar "escape" em "{" e "}" aqui uma vez que essas variáveis
+ # são usadas de forma literal como parâmetro do format: só precisamos dar
+ # "escape" quando é a string que será aplicada o format (como o js_template)
formatItem = 'function(row, idx, count, value) { return row[1]; }'
formatResult = 'function(row, idx, count) { return ''; }'
+ #
+ # Lembre-se de que para conseguir usar { e } de forma literal nas aberturas
+ # e fechamento de funções do js, você precisa usar {{ e }} respectivamente.
+ # https://docs.python.org/3/library/string.html#formatstrings
js_template = """\
- (function($) {
- $().ready(function() {
- $('#formfield-form-widgets-IVCGE-skos #%(id)s').each(function() {
- $('#formfield-form-widgets-IVCGE-skos').append('');
+ (function($) {{
+ $().ready(function() {{
+ $('#formfield-form-widgets-IVCGE-skos #{id}').each(function() {{
+ $('#formfield-form-widgets-IVCGE-skos').append('');
$(this).remove();
- $('#formfield-form-widgets-IVCGE-skos #%(id)s-input').autocomplete('%(url)s/@@token-search?f=%(id)s', {
+ $('#formfield-form-widgets-IVCGE-skos #{id}-input').autocomplete('{url}/@@token-search?f={id}', {{
autoFill: false,
- minChars: %(minChars)d,
- max: %(maxResults)d,
- mustMatch: %(mustMatch)s,
- matchContains: %(matchContains)s,
- formatItem: %(formatItem)s,
- formatResult: %(formatResult)s
- }).result(%(js_callback)s);
- })
- });
- })(jQuery);
+ minChars: {minChars},
+ max: {maxResults},
+ mustMatch: {mustMatch},
+ matchContains: {matchContains},
+ formatItem: {formatItem},
+ formatResult: {formatResult}
+ }}).result({js_callback});
+ }})
+ }});
+ }})(jQuery);
"""
+ # Lembre-se de que para conseguir usar { e } de forma literal nas aberturas
+ # e fechamento de funções do js, você precisa usar {{ e }} respectivamente.
+ # https://docs.python.org/3/library/string.html#formatstrings
js_callback_template = """\
- function(event, data, formatted) {
+ function(event, data, formatted) {{
var field = $('#formfield-form-widgets-IVCGE-skos input[type="checkbox"][value="' + data[0] + '"]');
if(field.length == 0)
- $('#formfield-form-widgets-IVCGE-skos #%(id)s-input').before("<" + "label class='plain'><" + "input type='checkbox' name='%(name)s' checked='checked' value='" + data[0] + "' /> " + data[1] + "
");
+ $('#formfield-form-widgets-IVCGE-skos #{id}-input').before("<" + "label class='plain'><" + "input type='checkbox' name='{name}' checked='checked' value='" + data[0] + "' /> " + data[1] + "
");
else
- field.each(function() { this.checked = true });
+ field.each(function() {{ this.checked = true }});
if(data[0])
- $('#formfield-form-widgets-IVCGE-skos #%(id)s-input').val('');
- }
+ $('#formfield-form-widgets-IVCGE-skos #{id}-input').val('');
+ }}
"""
def js(self):
context = self.context
form_url = context.absolute_url()
- js_callback = self.js_callback_template % dict(id=self.id, name=self.name)
- return self.js_template % dict(
- id=self.id,
- name=self.name,
- url=form_url,
- minChars=self.minChars,
- maxResults=self.maxResults,
- mustMatch=str(self.mustMatch).lower(),
- matchContains=str(self.matchContains).lower(),
- formatItem=self.formatItem,
- formatResult=self.formatResult,
- js_callback=js_callback,)
+ js_callback = self.js_callback_template.format(
+ **dict(id=self.id, name=self.name)
+ )
+ return self.js_template.format(
+ **dict(
+ id=self.id,
+ name=self.name,
+ url=form_url,
+ minChars=self.minChars,
+ maxResults=self.maxResults,
+ mustMatch=str(self.mustMatch).lower(),
+ matchContains=str(self.matchContains).lower(),
+ formatItem=self.formatItem,
+ formatResult=self.formatResult,
+ js_callback=js_callback,
+ )
+ )
def vocab(self):
name = 'brasil.gov.vcge'
@@ -164,7 +180,7 @@ def __call__(self):
if query in i.title.lower()]
results = sorted(results, key=lambda pair: len(pair[1]))
- return '\n'.join(['%s|%s' % (value, title)
+ return '\n'.join(['{0}|{1}'.format(value, title)
for value, title in results])
@@ -175,5 +191,5 @@ def __call__(self):
results = results.split('\n')
query = self.request.get('q', '')
for r in results:
- if r.startswith(u'%s|' % safe_unicode(query)):
+ if r.startswith(u'{0}|'.format(safe_unicode(query))):
return r
diff --git a/src/brasil/gov/vcge/tests/test_behavior.py b/src/brasil/gov/vcge/tests/test_behavior.py
index 46c8c3a..b8c9fcf 100644
--- a/src/brasil/gov/vcge/tests/test_behavior.py
+++ b/src/brasil/gov/vcge/tests/test_behavior.py
@@ -5,6 +5,7 @@
from brasil.gov.vcge.dx.interfaces import IVCGEDx
from brasil.gov.vcge.testing import HAS_DEXTERITY
from brasil.gov.vcge.testing import INTEGRATION_TESTING
+from plone import api
from plone.app.testing import login
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
@@ -61,10 +62,14 @@ def setUpContent(self):
token = 'http://vocab.e.gov.br/id/governo#cultura'
self.token = token
portal = self.portal
- oId = portal.invokeFactory('folder', 'content')
- o = IVCGE(portal[oId])
+ o = api.content.create(
+ type='Folder',
+ container=portal,
+ id='content'
+ )
+ o = IVCGE(o)
o.skos = [token, ]
- self.content = portal[oId]
+ self.content = o
def setUp(self):
if not HAS_DEXTERITY:
@@ -76,7 +81,11 @@ def setUp(self):
self.portal = portal
self.fti = add_folder_type(self.portal)
self.setUpUser()
- self.portal.invokeFactory('folder', 'folder')
+ api.content.create(
+ type='Folder',
+ container=self.portal,
+ id='folder'
+ )
self.setUpContent()
def test_behavior_applied(self):
@@ -86,7 +95,7 @@ def test_behavior_applied(self):
def test_content_information(self):
content = self.content
- self.assertEquals(content.skos, [self.token, ])
+ self.assertEqual(content.skos, [self.token, ])
class TestViewlet(unittest.TestCase):
@@ -101,8 +110,11 @@ def setUpUser(self):
def setUpContent(self):
token = 'http://vocab.e.gov.br/id/governo#cultura'
portal = self.portal
- oId = portal.invokeFactory('folder', 'content')
- o = portal[oId]
+ o = api.content.create(
+ type='Folder',
+ container=portal,
+ id='content'
+ )
o.skos = [token, ]
self.content = o
@@ -116,7 +128,11 @@ def setUp(self):
self.portal = portal
self.fti = add_folder_type(self.portal)
self.setUpUser()
- self.portal.invokeFactory('folder', 'folder')
+ api.content.create(
+ type='Folder',
+ container=self.portal,
+ id='folder'
+ )
self.setUpContent()
def test_rel(self):
@@ -124,16 +140,16 @@ def test_rel(self):
viewlet = VCGEViewlet(content, self.request, None, None)
viewlet.update()
rel = viewlet.rel()
- self.assertEquals(rel, u'dc:subject foaf:primaryTopic')
+ self.assertEqual(rel, u'dc:subject foaf:primaryTopic')
def test_skos(self):
content = self.content
viewlet = VCGEViewlet(content, self.request, None, None)
viewlet.update()
skos = viewlet.skos()
- self.assertEquals(len(skos), 1)
+ self.assertEqual(len(skos), 1)
term = skos[0]
- self.assertEquals(term.get('title'), u'Cultura')
+ self.assertEqual(term.get('title'), u'Cultura')
def test_skos_not_existent(self):
''' Testa o que acontece quando nao temos o Extender
@@ -143,4 +159,4 @@ def test_skos_not_existent(self):
viewlet = VCGEViewlet(portal, self.request, None, None)
viewlet.update()
skos = viewlet.skos()
- self.assertEquals(len(skos), 0)
+ self.assertEqual(len(skos), 0)
diff --git a/src/brasil/gov/vcge/tests/test_contentrules_action.py b/src/brasil/gov/vcge/tests/test_contentrules_action.py
index 6879fd7..fe2e658 100644
--- a/src/brasil/gov/vcge/tests/test_contentrules_action.py
+++ b/src/brasil/gov/vcge/tests/test_contentrules_action.py
@@ -2,6 +2,7 @@
from brasil.gov.vcge.contentrules.action import VCGEAction
from brasil.gov.vcge.contentrules.action import VCGEEditForm
from brasil.gov.vcge.testing import INTEGRATION_TESTING
+from plone import api
from plone.app.contentrules.rule import Rule
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
@@ -13,13 +14,13 @@
from zope.component import getMultiAdapter
from zope.component import getUtility
from zope.component.interfaces import IObjectEvent
-from zope.interface import implements
+from zope.interface import implementer
import unittest2 as unittest
+@implementer(IObjectEvent)
class DummyEvent(object):
- implements(IObjectEvent)
def __init__(self, object):
self.object = object
@@ -34,14 +35,26 @@ class TestSubjectAction(unittest.TestCase):
def setUp(self):
self.portal = self.layer['portal']
setRoles(self.portal, TEST_USER_ID, ['Manager'])
- self.portal.invokeFactory('Folder', 'folder')
- self.folder = self.portal['folder']
+
+ self.folder = api.content.create(
+ type='Folder',
+ container=self.portal,
+ id='folder'
+ )
self.folder.skos = [self.term, ]
self.folder.reindexObject()
- sub_folder_id = self.folder.invokeFactory('Folder', 'sub_folder')
- self.sub_folder = self.folder[sub_folder_id]
- self.document = self.folder[self.folder.invokeFactory('Document',
- 'a_document')]
+
+ self.sub_folder = api.content.create(
+ type='Folder',
+ container=self.folder,
+ id='sub_folder'
+ )
+
+ self.document = api.content.create(
+ type='Document',
+ container=self.folder,
+ id='a_document'
+ )
self.document.setSubject(['Bar', ])
self.document.reindexObject()
@@ -55,11 +68,10 @@ def setUp(self):
def test_registered(self):
element = getUtility(IRuleAction,
name='brasil.gov.vcge.actions.VCGE')
- self.assertEquals('brasil.gov.vcge.actions.VCGE',
- element.addview)
- self.assertEquals('edit', element.editview)
- self.assertEquals(None, element.for_)
- self.assertEquals(IObjectEvent, element.event)
+ self.assertEqual('brasil.gov.vcge.actions.VCGE', element.addview)
+ self.assertEqual('edit', element.editview)
+ self.assertEqual(None, element.for_)
+ self.assertEqual(IObjectEvent, element.event)
def test_invoke_add_view(self):
element = getUtility(IRuleAction,
@@ -77,9 +89,9 @@ def test_invoke_add_view(self):
'skos': [self.term, ]})
e = rule.actions[0]
- self.failUnless(isinstance(e, VCGEAction))
- self.assertEquals(False, e.same_as_parent)
- self.assertEquals([self.term, ], e.skos)
+ self.assertTrue(isinstance(e, VCGEAction))
+ self.assertEqual(False, e.same_as_parent)
+ self.assertEqual([self.term, ], e.skos)
def test_invoke_edit_view(self):
element = getUtility(IRuleAction,
@@ -87,7 +99,7 @@ def test_invoke_edit_view(self):
e = VCGEAction()
editview = getMultiAdapter((e, self.folder.REQUEST),
name=element.editview)
- self.failUnless(isinstance(editview, VCGEEditForm))
+ self.assertTrue(isinstance(editview, VCGEEditForm))
def test_summary_parent_vcge(self):
e = VCGEAction()
@@ -116,10 +128,9 @@ def test_execute_with_vcge(self):
ex = getMultiAdapter((self.folder, e,
DummyEvent(self.sub_folder)),
IExecutable)
- self.assertEquals(True, ex())
+ self.assertEqual(True, ex())
- self.assertEquals(list(self.sub_folder.skos),
- e.skos)
+ self.assertEqual(list(self.sub_folder.skos), e.skos)
def test_execute_same_as_parent(self):
e = VCGEAction()
@@ -129,9 +140,9 @@ def test_execute_same_as_parent(self):
ex = getMultiAdapter((self.folder, e,
DummyEvent(self.sub_folder)),
IExecutable)
- self.assertEquals(True, ex())
+ self.assertEqual(True, ex())
- self.assertEquals(self.sub_folder.skos, self.folder.skos)
+ self.assertEqual(self.sub_folder.skos, self.folder.skos)
def test_execute_object_without_vcge(self):
e = VCGEAction()
@@ -141,7 +152,7 @@ def test_execute_object_without_vcge(self):
ex = getMultiAdapter((self.folder, e,
DummyEvent(o)),
IExecutable)
- self.assertEquals(False, ex())
+ self.assertEqual(False, ex())
def test_execute_parent_without_vcge(self):
e = VCGEAction()
@@ -152,7 +163,7 @@ def test_execute_parent_without_vcge(self):
ex = getMultiAdapter((folder, e,
DummyEvent(o)),
IExecutable)
- self.assertEquals(False, ex())
+ self.assertEqual(False, ex())
def test_execute_parent_without_vcge_attribute(self):
e = VCGEAction()
@@ -162,4 +173,4 @@ def test_execute_parent_without_vcge_attribute(self):
ex = getMultiAdapter((self.folder, e,
DummyEvent(self.sub_folder)),
IExecutable)
- self.assertEquals(False, ex())
+ self.assertEqual(False, ex())
diff --git a/src/brasil/gov/vcge/tests/test_contentrules_condition.py b/src/brasil/gov/vcge/tests/test_contentrules_condition.py
index 0f07034..3058b42 100644
--- a/src/brasil/gov/vcge/tests/test_contentrules_condition.py
+++ b/src/brasil/gov/vcge/tests/test_contentrules_condition.py
@@ -2,6 +2,7 @@
from brasil.gov.vcge.contentrules.condition import VCGECondition
from brasil.gov.vcge.contentrules.condition import VCGEEditForm
from brasil.gov.vcge.testing import INTEGRATION_TESTING
+from plone import api
from plone.app.contentrules.rule import Rule
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
@@ -12,13 +13,13 @@
from zope.component import getMultiAdapter
from zope.component import getUtility
from zope.component.interfaces import IObjectEvent
-from zope.interface import implements
+from zope.interface import implementer
import unittest2 as unittest
+@implementer(IObjectEvent)
class DummyEvent(object):
- implements(IObjectEvent)
def __init__(self, object):
self.object = object
@@ -33,11 +34,19 @@ class TestVCGECondition(unittest.TestCase):
def setUp(self):
self.portal = self.layer['portal']
setRoles(self.portal, TEST_USER_ID, ['Manager'])
- self.portal.invokeFactory('Folder', 'folder')
- self.folder = self.portal['folder']
+
+ self.folder = api.content.create(
+ type='Folder',
+ container=self.portal,
+ id='folder'
+ )
self.folder.skos = [self.term, ]
- sub_folder_id = self.folder.invokeFactory('Folder', 'sub_folder')
- self.sub_folder = self.folder[sub_folder_id]
+
+ self.sub_folder = api.content.create(
+ type='Folder',
+ container=self.folder,
+ id='sub_folder'
+ )
self.sub_folder.skos = ['http://vocab.e.gov.br/2011/03/vcge#governo', ]
o = PortalContent('cmf', 'CMF Content', '', '', '')
self.folder._setObject('cmf', o, suppress_events=True)
@@ -45,11 +54,10 @@ def setUp(self):
def test_registered(self):
element = getUtility(IRuleCondition,
name='brasil.gov.vcge.conditions.VCGE')
- self.assertEquals('brasil.gov.vcge.conditions.VCGE',
- element.addview)
- self.assertEquals('edit', element.editview)
- self.assertEquals(None, element.for_)
- self.assertEquals(IObjectEvent, element.event)
+ self.assertEqual('brasil.gov.vcge.conditions.VCGE', element.addview)
+ self.assertEqual('edit', element.editview)
+ self.assertEqual(None, element.for_)
+ self.assertEqual(IObjectEvent, element.event)
def test_invoke_add_view(self):
element = getUtility(IRuleCondition,
@@ -66,8 +74,8 @@ def test_invoke_add_view(self):
addview.createAndAdd(data={'skos': [self.term, ]})
e = rule.conditions[0]
- self.failUnless(isinstance(e, VCGECondition))
- self.assertEquals([self.term, ], e.skos)
+ self.assertTrue(isinstance(e, VCGECondition))
+ self.assertEqual([self.term, ], e.skos)
def test_invoke_edit_view(self):
element = getUtility(IRuleCondition,
@@ -75,7 +83,7 @@ def test_invoke_edit_view(self):
e = VCGECondition()
editview = getMultiAdapter((e, self.folder.REQUEST),
name=element.editview)
- self.failUnless(isinstance(editview, VCGEEditForm))
+ self.assertTrue(isinstance(editview, VCGEEditForm))
def test_summary_empty_vcge(self):
e = VCGECondition()
@@ -98,11 +106,11 @@ def test_execute(self):
ex = getMultiAdapter((self.portal, e, DummyEvent(self.folder)),
IExecutable)
- self.assertEquals(True, ex())
+ self.assertEqual(True, ex())
ex = getMultiAdapter((self.portal, e, DummyEvent(self.sub_folder)),
IExecutable)
- self.assertEquals(False, ex())
+ self.assertEqual(False, ex())
def test_execute_empty(self):
e = VCGECondition()
@@ -110,17 +118,17 @@ def test_execute_empty(self):
ex = getMultiAdapter((self.portal, e, DummyEvent(self.folder)),
IExecutable)
- self.assertEquals(False, ex())
+ self.assertEqual(False, ex())
ex = getMultiAdapter((self.portal, e, DummyEvent(self.sub_folder)),
IExecutable)
- self.assertEquals(False, ex())
+ self.assertEqual(False, ex())
# Empty VCGE field
self.sub_folder.skos = []
ex = getMultiAdapter((self.portal, e, DummyEvent(self.sub_folder)),
IExecutable)
- self.assertEquals(True, ex())
+ self.assertEqual(True, ex())
def test_execute_object_without_vcge(self):
e = VCGECondition()
@@ -129,4 +137,4 @@ def test_execute_object_without_vcge(self):
ex = getMultiAdapter((self.folder, e,
DummyEvent(self.folder['cmf'])),
IExecutable)
- self.assertEquals(False, ex())
+ self.assertEqual(False, ex())
diff --git a/src/brasil/gov/vcge/tests/test_setup.py b/src/brasil/gov/vcge/tests/test_setup.py
index 5a8bd62..6b932f4 100644
--- a/src/brasil/gov/vcge/tests/test_setup.py
+++ b/src/brasil/gov/vcge/tests/test_setup.py
@@ -40,18 +40,18 @@ class TestInstall(BaseTestCase):
def test_installed(self):
self.assertTrue(self.qi.isProductInstalled(PROJECTNAME),
- '%s not installed' % PROJECTNAME)
+ '{0} not installed'.format(PROJECTNAME))
def test_dependencies_installed(self):
for product in ['raptus.autocompletewidget', ]:
self.assertTrue(self.qi.isProductInstalled(product),
- '%s not installed' % product)
+ '{0} not installed'.format(product))
@unittest.skipIf(not HAS_DEXTERITY, '"dexterity" extra not included')
def test_dx_dependencies_installed(self):
for product in ['plone.app.dexterity', ]:
self.assertTrue(self.qi.isProductInstalled(product),
- '%s not installed' % product)
+ '{0} not installed'.format(product))
def test_browserlayer(self):
from brasil.gov.vcge.interfaces import IVCGEInstalado
@@ -61,7 +61,7 @@ def test_cssregistry(self):
portal_css = self.portal.portal_css
for css in STYLESHEETS:
self.assertTrue(css in portal_css.getResourceIds(),
- '%s not installed' % css)
+ '{0} not installed'.format(css))
class TestUpgrade(BaseTestCase):
@@ -108,4 +108,4 @@ def test_cssregistry(self):
portal_css = self.portal.portal_css
for css in STYLESHEETS:
self.assertTrue(css not in portal_css.getResourceIds(),
- '%s installed' % css)
+ '{0} installed'.format(css))
diff --git a/src/brasil/gov/vcge/tests/test_viewlet.py b/src/brasil/gov/vcge/tests/test_viewlet.py
index 150b432..722ae52 100644
--- a/src/brasil/gov/vcge/tests/test_viewlet.py
+++ b/src/brasil/gov/vcge/tests/test_viewlet.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from brasil.gov.vcge.browser.viewlets import VCGEViewlet
from brasil.gov.vcge.testing import INTEGRATION_TESTING
+from plone import api
from plone.app.testing import login
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
@@ -22,8 +23,11 @@ def setUpUser(self):
def setUpContent(self):
token = 'http://vocab.e.gov.br/id/governo#cultura'
portal = self.portal
- oId = portal.invokeFactory('Document', 'doc')
- o = portal[oId]
+ o = api.content.create(
+ type='Document',
+ container=portal,
+ id='doc'
+ )
o.Schema().getField('skos').set(o, [token, ])
self.content = o
@@ -40,16 +44,16 @@ def test_rel(self):
viewlet = VCGEViewlet(content, self.request, None, None)
viewlet.update()
rel = viewlet.rel()
- self.assertEquals(rel, u'dc:subject foaf:primaryTopic')
+ self.assertEqual(rel, u'dc:subject foaf:primaryTopic')
def test_skos(self):
content = self.content
viewlet = VCGEViewlet(content, self.request, None, None)
viewlet.update()
skos = viewlet.skos()
- self.assertEquals(len(skos), 1)
+ self.assertEqual(len(skos), 1)
term = skos[0]
- self.assertEquals(term.get('title'), u'Cultura')
+ self.assertEqual(term.get('title'), u'Cultura')
def test_skos_not_existent(self):
''' Testa o que acontece quando nao temos o Extender
@@ -59,4 +63,4 @@ def test_skos_not_existent(self):
viewlet = VCGEViewlet(portal, self.request, None, None)
viewlet.update()
skos = viewlet.skos()
- self.assertEquals(len(skos), 0)
+ self.assertEqual(len(skos), 0)
diff --git a/src/brasil/gov/vcge/vocabulary.py b/src/brasil/gov/vcge/vocabulary.py
index 29a4000..a21563e 100644
--- a/src/brasil/gov/vcge/vocabulary.py
+++ b/src/brasil/gov/vcge/vocabulary.py
@@ -1,12 +1,13 @@
# -*- coding:utf-8 -*-
from brasil.gov.vcge.utils import load_skos
-from zope.interface import implements
+from zope.interface import implementer
from zope.schema.interfaces import IVocabularyFactory
from zope.schema.vocabulary import SimpleTerm
from zope.schema.vocabulary import SimpleVocabulary
+@implementer(IVocabularyFactory)
class VCGEVocabulary(object):
"""Vocabulario Controlado do Governo Eletronico
@@ -29,7 +30,6 @@ class VCGEVocabulary(object):
>>> doc.title, doc.token, doc.value
(u'Cultura', token, token)
"""
- implements(IVocabularyFactory)
def __call__(self, context):
items = []