Skip to content

Commit

Permalink
Merge branch 'master' into fix-tinymce-widget-accessor
Browse files Browse the repository at this point in the history
  • Loading branch information
jensens authored Feb 1, 2018
2 parents e4750ee + a5aa4d2 commit e25765a
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 95 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ cache:
before_install:
- mkdir -p $HOME/buildout-cache/{eggs,downloads}
- virtualenv .
- bin/python bootstrap.py --setuptools-version=33.1.1 --buildout-version=2.8.0 #from https://github.com/plone/buildout.coredev/blob/5.1/requirements.txt 2017-05-30 11:57
# Keep in sync with buildout.cfg:
- bin/python bootstrap.py --setuptools-version=38.2.4 --buildout-version=2.11.0
install:
- bin/buildout -Nvt 5 -c travis.cfg
script:
Expand Down
7 changes: 6 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ Breaking changes:

New features:

- *add item here*
- Removed CMFQuickInstaller dependency.
This was only used in ancient migration code.
[maurits]

Bug fixes:

- Use the edit accessor to get text for TinyMCEWidget.
[davisagli]

- Fix test failures from https://github.com/plone/plone.app.widgets/pull/177
[thet]


1.14.3 (2017-11-24)
-------------------
Expand Down
17 changes: 10 additions & 7 deletions Products/Archetypes/Extensions/migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,19 @@ def write(self, s):
def reinstallArchetypes(portal, out):
"""let's quickinstaller (re)install Archetypes and it's dependencies
"""
qi = getToolByName(portal, 'portal_quickinstaller')
# Import here so it does not break when you manage to
# get a too old CMFPlone with a too new Archetypes.
from Products.CMFPlone.utils import get_installer
qi = get_installer(portal)
products = ('MimetypesRegistry', 'PortalTransforms', 'Archetypes', )
print >>out, 'Reinstalling Archetypes and it\'s dependencies'
for product in products:
if qi.isProductInstalled(product):
qi.reinstallProducts([product])
print >>out, '... reinstalling %s' % product
else:
qi.installProducts([product])
print >>out, '... installing %s' % product
full_product = 'Products.{0}'.format(product)
if qi.is_product_installed(full_product):
qi.uninstall_product(full_product)
print >>out, '... uninstalling %s' % full_product
qi.install_product(full_product)
print >>out, '... installing %s' % full_product
print >>out, 'Done\n'


Expand Down
21 changes: 12 additions & 9 deletions Products/Archetypes/Extensions/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,19 +306,22 @@ def setupEnvironment(self, out, types,
install_deps=1):

if install_deps:
qi = getToolByName(self, 'portal_quickinstaller', None)
if require_dependencies:
if not qi.isProductInstalled('CMFFormController'):
qi.installProduct('CMFFormController', locked=1)
# Import here so it does not break when you manage to
# get a too old CMFPlone with a too new Archetypes.
from Products.CMFPlone.utils import get_installer
qi = get_installer(self)
if not qi.is_product_installed('Products.CMFFormController'):
qi.install_product('Products.CMFFormController', locked=1)
print >>out, 'Installing CMFFormController'
if not qi.isProductInstalled('MimetypesRegistry'):
qi.installProduct('MimetypesRegistry')
if not qi.is_product_installed('Products.MimetypesRegistry'):
qi.install_product('Products.MimetypesRegistry')
print >>out, 'Installing MimetypesRegistry'
if not qi.isProductInstalled('PortalTransforms'):
qi.installProduct('PortalTransforms')
if not qi.is_product_installed('Products.PortalTransforms'):
qi.install_product('Products.PortalTransforms')
print >>out, 'Installing PortalTransforms'
if not qi.isProductInstalled('Archetypes'):
qi.installProduct('Archetypes')
if not qi.is_product_installed('Archetypes'):
qi.install_product('Products.Archetypes')
print >>out, 'Installing Archetypes'

if product_skins_dir:
Expand Down
1 change: 0 additions & 1 deletion Products/Archetypes/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<include package="plone.uuid" />

<include package="Products.CMFFormController" />
<include package="Products.CMFQuickInstallerTool" />
<include package="Products.MimetypesRegistry" />
<include package="Products.PortalTransforms" />
<include package="Products.statusmessages" />
Expand Down
185 changes: 117 additions & 68 deletions Products/Archetypes/tests/test_pawidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,19 @@ def setUp(self):
xmlconfig.file('configure.zcml', plone.uuid,
context=self.layer['configurationContext'])

