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