Skip to content

Commit

Permalink
Merge pull request #20 from collective/hvelarde-pin-responsivevoice
Browse files Browse the repository at this point in the history
Use version 1.4 of the ResponsiveVoice API
  • Loading branch information
hvelarde committed Jun 13, 2016
2 parents 5a297c2 + daa9a52 commit 558b550
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 55 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Changelog
1.0b1 (unreleased)
------------------

- Use version 1.4 of the ResponsiveVoice API.
[hvelarde]

- Package is now compatible with Plone 5.0 and Plone 5.1.
[rodfersou, hvelarde]

Expand Down
5 changes: 5 additions & 0 deletions src/collective/texttospeech/config.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# -*- coding: utf-8 -*-
from plone import api


PROJECTNAME = 'collective.texttospeech'

# by default, all standard content types will be enabled
DEFAULT_ENABLED_CONTENT_TYPES = [
'Document',
'News Item'
]

IS_PLONE_5 = api.env.plone_version().startswith('5')
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<object name="portal_javascripts">
<javascript id="//code.responsivevoice.org/responsivevoice.js"
<javascript id="//code.responsivevoice.org/1.4/responsivevoice.js"
cacheable="False" compression="none" cookable="False" enabled="True"
expression="" inline="False" authenticated="False" insert-after="*" />
<javascript id="++resource++collective.texttospeech/main.js"
Expand Down
4 changes: 0 additions & 4 deletions src/collective/texttospeech/testing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
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
Expand All @@ -8,9 +7,6 @@
from plone.testing import z2


IS_PLONE_5 = api.env.plone_version().startswith('5')


class Fixture(PloneSandboxLayer):

defaultBases = (PLONE_FIXTURE,)
Expand Down
49 changes: 0 additions & 49 deletions src/collective/texttospeech/tests/test_resources.py

This file was deleted.

31 changes: 31 additions & 0 deletions src/collective/texttospeech/tests/test_setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
"""Ensure add-on is properly installed and uninstalled."""
from collective.texttospeech.config import IS_PLONE_5
from collective.texttospeech.config import PROJECTNAME
from collective.texttospeech.interfaces import IBrowserLayer
from collective.texttospeech.testing import INTEGRATION_TESTING
Expand All @@ -8,6 +9,14 @@
import unittest


JAVASCRIPTS = (
'//code.responsivevoice.org/1.4/responsivevoice.js',
'++resource++collective.texttospeech/main.js',
)

CSS = '++resource++collective.texttospeech/main.css'


class InstallTestCase(unittest.TestCase):

"""Ensure product is properly installed."""
Expand All @@ -24,6 +33,17 @@ def test_installed(self):
def test_addon_layer(self):
self.assertIn(IBrowserLayer, registered_layers())

@unittest.skipIf(IS_PLONE_5, 'No easy way to test this under Plone 5')
def test_jsregistry(self):
resource_ids = self.portal.portal_javascripts.getResourceIds()
for id_ in JAVASCRIPTS:
self.assertIn(id_, resource_ids, id_ + ' not installed')

@unittest.skipIf(IS_PLONE_5, 'No easy way to test this under Plone 5')
def test_cssregistry(self):
resource_ids = self.portal.portal_css.getResourceIds()
self.assertIn(CSS, resource_ids)

def test_setup_permission(self):
permission = 'collective.texttospeech: Setup'
roles = self.portal.rolesOfPermission(permission)
Expand Down Expand Up @@ -54,3 +74,14 @@ def test_uninstalled(self):

def test_addon_layer_removed(self):
self.assertNotIn(IBrowserLayer, registered_layers())

@unittest.skipIf(IS_PLONE_5, 'No easy way to test this under Plone 5')
def test_jsregistry_removed(self):
resource_ids = self.portal.portal_javascripts.getResourceIds()
for id_ in JAVASCRIPTS:
self.assertNotIn(id_, resource_ids, id_ + ' not removed')

@unittest.skipIf(IS_PLONE_5, 'No easy way to test this under Plone 5')
def test_cssregistry_removed(self):
resource_ids = self.portal.portal_css.getResourceIds()
self.assertNotIn(CSS, resource_ids)
25 changes: 24 additions & 1 deletion src/collective/texttospeech/tests/test_upgrades.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
from collective.texttospeech.config import IS_PLONE_5
from collective.texttospeech.testing import INTEGRATION_TESTING
from plone import api

import unittest

Expand Down Expand Up @@ -40,4 +42,25 @@ def test_profile_version(self):

def test_registered_steps(self):
steps = len(self.setup.listUpgrades(self.profile_id)[0])
self.assertEqual(steps, 2)
self.assertEqual(steps, 3)

@unittest.skipIf(IS_PLONE_5, 'Upgrade step not supported under Plone 5')
def test_pin_responsivevoice(self):
# check if the upgrade step is registered
title = u'Use version 1.4 of the ResponsiveVoice API'
step = self._get_upgrade_step_by_title(title)
assert step is not None

# simulate state on previous version
from collective.texttospeech.upgrades.v2 import NEW_JS
from collective.texttospeech.upgrades.v2 import OLD_JS
portal_js = api.portal.get_tool('portal_javascripts')
# HACK: can not use portal_js.renameResource
# see: https://github.com/plone/Products.ResourceRegistries/pull/20
portal_js.getResource(NEW_JS)._data['id'] = OLD_JS
assert OLD_JS in portal_js.getResourceIds()

# run the upgrade step to validate the update
self._do_upgrade(step)
self.assertNotIn(OLD_JS, portal_js.getResourceIds())
self.assertIn(NEW_JS, portal_js.getResourceIds())
21 changes: 21 additions & 0 deletions src/collective/texttospeech/upgrades/v2/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,22 @@
# -*- coding: utf-8 -*-
from collective.texttospeech.config import IS_PLONE_5
from collective.texttospeech.logger import logger
from plone import api


NEW_JS = '//code.responsivevoice.org/1.4/responsivevoice.js'
OLD_JS = '//code.responsivevoice.org/responsivevoice.js'


def pin_responsivevoice(setup_tool):
"""Use version 1.4 of the ResponsiveVoice API."""
if IS_PLONE_5:
return # upgrade step not supported under Plone 5

portal_js = api.portal.get_tool('portal_javascripts')
if OLD_JS in portal_js.getResourceIds():
# HACK: can not use portal_js.renameResource
# see: https://github.com/plone/Products.ResourceRegistries/pull/20
portal_js.getResource(OLD_JS)._data['id'] = NEW_JS
assert NEW_JS in portal_js.getResourceIds()
logger.info('ResponsiveVoice version updated to 1.4.')
6 changes: 6 additions & 0 deletions src/collective/texttospeech/upgrades/v2/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
destination="2"
profile="collective.texttospeech:default">

<genericsetup:upgradeStep
title="Use version 1.4 of the ResponsiveVoice API"
description=""
handler=".pin_responsivevoice"
/>

<genericsetup:upgradeStep
title="Cook CSS resources"
description="There were changes in the CSS files, so we need to cook the resources."
Expand Down

0 comments on commit 558b550

Please sign in to comment.