-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Caching issues with WhatsApp button
- Loading branch information
Showing
15 changed files
with
170 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0"?> | ||
<object name="portal_javascripts" purge="False"> | ||
<javascript id="++resource++sl_scripts/social_like.js" | ||
cacheable="True" compression="safe" cookable="True" enabled="True" | ||
inline="False" authenticated="False" | ||
insert-after="*" /> | ||
</object> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<?xml version="1.0"?> | ||
<metadata> | ||
<version>3020</version> | ||
<version>3030</version> | ||
</metadata> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# -*- coding: utf-8 -*- | ||
from plone import api | ||
from sc.social.like.testing import INTEGRATION_TESTING | ||
|
||
import unittest | ||
|
||
|
||
class UpgradeTestCaseBase(unittest.TestCase): | ||
|
||
layer = INTEGRATION_TESTING | ||
|
||
def setUp(self, from_version, to_version): | ||
self.portal = self.layer['portal'] | ||
self.setup = self.portal['portal_setup'] | ||
self.profile_id = u'sc.social.like:default' | ||
self.from_version = from_version | ||
self.to_version = to_version | ||
|
||
def get_upgrade_step(self, title): | ||
"""Get the named upgrade step.""" | ||
self.setup.setLastVersionForProfile(self.profile_id, self.from_version) | ||
upgrades = self.setup.listUpgrades(self.profile_id) | ||
steps = [s for s in upgrades[0] if s['title'] == title] | ||
return steps[0] if steps else None | ||
|
||
def execute_upgrade_step(self, step): | ||
"""Execute an upgrade step.""" | ||
request = self.layer['request'] | ||
request.form['profile_id'] = self.profile_id | ||
request.form['upgrades'] = [step['id']] | ||
self.setup.manage_doUpgrades(request=request) | ||
|
||
@property | ||
def total_steps(self): | ||
"""Return the number of steps in the upgrade.""" | ||
self.setup.setLastVersionForProfile(self.profile_id, self.from_version) | ||
upgrades = self.setup.listUpgrades(self.profile_id) | ||
assert len(upgrades) > 0 | ||
return len(upgrades[0]) | ||
|
||
|
||
class Upgrade1to2TestCase(UpgradeTestCaseBase): | ||
|
||
def setUp(self): | ||
UpgradeTestCaseBase.setUp(self, u'3020', u'3030') | ||
|
||
def test_upgrade_to_3030_registrations(self): | ||
version = self.setup.getLastVersionForProfile(self.profile_id)[0] | ||
self.assertTrue(int(version) >= int(self.to_version)) | ||
self.assertEqual(self.total_steps, 3) | ||
|
||
def test_update_resource_conditions(self): | ||
# check if the upgrade step is registered | ||
title = u'Fix caching for WhatsApp' | ||
step = self.get_upgrade_step(title) | ||
self.assertTrue(step is not None) | ||
|
||
js_tool = api.portal.get_tool('portal_javascripts') | ||
JS_ID = '++resource++sl_scripts/social_like.js' | ||
|
||
# simulate state on previous version | ||
js_tool.unregisterResource(JS_ID) | ||
|
||
# run the upgrade step to validate the update | ||
self.execute_upgrade_step(step) | ||
|
||
# Check | ||
self.assertIn(JS_ID, js_tool.getResourceIds()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,21 @@ | ||
# -*- coding:utf-8 -*- | ||
from plone import api | ||
from sc.social.like.config import PROJECTNAME | ||
|
||
import logging | ||
|
||
logger = logging.getLogger(PROJECTNAME) | ||
|
||
|
||
def cook_css_resources(context): | ||
"""Cook css resources.""" | ||
css_tool = api.portal.get_tool('portal_css') | ||
css_tool.cookResources() | ||
logger.info('CSS resources were cooked') | ||
|
||
|
||
def cook_javascript_resources(context): | ||
"""Cook javascript resources.""" | ||
js_tool = api.portal.get_tool('portal_javascripts') | ||
js_tool.cookResources() | ||
logger.info('Javascript resources were cooked') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# -*- coding:utf-8 -*- | ||
from sc.social.like.config import PROJECTNAME | ||
|
||
import logging | ||
|
||
logger = logging.getLogger(PROJECTNAME) | ||
|
||
|
||
def fix_caching_for_whatsapp(setup_tool): | ||
"""Fix caching for WhatsApp.""" | ||
profile = 'profile-{0}:default'.format(PROJECTNAME) | ||
setup_tool.runImportStepFromProfile(profile, 'jsregistry') | ||
logger.info('Caching for WhatsApp were fixed.') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<configure | ||
xmlns="http://namespaces.zope.org/zope" | ||
xmlns:gs="http://namespaces.zope.org/genericsetup" | ||
i18n_domain="sc.social.like"> | ||
|
||
<gs:upgradeSteps | ||
source="3020" | ||
destination="3030" | ||
profile="sc.social.like:default"> | ||
|
||
<gs:upgradeStep | ||
title="Fix caching for WhatsApp" | ||
description="Fix caching issues with WhatsApp button" | ||
handler=".fix_caching_for_whatsapp" | ||
/> | ||
|
||
<gs:upgradeStep | ||
title="Cook CSS resources" | ||
description="There were changes in the CSS files, so we need to cook the resources." | ||
handler="..cook_css_resources" | ||
/> | ||
|
||
<gs:upgradeStep | ||
title="Cook JS resources" | ||
description="There were changes in the JS files, so we need to cook the resources." | ||
handler="..cook_javascript_resources" | ||
/> | ||
|
||
</gs:upgradeSteps> | ||
|
||
</configure> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters