1 | # |
---|
2 | # Tests for quintagroup.plonegooglesitemaps upgrading |
---|
3 | # |
---|
4 | |
---|
5 | from base import * |
---|
6 | from Products.CMFPlone.utils import _createObjectByType |
---|
7 | from Products.GenericSetup.upgrade import _upgrade_registry |
---|
8 | from quintagroup.canonicalpath.interfaces import ICanonicalPath |
---|
9 | from quintagroup.canonicalpath.interfaces import ICanonicalLink |
---|
10 | |
---|
11 | class TestUpgrade(TestCase): |
---|
12 | |
---|
13 | def afterSetUp(self): |
---|
14 | self.setup = self.portal.portal_setup |
---|
15 | self.profile = "quintagroup.plonegooglesitemaps:default" |
---|
16 | |
---|
17 | def getUpgradeStep(self, sortkey): |
---|
18 | upgrades = self.setup.listUpgrades(self.profile, show_old=True) |
---|
19 | upgrade_id = upgrades[sortkey-1]["id"] |
---|
20 | step = _upgrade_registry.getUpgradeStep(self.profile, upgrade_id) |
---|
21 | return step |
---|
22 | |
---|
23 | def test_upgradeStepsRegistration(self): |
---|
24 | # Test upgrade steps |
---|
25 | upgrades = self.setup.listUpgrades(self.profile, show_old=True) |
---|
26 | self.assertEqual(len(upgrades), 2) |
---|
27 | self.assertEqual(upgrades[0]["title"].endswith("1.0 to 1.1"), True) |
---|
28 | self.assertEqual(upgrades[1]["title"].endswith("1.1 to 1.2"), True) |
---|
29 | |
---|
30 | def test_upgradeSetupRegistration(self): |
---|
31 | # Test registered upgrade profiles |
---|
32 | pids = [i['id'] for i in self.setup.listProfileInfo()] |
---|
33 | self.assertEqual("quintagroup.plonegooglesitemaps:upgrade_1_0_to_1_1" in pids, True) |
---|
34 | self.assertEqual("quintagroup.plonegooglesitemaps:upgrade_1_1_to_1_2" in pids, True) |
---|
35 | |
---|
36 | def test_step_1_0_to_1_1(self): |
---|
37 | # Prepare testing data |
---|
38 | catalog = self.portal.portal_catalog |
---|
39 | if "canonical_path" in catalog._catalog.names: |
---|
40 | catalog.delColumn("canonical_path") |
---|
41 | # Upgrade to 1.1 version |
---|
42 | step = self.getUpgradeStep(1) |
---|
43 | if step is not None: |
---|
44 | step.doStep(self.setup) |
---|
45 | # canonical_path column must be added to portal_catalog |
---|
46 | self.assertEqual("canonical_path" in catalog._catalog.names, True) |
---|
47 | |
---|
48 | def test_step_1_1_to_1_2(self): |
---|
49 | # Prepare testing data |
---|
50 | catalog = self.portal.portal_catalog |
---|
51 | doc = _createObjectByType('Document', self.portal, id='test_doc') |
---|
52 | ICanonicalPath(doc).canonical_path = "/my_test_doc" |
---|
53 | if not "canonical_path" in catalog._catalog.names: |
---|
54 | catalog.addColumn("canonical_path") |
---|
55 | # Upgrade to 1.2 versionb |
---|
56 | step = self.getUpgradeStep(2) |
---|
57 | if step is not None: |
---|
58 | step.doStep(self.setup) |
---|
59 | # canonical_link column replace canonical_path one in the portal_catalog |
---|
60 | self.assertEqual("canonical_link" in catalog._catalog.names, True) |
---|
61 | self.assertEqual("canonical_path" in catalog._catalog.names, False) |
---|
62 | # canonical_link property refactored from canonical_path one for the object |
---|
63 | migrated_link = self.portal.absolute_url() + '/my_test_doc' |
---|
64 | self.assertNotEqual(ICanonicalPath(doc).canonical_path, "/my_test_doc") |
---|
65 | self.assertEqual(ICanonicalLink(doc).canonical_link, migrated_link) |
---|
66 | # canonical_link brain must contains updated canonical_link data |
---|
67 | brain = catalog(id="test_doc")[0] |
---|
68 | self.assertEqual(brain.canonical_link, migrated_link) |
---|
69 | |
---|
70 | |
---|
71 | def test_suite(): |
---|
72 | from unittest import TestSuite, makeSuite |
---|
73 | suite = TestSuite() |
---|
74 | suite.addTest(makeSuite(TestUpgrade)) |
---|
75 | return suite |
---|
76 | |
---|
77 | if __name__ == '__main__': |
---|
78 | unittest.main(defaultTest='test_suite') |
---|
79 | # framework() |
---|