[1] | 1 | from Testing import ZopeTestCase |
---|
| 2 | from Products.Archetypes.tests import ArchetypesTestCase |
---|
| 3 | from Products.CMFCore.utils import getToolByName |
---|
| 4 | from AccessControl.SecurityManagement import newSecurityManager |
---|
| 5 | from AccessControl.SecurityManagement import noSecurityManager |
---|
| 6 | from Products.PloneTestCase.setup import setupPloneSite |
---|
| 7 | |
---|
| 8 | ZopeTestCase.installProduct('ShortMessage') |
---|
| 9 | ZopeTestCase.installProduct('CMFMember') |
---|
| 10 | ZopeTestCase.installProduct('PloneSMSCommunicator') |
---|
| 11 | from Products.ShortMessage import ShortMessage |
---|
| 12 | import time |
---|
| 13 | |
---|
| 14 | tests=[] |
---|
| 15 | PRODUCTS=('ShortMessage', 'CMFMember', 'PloneSMSCommunicator') |
---|
| 16 | |
---|
| 17 | class TestShortMessage(ArchetypesTestCase.ArcheSiteTestCase): |
---|
| 18 | |
---|
| 19 | def createManager(self, portal): |
---|
| 20 | acl_users = portal.acl_users |
---|
| 21 | return acl_users._doAddUser('PortalManager', '', ['Manager'], (), (), ) |
---|
| 22 | |
---|
| 23 | def installProducts(self, portal): |
---|
| 24 | #create manager user |
---|
| 25 | self.createManager(portal) |
---|
| 26 | user = portal.acl_users.getUserById('PortalManager') |
---|
| 27 | #login as manager |
---|
| 28 | newSecurityManager(None, user) |
---|
| 29 | #install products |
---|
| 30 | qi = getToolByName(portal, 'portal_quickinstaller') |
---|
| 31 | for product in PRODUCTS: |
---|
| 32 | qi.installProduct(product) |
---|
| 33 | #log out |
---|
| 34 | noSecurityManager() |
---|
| 35 | |
---|
| 36 | def afterSetUp(self): |
---|
| 37 | |
---|
| 38 | #get Portal and acl_users |
---|
| 39 | portal = self.portal |
---|
| 40 | acl_users = portal.acl_users |
---|
| 41 | self.installProducts(portal) |
---|
| 42 | #create ShortMessage object |
---|
| 43 | us = acl_users.getUserById('PortalManager') |
---|
| 44 | newSecurityManager(None, us) |
---|
| 45 | self.folder.invokeFactory(type_name='ShortMessage', id='sms') |
---|
| 46 | noSecurityManager() |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | def test_sender(self): |
---|
| 50 | self.folder.sms.setSender('+380979312198') |
---|
| 51 | self.assertEqual(self.folder.sms.getSender(), '+380979312198') |
---|
| 52 | |
---|
| 53 | def test_recipient(self): |
---|
| 54 | self.folder.sms.setRecipient('g1') |
---|
| 55 | self.assertEqual(self.folder.sms.getRecipient(), 'g1') |
---|
| 56 | |
---|
| 57 | def test_body(self): |
---|
| 58 | self.folder.sms.setBody('hello Taras this is text message') |
---|
| 59 | self.assertEqual(self.folder.sms.getBody(), 'hello Taras this is text message') |
---|
| 60 | |
---|
| 61 | tests.append(TestShortMessage) |
---|
| 62 | |
---|
| 63 | def test_suite(): |
---|
| 64 | from unittest import TestSuite, makeSuite |
---|
| 65 | suite = TestSuite() |
---|
| 66 | suite.addTest(makeSuite(TestShortMessage)) |
---|
| 67 | return suite |
---|
| 68 | |
---|
| 69 | if __name__ == '__main__': |
---|
| 70 | framework() |
---|