def assertDictContainsSubset(self, dict_a, dict_b):
"""Since ``assertDictContainsSubset`` is deprecated in Python 3.2 we
provide a substitution here.
From: https://stackoverflow.com/a/21213251/1337474
"""
def extractDictAFromB(A, B):
return dict([(k, B[k]) for k in A.keys() if k in B.keys()])
self.assertEqual(dict_a, extractDictAFromB(dict_a, dict_b))

@mock.patch(
'plone.app.widgets.utils.getToolByName',
new=Mock(return_value=Mock(return_value='testuser'))
)
def test_multi_valued(self):
from zope.event import notify
from zope.interface import implementer
Expand All @@ -353,28 +366,37 @@ class ExampleContent(object):
self.field.multiValued = True

widget = RelatedItemsWidget()
base_args = widget._base_args(self.context, self.field, self.request)

self.assertEqual(
self.assertDictContainsSubset(
{
'name': 'fieldname',
'value': '{};{}'.format(IUUID(obj1), IUUID(obj2)),
'pattern': 'relateditems',
'pattern_options': {
'separator': ';',
'orderable': True,
'maximumSelectionSize': -1,
'vocabularyUrl': '/@@getVocabulary?name='
'plone.app.vocabularies.Catalog'
'&field=fieldname',
'basePath': '/Plone/doc',
'contextPath': '/Plone/doc',
'rootPath': '/',
'rootUrl': ''
},
},
widget._base_args(self.context, self.field, self.request),
base_args
)

self.assertDictContainsSubset(
{
'separator': ';',
'orderable': True,
'maximumSelectionSize': -1,
'vocabularyUrl': '/@@getVocabulary?name='
'plone.app.vocabularies.Catalog'
'&field=fieldname',
'basePath': '/Plone/doc',
'contextPath': '/Plone/doc',
'rootPath': '/',
'rootUrl': ''
},
base_args.get('pattern_options', {})
)

@mock.patch(
'plone.app.widgets.utils.getToolByName',
new=Mock(return_value=Mock(return_value='testuser'))
)
def test_single_value(self):
from zope.event import notify
from zope.interface import implementer
Expand All @@ -395,26 +417,35 @@ class ExampleContent(object):
self.field.multiValued = False

widget = RelatedItemsWidget()
base_args = widget._base_args(self.context, self.field, self.request)

self.assertEqual(
self.assertDictContainsSubset(
{
'name': 'fieldname',
'value': '{}'.format(IUUID(obj1)),
'pattern': 'relateditems',
'pattern_options': {
'separator': ';',
'orderable': True,
'maximumSelectionSize': 1,
'vocabularyUrl': '/@@getVocabulary?name=plone.app.vocabularies.Catalog&field=fieldname', # noqa
'basePath': '/Plone/doc',
'contextPath': '/Plone/doc',
'rootPath': '/',
'rootUrl': ''
},
},
widget._base_args(self.context, self.field, self.request),
base_args
)

self.assertDictContainsSubset(
{
'separator': ';',
'orderable': True,
'maximumSelectionSize': 1,
'vocabularyUrl': '/@@getVocabulary?name=plone.app.vocabularies.Catalog&field=fieldname', # noqa
'basePath': '/Plone/doc',
'contextPath': '/Plone/doc',
'rootPath': '/',
'rootUrl': ''
},
base_args.get('pattern_options', {})
)

@mock.patch(
'plone.app.widgets.utils.getToolByName',
new=Mock(return_value=Mock(return_value='testuser'))
)
def test_single_valued_empty(self):
from Products.Archetypes.Widget import RelatedItemsWidget

Expand All @@ -423,28 +454,37 @@ def test_single_valued_empty(self):
self.field.multiValued = False

widget = RelatedItemsWidget()
base_args = widget._base_args(self.context, self.field, self.request)

self.assertEqual(
self.assertDictContainsSubset(
{
'name': 'fieldname',
'value': '',
'pattern': 'relateditems',
'pattern_options': {
'separator': ';',
'orderable': True,
'maximumSelectionSize': 1,
'vocabularyUrl': '/@@getVocabulary?name='
'plone.app.vocabularies.Catalog'
'&field=fieldname',
'basePath': '/Plone/doc',
'contextPath': '/Plone/doc',
'rootPath': '/',
'rootUrl': '',
},
},
widget._base_args(self.context, self.field, self.request),
base_args
)

self.assertDictContainsSubset(
{
'separator': ';',
'orderable': True,
'maximumSelectionSize': 1,
'vocabularyUrl': '/@@getVocabulary?name='
'plone.app.vocabularies.Catalog'
'&field=fieldname',
'basePath': '/Plone/doc',
'contextPath': '/Plone/doc',
'rootPath': '/',
'rootUrl': '',
},
base_args.get('pattern_options', {})
)

@mock.patch(
'plone.app.widgets.utils.getToolByName',
new=Mock(return_value=Mock(return_value='testuser'))
)
def test_multiple_widgets(self):
from zope.event import notify
from Products.Archetypes.Widget import RelatedItemsWidget
Expand All @@ -471,26 +511,30 @@ class ExampleContent(object):
widget=RelatedItemsWidget(),
)
field1.accessor = "fieldvalue"
base_args1 = field1.widget._base_args(self.context, field1, self.request) # noqa

self.assertEqual(
self.assertDictContainsSubset(
{
'name': 'fieldname1',
'value': '{}'.format(IUUID(obj1)),
'pattern': 'relateditems',
'pattern_options': {
'separator': ';',
'orderable': True,
'maximumSelectionSize': 1,
'vocabularyUrl': '/@@getVocabulary?name='
'plone.app.vocabularies.Catalog'
'&field=fieldname1',
'basePath': '/Plone/doc',
'contextPath': '/Plone/doc',
'rootPath': '/',
'rootUrl': '',
},
},
field1.widget._base_args(self.context, field1, self.request),
base_args1
)
self.assertDictContainsSubset(
{
'separator': ';',
'orderable': True,
'maximumSelectionSize': 1,
'vocabularyUrl': '/@@getVocabulary?name='
'plone.app.vocabularies.Catalog'
'&field=fieldname1',
'basePath': '/Plone/doc',
'contextPath': '/Plone/doc',
'rootPath': '/',
'rootUrl': '',
},
base_args1.get('pattern_options', {})
)

field2 = ReferenceField(
Expand All @@ -501,26 +545,31 @@ class ExampleContent(object):
)
field2.accessor = "fieldvalue"
self.context.fieldvalue = lambda: [obj1, obj2]
base_args2 = field2.widget._base_args(self.context, field2, self.request) # noqa

self.assertEqual(
self.assertDictContainsSubset(
{
'name': 'fieldname2',
'value': '{};{}'.format(IUUID(obj1), IUUID(obj2)),
'pattern': 'relateditems',
'pattern_options': {
'separator': ';',
'orderable': True,
'maximumSelectionSize': -1,
'vocabularyUrl': '/@@getVocabulary?name='
'plone.app.vocabularies.Catalog'
'&field=fieldname2',
'basePath': '/Plone/doc',
'contextPath': '/Plone/doc',
'rootPath': '/',
'rootUrl': '',
},
},
field2.widget._base_args(self.context, field2, self.request),
base_args2
)

self.assertDictContainsSubset(
{
'separator': ';',
'orderable': True,
'maximumSelectionSize': -1,
'vocabularyUrl': '/@@getVocabulary?name='
'plone.app.vocabularies.Catalog'
'&field=fieldname2',
'basePath': '/Plone/doc',
'contextPath': '/Plone/doc',
'rootPath': '/',
'rootUrl': '',
},
base_args2.get('pattern_options', {})
)


Expand Down
12 changes: 5 additions & 7 deletions buildout.cfg
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
[buildout]
index = https://pypi.python.org/simple/
develop = .
parts = test
extends = http://dist.plone.org/release/5.1-latest/versions.cfg
https://raw.githubusercontent.com/plone/buildout.coredev/5.1/sources.cfg

# 2017-05-30 plone.app.widgets 2.1.1 does not suffice
# TODO get rid of auto-checkout when new release has happened
extensions = mr.developer
auto-checkout = plone.app.widgets

[versions]
Products.Archetypes =
Products.Archetypes =
# Keep in sync with .travis.yml:
setuptools = 38.2.4
zc.buildout = 2.11.0

[test]
recipe = zc.recipe.testrunner
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"Framework :: Plone",
"Framework :: Plone :: 5.1",
"Framework :: Zope2",
"License :: OSI Approved :: GNU General Public License (GPL)",
"Programming Language :: Python",
"Programming Language :: Python :: 2.7",
],
Expand Down Expand Up @@ -53,7 +54,6 @@
'zope.viewlet',
'Products.CMFCore',
'Products.CMFFormController',
'Products.CMFQuickInstallerTool',
'Products.DCWorkflow',
'Products.GenericSetup>=1.8.3',
'Products.MimetypesRegistry>=2.0.3',
Expand Down

0 comments on commit e25765a

Please sign in to comment.