-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
141 additions
and
37 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
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from collective.weather.testing import INTEGRATION_TESTING | ||
from plone.registry import field | ||
from plone.registry.interfaces import IRegistry | ||
from plone.registry.record import Record | ||
from zope.component import getUtility | ||
|
||
import unittest2 as 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'collective.weather:default' | ||
self.from_version = from_version | ||
self.to_version = to_version | ||
|
||
def _get_upgrade_step(self, title): | ||
"""Get one of the upgrade steps. | ||
Keyword arguments: | ||
title -- the title used to register the 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 _do_upgrade_step(self, step): | ||
"""Execute an upgrade step. | ||
Keyword arguments: | ||
step -- the step we want to run | ||
""" | ||
request = self.layer['request'] | ||
request.form['profile_id'] = self.profile_id | ||
request.form['upgrades'] = [step['id']] | ||
self.setup.manage_doUpgrades(request=request) | ||
|
||
def _how_many_upgrades_to_do(self): | ||
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'1', u'2') | ||
|
||
def test_upgrade_to_2_registrations(self): | ||
version = self.setup.getLastVersionForProfile(self.profile_id)[0] | ||
self.assertTrue(version >= self.to_version) | ||
self.assertEqual(self._how_many_upgrades_to_do(), 1) | ||
|
||
def test_code_clean_up(self): | ||
# check if the upgrade step is registered | ||
title = u'code_clean_up' | ||
description = u'Remove all Google Weather related code.' | ||
step = self._get_upgrade_step(title) | ||
self.assertIsNotNone(step) | ||
self.assertEqual(step['description'], description) | ||
|
||
# simulate state on previous version | ||
registry = getUtility(IRegistry) | ||
BASE_REGISTRY = 'collective.weather.browser.interfaces.IGoogleWeatherSchema.{0}' | ||
records = [ | ||
BASE_REGISTRY.format('use_google'), | ||
BASE_REGISTRY.format('google_location_ids'), | ||
BASE_REGISTRY.format('google_language'), | ||
BASE_REGISTRY.format('google_units'), | ||
] | ||
|
||
for r in records: | ||
registry.records[r] = Record(field.TextLine(title=u'Test')) | ||
self.assertIn(r, registry) | ||
|
||
# run the upgrade step to validate the update | ||
self._do_upgrade_step(step) | ||
|
||
for r in records: | ||
self.assertNotIn(r, registry) |
Empty file.
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,5 @@ | ||
<configure xmlns="http://namespaces.zope.org/zope"> | ||
|
||
<include package=".v2" /> | ||
|
||
</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
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,26 @@ | ||
<configure | ||
xmlns="http://namespaces.zope.org/zope" | ||
xmlns:genericsetup="http://namespaces.zope.org/genericsetup"> | ||
|
||
<genericsetup:registerProfile | ||
name="default" | ||
title="collective.weather: version 2" | ||
directory="profile" | ||
description="Upgrade collective.weather profile to version 2." | ||
provides="Products.GenericSetup.interfaces.EXTENSION" | ||
/> | ||
|
||
<genericsetup:upgradeSteps | ||
source="1" | ||
destination="2" | ||
profile="collective.weather:default"> | ||
|
||
<genericsetup:upgradeStep | ||
title="code_clean_up" | ||
description="Remove all Google Weather related code." | ||
handler=".code_clean_up" | ||
/> | ||
|
||
</genericsetup: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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0"?> | ||
<registry> | ||
<record name="collective.weather.browser.interfaces.IGoogleWeatherSchema.use_google" delete="true" /> | ||
<record name="collective.weather.browser.interfaces.IGoogleWeatherSchema.google_location_ids" delete="true" /> | ||
<record name="collective.weather.browser.interfaces.IGoogleWeatherSchema.google_language" delete="true" /> | ||
<record name="collective.weather.browser.interfaces.IGoogleWeatherSchema.google_units" delete="true" /> | ||
</registry> |