Skip to content

Commit

Permalink
Merge pull request #81 from collective/python3
Browse files Browse the repository at this point in the history
Added support for Python 3 during PloneConf2018's Sprint at Microsoft, Tokyo!!
  • Loading branch information
Shriyanshagro committed Nov 10, 2018
2 parents ae564a9 + 12e0389 commit 2153458
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 28 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Changelog
1.0.3 (unreleased)
------------------

- Nothing changed yet.
- Add Support for Python 3.
[pbauer, staeff, Shriyanshagro]


1.0.2 (2018-08-14)
Expand Down
7 changes: 5 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@
setup(
name='collective.ifttt',
version='1.0.3.dev0',
description=
"This addon is developed to make use of IFTTT webhook with Plone",
description="Plone addon to make use of IFTTT webhook with Plone",
long_description=long_description,
# Get more from https://pypi.python.org/pypi?%3Aaction=list_classifiers
classifiers=[
"Environment :: Web Environment",
"Framework :: Plone",
"Framework :: Plone :: 5.0",
"Framework :: Plone :: 5.1",
"Framework :: Plone :: 5.2",
"Programming Language :: Python",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Operating System :: OS Independent",
"License :: OSI Approved :: GNU General Public License v2 (GPLv2)",
],
Expand All @@ -45,6 +47,7 @@
'setuptools',
'z3c.jbot',
'requests',
'six',
],
extras_require={
'test': [
Expand Down
3 changes: 2 additions & 1 deletion src/collective/ifttt/actions/ifttt.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from plone.contentrules.rule.interfaces import IExecutable
from plone.contentrules.rule.interfaces import IRuleElementData
from plone.event.interfaces import IEventAccessor
from Products.CMFPlone.utils import safe_unicode
from zope import schema
from zope.component import adapter
from zope.component import queryMultiAdapter
Expand Down Expand Up @@ -107,7 +108,7 @@ def __init__(self, context, element, event):
def __call__(self, *args, **kwargs):
ifttt_event_name = self.element.ifttt_event_name
payload_option = self.element.payload_option
title = self.context.Title().decode('utf-8', 'ignore')
title = safe_unicode(self.context.Title())
url = self.context.absolute_url()
secret_key = api.portal.get_registry_record('ifttt.ifttt_secret_key')
ifttt_trigger_url = 'https://maker.ifttt.com/trigger/' + \
Expand Down
6 changes: 3 additions & 3 deletions src/collective/ifttt/browser/content_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from plone.autoform import directives as forms
from plone.autoform.form import AutoExtensibleForm
from Products.CMFCore.interfaces._events import IActionSucceededEvent
from Products.CMFPlone.utils import safe_unicode
from z3c.form import button
from z3c.form import form
from zope import schema
Expand Down Expand Up @@ -129,17 +130,16 @@ def handleApply(self, action):
u'${ifttt_event_name} to ${title}',
mapping=dict(
ifttt_event_name=data.get('ifttt_event_name'),
title=self.context.Title().decode('utf-8', 'ignore'),
title=safe_unicode(self.context.Title()),
),
),
request=getRequest(),
type='info'
)

except Exception as er:

logger.exception(
u'Unexpected exception: {0:s}'.format(er),
u'Unexpected exception: {0:s}'.format(str(er)),
) # noqa

# Redirect back to the front page with a status message
Expand Down
3 changes: 2 additions & 1 deletion src/collective/ifttt/browser/event_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from plone.autoform import directives as forms
from plone.autoform.form import AutoExtensibleForm
from Products.CMFCore.interfaces._events import IActionSucceededEvent
from Products.CMFPlone.utils import safe_unicode
from z3c.form import button
from z3c.form import form
from zope import schema
Expand Down Expand Up @@ -119,7 +120,7 @@ def handleApply(self, action):
u'${ifttt_event_name} to ${title}',
mapping=dict(
ifttt_event_name=data.get('ifttt_event_name'),
title=self.context.Title().decode('utf-8', 'ignore'),
title=safe_unicode(self.context.Title()),
),
),
request=getRequest(),
Expand Down
2 changes: 1 addition & 1 deletion src/collective/ifttt/browser/manage_trigger.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# -*- coding: utf-8 -*-

from collective.ifttt import _
from collective.ifttt.browser.views import availableTriggers
from plone import api
from plone.autoform import directives as forms
from plone.autoform.form import AutoExtensibleForm
from plone.contentrules.engine.interfaces import IRuleStorage
from views import availableTriggers
from z3c.form import button
from z3c.form import form
from z3c.form.browser.checkbox import CheckBoxFieldWidget
Expand Down
3 changes: 2 additions & 1 deletion src/collective/ifttt/browser/user_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from plone.app.z3cform.widget import SelectFieldWidget
from plone.autoform import directives as forms
from plone.autoform.form import AutoExtensibleForm
from Products.CMFPlone.utils import safe_unicode
from z3c.form import button
from z3c.form import form
from zope import schema
Expand Down Expand Up @@ -111,7 +112,7 @@ def handleApply(self, action):
u'${ifttt_event_name} to ${title}',
mapping=dict(
ifttt_event_name=data.get('ifttt_event_name'),
title=self.context.Title().decode('utf-8', 'ignore'),
title=safe_unicode(self.context.Title()),
),
),
request=getRequest(),
Expand Down
2 changes: 1 addition & 1 deletion src/collective/ifttt/tests/test_easyforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from plone.app import testing
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
from StringIO import StringIO
from six import StringIO
from zope.testing.loggingsupport import InstalledHandler
from ZPublisher.HTTPRequest import HTTPRequest
from ZPublisher.HTTPResponse import HTTPResponse
Expand Down
15 changes: 6 additions & 9 deletions src/collective/ifttt/tests/test_iftttaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,20 @@ def test_AddFormView(self):

addview.form_instance.update()

payload_option = payload_options.by_value.keys()

for i in range(len(payload_option)):
for index, option in enumerate(payload_options):

content = addview.form_instance.create(
data={
'ifttt_event_name': 'ifttt_applet',
'payload_option': payload_option[i],
'payload_option': option,
}
)
addview.form_instance.add(content)

e = rule.actions[i]
e = rule.actions[index]
self.assertTrue(isinstance(e, IftttTriggerAction))
self.assertEqual('ifttt_applet', e.ifttt_event_name)
self.assertEqual(payload_option[i], e.payload_option)
self.assertEqual(option, e.payload_option)

def test_EditFormView(self):
element = getUtility(IRuleAction, name='plone.actions.Ifttt')
Expand All @@ -90,13 +88,12 @@ def test_ActionExecutor(self):
value=u'secret',
)
element.ifttt_event_name = 'ifttt_applet'
payload_option = payload_options.by_value.keys()

for i in range(len(payload_option)):
for option in payload_options:
# inspect logs
handler = InstalledHandler('collective.ifttt.requests')

element.payload_option = payload_option[i]
element.payload_option = option.value
ex = getMultiAdapter((context, element, DummyEvent(self.folder)),
IExecutable)
self.assertTrue(ex())
Expand Down
13 changes: 8 additions & 5 deletions src/collective/ifttt/tests/test_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
from Products.CMFPlone.interfaces import INonInstallable
from Products.CMFPlone.utils import get_installer
from zope.component import getAllUtilitiesRegisteredFor

import unittest
Expand All @@ -18,12 +19,13 @@ class TestSetup(unittest.TestCase):
def setUp(self):
"""Custom shared utility setup for tests."""
self.portal = self.layer['portal']
self.installer = api.portal.get_tool('portal_quickinstaller')
self.installer = get_installer(self.portal, self.layer['request'])
self.setup = api.portal.get_tool('portal_setup')

def test_product_installed(self):
"""Test if collective.ifttt is installed."""
self.assertTrue(self.installer.isProductInstalled('collective.ifttt'))
self.assertTrue(
self.installer.is_product_installed('collective.ifttt'))

def test_product_upgrade(self):
"""Test if collective.ifttt can be upgraded."""
Expand Down Expand Up @@ -54,10 +56,10 @@ class TestUninstall(unittest.TestCase):

def setUp(self):
self.portal = self.layer['portal']
self.installer = api.portal.get_tool('portal_quickinstaller')
self.installer = get_installer(self.portal, self.layer['request'])
roles_before = api.user.get_roles(TEST_USER_ID)
setRoles(self.portal, TEST_USER_ID, ['Manager'])
self.installer.uninstallProducts(['collective.ifttt'])
self.installer.uninstall_product('collective.ifttt')
setRoles(self.portal, TEST_USER_ID, roles_before)

def test_hidden_uninstall_profile(self):
Expand All @@ -70,7 +72,8 @@ def test_hidden_uninstall_profile(self):

def test_product_uninstalled(self):
"""Test if collective.ifttt is cleanly uninstalled."""
self.assertFalse(self.installer.isProductInstalled('collective.ifttt'))
self.assertFalse(
self.installer.is_product_installed('collective.ifttt'))

def test_browserlayer_removed(self):
"""Test that ICollectiveIftttLayer is removed."""
Expand Down
7 changes: 4 additions & 3 deletions src/collective/ifttt/utils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# -*- coding: utf-8 -*-

from collective.ifttt import _
from interfaces import IFTTTMarker
from collective.ifttt.interfaces import IFTTTMarker
from plone import api
from plone.app.contentrules import api as rules_api
from plone.contentrules.engine.interfaces import IRuleStorage
from plone.contentrules.rule.interfaces import IRuleAction
from plone.contentrules.rule.interfaces import IRuleCondition
from Products.CMFPlone.utils import safe_unicode
from Products.statusmessages import STATUSMESSAGEKEY
from zope.annotation.interfaces import IAnnotations
from zope.component import getMultiAdapter
Expand Down Expand Up @@ -41,7 +42,7 @@ def add_rule(self, data, trigger_type):
trigger_type=trigger_type,
ifttt_event_name=data.get('ifttt_event_name'),
content_types=(', ').join(data.get('content_types')),
title=self.context.Title().decode('utf-8', 'ignore'),
title=self.context.Title(),
path=self.context.absolute_url_path(),
)
)
Expand All @@ -51,7 +52,7 @@ def add_rule(self, data, trigger_type):
u'"${ifttt_event_name}" on the ${title} folder',
mapping=dict(
ifttt_event_name=data.get('ifttt_event_name'),
title=self.context.Title().decode('utf-8', 'ignore'),
title=safe_unicode(self.context.Title()),
)
)

Expand Down

0 comments on commit 2153458

Please sign in to comment.