1 | import unittest |
---|
2 | from quintagroup.pfg.captcha.field import CAPTCHA_ID |
---|
3 | from quintagroup.pfg.captcha.tests.base import TestCaseNotInstalled, \ |
---|
4 | REQUIREMENTS |
---|
5 | |
---|
6 | |
---|
7 | class TestMigration(TestCaseNotInstalled): |
---|
8 | """Migration perform recreation old CaptchaField |
---|
9 | objects from qPloneCaptchaField product to new |
---|
10 | CaptchaField from quintagroup.pfg.captcha package. |
---|
11 | |
---|
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. |
---|
16 | |
---|
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 | |
---|
28 | def afterSetUp(self): |
---|
29 | self.loginAsPortalOwner() |
---|
30 | self.qi = self.portal.portal_quickinstaller |
---|
31 | self.pt = self.portal.portal_types |
---|
32 | self.prepareToMigration() |
---|
33 | |
---|
34 | def beforeTearDown(self): |
---|
35 | self.qi.uninstallProducts(["quintagroup.pfg.captcha", ]) |
---|
36 | |
---|
37 | def prepareToMigration(self): |
---|
38 | # Install types |
---|
39 | for p in REQUIREMENTS: |
---|
40 | if not self.qi.isProductInstalled(p): |
---|
41 | self.qi.installProduct(p) |
---|
42 | # Add captcha field |
---|
43 | self.portal.invokeFactory("FormFolder", 'test_form') |
---|
44 | test_form = self.portal['test_form'] |
---|
45 | test_form.invokeFactory("CaptchaField", CAPTCHA_ID) |
---|
46 | self.cf_path = "test_form/key" |
---|
47 | self.old_cf = self.portal.unrestrictedTraverse(self.cf_path) |
---|
48 | self.assert_(self.old_cf) |
---|
49 | self.pt['CaptchaField'].manage_changeProperties( |
---|
50 | product="qPloneCaptchaField") |
---|
51 | self.qi.manage_delObjects('quintagroup.pfg.captcha') |
---|
52 | |
---|
53 | def testMigration(self): |
---|
54 | self.addProduct("quintagroup.pfg.captcha") |
---|
55 | new_cf = self.portal.unrestrictedTraverse(self.cf_path) |
---|
56 | self.assert_(self.old_cf != new_cf) |
---|
57 | |
---|
58 | |
---|
59 | def test_suite(): |
---|
60 | suite = unittest.TestSuite() |
---|
61 | suite.addTest(unittest.makeSuite(TestMigration)) |
---|
62 | return suite |
---|