| 65 | | class IntegrationTestCase(CPSTestCase): |
|---|
| | 65 | class CommonIntegrationFixture: |
|---|
| | 66 | """ Things like site structure and such.""" |
|---|
| | 67 | |
|---|
| | 68 | def fixtureSetUp(self): |
|---|
| | 69 | # create test sandboxes in the mailboxes space |
|---|
| | 70 | self.wftool = wftool = getToolByName(self.portal, 'portal_workflow') |
|---|
| | 71 | self.ttool = ttool = getToolByName(self.portal, 'portal_types') |
|---|
| | 72 | mailboxes = self.portal.mailboxes |
|---|
| | 73 | |
|---|
| | 74 | wftool.invokeFactoryFor(mailboxes, 'Mailbox Group', self.MBG_ID) |
|---|
| | 75 | self.mbg = mailboxes[self.MBG_ID] |
|---|
| | 76 | |
|---|
| | 77 | wftool.invokeFactoryFor(self.mbg, 'Mailbox', self.MB_ID, |
|---|
| | 78 | **{'from': 'test_mailbox@cpscourrier.com'}) |
|---|
| | 79 | self.mb = self.mbg[self.MB_ID] |
|---|
| | 80 | |
|---|
| | 81 | wftool.invokeFactoryFor(self.mbg, 'Mailbox', self.MB2_ID, |
|---|
| | 82 | **{'from': 'test_mailbox2@cpscourrier.com'}) |
|---|
| | 83 | self.mb2 = self.mbg[self.MB2_ID] |
|---|
| | 84 | |
|---|
| | 85 | class CPSCourrierFunctionalLayerClass(CommonIntegrationFixture, |
|---|
| | 86 | CPSCourrierLayerClass): |
|---|
| | 87 | |
|---|
| | 88 | """Functional testing layer. |
|---|
| | 89 | |
|---|
| | 90 | The contract of testcases living in this layer is that they must |
|---|
| | 91 | create their mail documents and clean up their mess. """ |
|---|
| | 92 | |
|---|
| | 93 | #can't use __bases__ here, since method names change |
|---|
| | 94 | |
|---|
| | 95 | MBG_ID = 'ftest-mailbox-group' |
|---|
| | 96 | MB_ID = 'ftest-mailbox' |
|---|
| | 97 | MB2_ID = 'ftest-mailbox2' |
|---|
| | 98 | |
|---|
| | 99 | def setUp(self): |
|---|
| | 100 | CPSCourrierLayerClass.setUp(self) |
|---|
| | 101 | self.login() |
|---|
| | 102 | CommonIntegrationFixture.fixtureSetUp(self) |
|---|
| | 103 | # create some users |
|---|
| | 104 | mtool = getToolByName(self.portal, 'portal_membership') |
|---|
| | 105 | dtool = getToolByName(self.portal, 'portal_directories') |
|---|
| | 106 | mdir = dtool['members'] |
|---|
| | 107 | |
|---|
| | 108 | roles = {'reader': 'WorkspaceReader', |
|---|
| | 109 | 'member1': 'WorkspaceMember', |
|---|
| | 110 | 'member2': 'WorkspaceMember', |
|---|
| | 111 | 'member3': 'WorkspaceMember', |
|---|
| | 112 | 'manager': 'WorkspaceManager',} |
|---|
| | 113 | for prefix, role in roles.items(): |
|---|
| | 114 | for id, folder in ((self.MBG_ID, self.mbg,), |
|---|
| | 115 | (self.MB_ID, self.mb,), |
|---|
| | 116 | (self.MB2_ID, self.mb2,)): |
|---|
| | 117 | user_id = '%s_%s' % (prefix, id) |
|---|
| | 118 | mdir._createEntry({'id': user_id, 'roles':('Member',)}) |
|---|
| | 119 | mtool.setLocalRoles(folder, [user_id], role) |
|---|
| | 120 | transaction.commit() |
|---|
| | 121 | self.logout() |
|---|
| | 122 | |
|---|
| | 123 | def tearDown(self): |
|---|
| | 124 | pass |
|---|
| | 125 | |
|---|
| | 126 | |
|---|
| | 127 | CPSCourrierFunctionalLayer = CPSCourrierFunctionalLayerClass( |
|---|
| | 128 | __name__, |
|---|
| | 129 | 'CPSCourrierFunctionalLayer' |
|---|
| | 130 | ) |
|---|
| | 131 | |
|---|
| | 132 | |
|---|
| | 133 | class IntegrationTestCase(CommonIntegrationFixture, CPSTestCase): |
|---|
| | 134 | """For tests that need to avoid side-effects. |
|---|
| | 135 | |
|---|
| | 136 | provides the same kind of environment as CPSCourrierFunctionalLayer. |
|---|
| | 137 | doesn't share anything but profiles.""" |
|---|
| | 138 | |
|---|
| 73 | | # create test sandboxes in the mailboxes space |
|---|
| 74 | | wftool = getToolByName(self.portal, 'portal_workflow') |
|---|
| 75 | | ttool = getToolByName(self.portal, 'portal_types') |
|---|
| 76 | | mailboxes = self.portal.mailboxes |
|---|
| 77 | | |
|---|
| 78 | | wftool.invokeFactoryFor(mailboxes, 'Mailbox Group', self.MBG_ID) |
|---|
| 79 | | self.mbg = mailboxes[self.MBG_ID] |
|---|
| 80 | | |
|---|
| 81 | | wftool.invokeFactoryFor(self.mbg, 'Mailbox', self.MB_ID, |
|---|
| 82 | | **{'from': 'test_mailbox@cpscourrier.com'}) |
|---|
| 83 | | self.mb = self.mbg[self.MB_ID] |
|---|
| 84 | | |
|---|
| 85 | | wftool.invokeFactoryFor(self.mbg, 'Mailbox', self.MB2_ID, |
|---|
| 86 | | **{'from': 'test_mailbox2@cpscourrier.com'}) |
|---|
| 87 | | self.mb2 = self.mbg[self.MB2_ID] |
|---|
| 88 | | |
|---|
| | 147 | CommonIntegrationFixture.fixtureSetUp(self) |
|---|
| | 191 | class CourrierFunctionalTestCase(CPSTestCase): |
|---|
| | 192 | |
|---|
| | 193 | layer = CPSCourrierFunctionalLayer |
|---|
| | 194 | |
|---|
| | 195 | def afterSetUp(self): |
|---|
| | 196 | self.mbg = getattr(self.portal.mailboxes, self.layer.MBG_ID) |
|---|
| | 197 | self.mb = getattr(self.mbg, self.layer.MB_ID) |
|---|
| | 198 | self.wftool = getToolByName(self.portal, 'portal_workflow') |
|---|
| | 199 | self.ttool = getToolByName(self.portal, 'portal_types') |
|---|
| | 200 | |
|---|
| | 201 | def flogin(self, prefix, object): |
|---|
| | 202 | """ Login as prefixed user on object. |
|---|
| | 203 | |
|---|
| | 204 | Typical use case: self.flogin('member1', self.mb) logs in as |
|---|
| | 205 | one of the users that were created in layer to be WorkspaceMember in |
|---|
| | 206 | self.mb. |
|---|
| | 207 | """ |
|---|
| | 208 | self.login('%s_%s' % (prefix, object.getId())) |
|---|
| | 209 | |
|---|
| | 210 | |
|---|
| | 211 | def createIncoming(self, container=None, mail_id='incoming'): |
|---|
| | 212 | """Create incoming mail and set it as an attr on self. |
|---|
| | 213 | |
|---|
| | 214 | Default container is self.mb, |
|---|
| | 215 | """ |
|---|
| | 216 | self.createMail(container=container, |
|---|
| | 217 | mail_id=mail_id, |
|---|
| | 218 | portal_type="Incoming Mail") |
|---|
| | 219 | |
|---|
| | 220 | def createOutgoing(self, container=None, mail_id='outgoing'): |
|---|
| | 221 | """Create outgoing mail and set it as an attr on self. |
|---|
| | 222 | |
|---|
| | 223 | Default container is self.mb, |
|---|
| | 224 | """ |
|---|
| | 225 | self.createMail(container=container, |
|---|
| | 226 | mail_id=mail_id, |
|---|
| | 227 | portal_type="Outgoing Mail") |
|---|
| | 228 | |
|---|
| | 229 | def createMail(self, container=None, mail_id=None, portal_type=None): |
|---|
| | 230 | """Create mail and set it as an attr on self using given id |
|---|
| | 231 | |
|---|
| | 232 | Default container is self.mb |
|---|
| | 233 | """ |
|---|
| | 234 | if container is None: |
|---|
| | 235 | container = self.mb |
|---|
| | 236 | |
|---|
| | 237 | mail_fti = self.ttool[portal_type] |
|---|
| | 238 | dm = mail_fti.getDataModel(None) |
|---|
| | 239 | mail_id = self.wftool.invokeFactoryFor(self.mb, |
|---|
| | 240 | portal_type, |
|---|
| | 241 | mail_id, |
|---|
| | 242 | datamodel=dm) |
|---|
| | 243 | |
|---|
| | 244 | mail = container[mail_id] |
|---|
| | 245 | setattr(self, mail_id, mail) |
|---|
| | 246 | setattr(self, '%s_id' % mail_id, mail.getId()) |
|---|