[3168] | 1 | import unittest |
---|
[3426] | 2 | from quintagroup.pfg.captcha.field import CAPTCHA_ID |
---|
[3212] | 3 | from quintagroup.pfg.captcha.tests.base import TestCaseNotInstalled, \ |
---|
| 4 | REQUIREMENTS |
---|
[2732] | 5 | |
---|
[3168] | 6 | |
---|
[2732] | 7 | class TestMigration(TestCaseNotInstalled): |
---|
[2734] | 8 | """Migration perform recreation old CaptchaField |
---|
| 9 | objects from qPloneCaptchaField product to new |
---|
| 10 | CaptchaField from quintagroup.pfg.captcha package. |
---|
[2732] | 11 | |
---|
[2734] | 12 | Migration based on: |
---|
| 13 | * presence old portal type CaptchaField with |
---|
| 14 | "qPloneCaptchaField" value in *product* field. |
---|
| 15 | * presence of CaptchaField objects on the site. |
---|
[2732] | 16 | |
---|
[2734] | 17 | This TestCase emulate migration with: |
---|
| 18 | 1. Install new quintagroup.pfg.captcha package |
---|
| 19 | and add test CaptchaField object. |
---|
| 20 | 2. Change *product" field value in |
---|
| 21 | portal_tyeps/CaptchaField FTI |
---|
| 22 | Then it install quintagroup.pfg.captcha and test if |
---|
| 23 | tested CaptchaField object is recreated and *product* |
---|
| 24 | field for portal_type/CaptchaField is changed to |
---|
| 25 | quintagroup.pfg.captcha. |
---|
| 26 | """ |
---|
| 27 | |
---|
[2732] | 28 | def afterSetUp(self): |
---|
| 29 | self.loginAsPortalOwner() |
---|
[2734] | 30 | self.qi = self.portal.portal_quickinstaller |
---|
| 31 | self.pt = self.portal.portal_types |
---|
| 32 | self.prepareToMigration() |
---|
[2732] | 33 | |
---|
[2734] | 34 | def beforeTearDown(self): |
---|
[3168] | 35 | self.qi.uninstallProducts(["quintagroup.pfg.captcha", ]) |
---|
[2732] | 36 | |
---|
[2734] | 37 | def prepareToMigration(self): |
---|
| 38 | # Install types |
---|
[3212] | 39 | for p in REQUIREMENTS: |
---|
| 40 | if not self.qi.isProductInstalled(p): |
---|
| 41 | self.qi.installProduct(p) |
---|
[2734] | 42 | # Add captcha field |
---|
| 43 | self.portal.invokeFactory("FormFolder", 'test_form') |
---|
| 44 | test_form = self.portal['test_form'] |
---|
[3426] | 45 | test_form.invokeFactory("CaptchaField", CAPTCHA_ID) |
---|
[2734] | 46 | self.cf_path = "test_form/key" |
---|
[3168] | 47 | self.old_cf = self.portal.unrestrictedTraverse(self.cf_path) |
---|
[2734] | 48 | self.assert_(self.old_cf) |
---|
[3168] | 49 | self.pt['CaptchaField'].manage_changeProperties( |
---|
| 50 | product="qPloneCaptchaField") |
---|
[2734] | 51 | self.qi.manage_delObjects('quintagroup.pfg.captcha') |
---|
[2732] | 52 | |
---|
[2734] | 53 | def testMigration(self): |
---|
| 54 | self.addProduct("quintagroup.pfg.captcha") |
---|
[3168] | 55 | new_cf = self.portal.unrestrictedTraverse(self.cf_path) |
---|
[2734] | 56 | self.assert_(self.old_cf != new_cf) |
---|
| 57 | |
---|
| 58 | |
---|
[2732] | 59 | def test_suite(): |
---|
| 60 | suite = unittest.TestSuite() |
---|
| 61 | suite.addTest(unittest.makeSuite(TestMigration)) |
---|
| 62 | return suite |
---|