source: trunk/tests/testGroups.py @ 1930

Revision 1930, 10.8 KB checked in by jukka, 12 years ago (diff)

Fixed tests and other stuff, fixed #1376, closed #1420.

Line 
1# Copyright 2006 by the LeMill Team (see AUTHORS)
2#
3# This file is part of LeMill.
4#
5# LeMill is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
9#
10# LeMill is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with LeMill; if not, write to the Free Software
17# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
19import os, sys, re
20if __name__ == '__main__':
21    execfile(os.path.join(sys.path[0], 'framework.py'))
22
23from Testing import ZopeTestCase
24from LeMillTestCase import LeMillTestCase
25from Testing.ZopeTestCase.functional import Functional
26from Products.CMFCore.utils import getToolByName
27
28from Products.LeMill.config import *
29from Products.PloneTestCase.setup import portal_owner, default_password
30
31
32auth=':'.join((portal_owner, default_password))
33
34
35class TestGroups(LeMillTestCase,Functional):
36    """
37    Test suite for verifying group functionality. Mostly copied from TestUsers. As there is no our own Group tool or object, there isn't much to test.
38    """
39
40    def testGroupView(self):
41        self.loginAsPortalOwner()
42        group1 = self.newGroup('testgroup1')
43        result=self.publish(group1.absolute_url_path()+'/view', basic=auth).getBody()
44        self.failUnless(result.find('portlet-groupblog-actions') != -1, "Portlet not shown")
45
46    def testGroupEdit(self):
47        self.loginAsPortalOwner() #GRUF's settings are a bit restrictive
48        self.group1 = self.newGroup('testgroup1')
49        self.TOKENS1 = 'unit testing is foobar'
50        self.TOKENS2 = ['word','another']
51        self.group1.edit(description=self.TOKENS1, tags=self.TOKENS2)
52        result=self.publish(self.portal.absolute_url_path()+'/community/testgroup1/base_edit', basic=auth)
53        for prop in ['title','description','tags']:
54            self.failUnless(result.getBody().find(prop) != -1, "edit form broken, missing property:"+prop+result.getBody())
55
56    # joining, leaving and such are not tested, because they're just calls to GroupUserFolder's methods in form handler scripts.
57
58    def testJoiningAndLeavingGroup(self):
59        self.addUser('commoner','passwd1')
60        self.group1=self.newGroup('testgroup1')
61        self.login('commoner')
62        auth='commoner:passwd1'
63        self.group1.join_group()
64        result=self.publish(self.portal.absolute_url_path()+'/community/testgroup1', basic=auth)
65        self.failUnless('commoner' in self.group1.getGroupMembers(), "Joined member not visible in group members: %s" % self.group1.getGroupMembers())
66        self.failUnless(result.getBody().find('Leave group') != -1, "If we're joined there should be leave group on page somewhere: "+result.getBody())
67        self.group1.leave_group()
68        result=self.publish(self.portal.absolute_url_path()+'/community/testgroup1', basic=auth)
69        self.failIf('commoner' in self.group1.getGroupMembers(), "Joined member still visible in group members, after leaving.")
70        self.failIf(result.getBody().find('Leave group') != -1, "We should have left already: "+result.getBody())
71
72   
73    def testGroupList(self):
74        self.group1 = self.newGroup('testgroup1')
75        self.TOKENS1 = 'titlefoobar'
76        self.group1.edit(title=self.TOKENS1)
77        result=self.publish(self.portal.absolute_url_path()+'/community/groups', basic=auth)
78        self.failUnless(result.getBody().find(self.TOKENS1) != -1, "can't find created group when browsing group names"+result.getBody())
79
80    def testInviteGroups(self):
81        self.loginAsPortalOwner()
82        self.portal.portal_membership.createMemberArea('portal_owner')
83        self.addUser('invited','passwd1')
84        self.addUser('inviter','passwd2')
85        self.login('inviter')
86        iauth='inviter:passwd2'
87        self.group1 = self.newGroup('testgroup1')
88        self.group2 = self.newGroup('testgroup2')
89        self.group1.join_group()
90        self.group2.join_group()
91        # 1) there shouldn't be invite -link visible in your own profile page
92        result=self.publish(self.portal.community.inviter.absolute_url_path(), basic=iauth)
93        self.failIf(result.getBody().find('Invite to group') != -1, "Invite to group - link visible for your own page"+result.getBody())
94        # 2) there should be invite link in other people's profiles
95        result=self.publish(self.portal.community.invited.absolute_url_path(), basic=iauth)
96        self.failUnless(result.getBody().find('Invite to group') != -1, "Invite to group - link not visible in other people's pages"+result.getBody())
97        # 3) invite form should show your groups
98        result=self.publish(self.portal.community.invited.absolute_url_path()+'/group_invite', basic=iauth)
99        self.failUnless(result.getBody().find('testgroup1') != -1, "group1 not visible in group invite form"+result.getBody())
100        self.failUnless(result.getBody().find('testgroup2') != -1, "group2 not visible in group invite form"+result.getBody())
101        self.failIf(result.getBody().find('already a member') != -1, "marked as member in group invite form when shouldn't be"+result.getBody())
102        # 4) if our invitee is already a member, there should be a notion of that
103        self.login('invited')
104        self.group1.join_group()
105        result=self.publish(self.portal.community.invited.absolute_url_path()+'/group_invite', basic=iauth) # this is still ran as portal_owner
106        self.failUnless(result.getBody().find('already a member') != -1, "member is already in group, but it doesn't get noticed"+result.getBody())             
107       
108       
109    def testBlogPost(self):
110        self.loginAsPortalOwner()
111        TITLE='TheseThingsTakeTime'
112        VALUE='Most inept that ever stepped'
113        self.group = self.newGroup('testgroup')
114        ob = self.construct('BlogPost','TestPost',self.portal.community.testgroup)
115        ob.processForm(values={'title':TITLE,'bodyText':VALUE})
116        ob.at_post_edit_script()
117        result=self.publish(self.portal.absolute_url_path()+'/community/testgroup', basic=auth)
118        self.failUnless(result.getBody().find(TITLE) != -1, "can't find post title from group's blog"+result.getBody())
119        self.failUnless(result.getBody().find(TITLE) != -1, "can't find post title from group's blog"+result.getBody())
120        result=self.publish(self.portal.absolute_url_path()+'/community/testgroup/thesethingstaketime', basic=auth)
121        self.failUnless(result.getBody().find(VALUE) != -1, "can't find post body from post"+result.getBody())
122        self.failUnless(result.getBody().find('textarea') != -1 and result.getBody().find('name="body_text"') != -1, "comment box not visible for post"+result.getBody())
123
124        ob = self.construct('BlogPost','TestPost',self.portal.community.testgroup)
125        ob.processForm(values={'title':TITLE,'bodyText':'huigrehr\ngyuiwgre\n\nhuigrwegr\nhttp://index.hu/huigrehgr/hrehuwigw/ehreuqihgrehr/ehjreugihrtre/htjreuihreuige/gre/gre/gr'})
126        self.assertEqual(self.cookText(ob.getBodyText()), 'huigrehr<br />gyuiwgre</p><p>huigrwegr<br /><a href="http://index.hu/huigrehgr/hrehuwigw/ehreuqihgrehr/ehjreugihrtre/htjreuihreuige/gre/gre/gr">http://index.hu/.../gr</a>')
127
128    def testBlogPostsInCommunityFrontPage(self):
129        self.addUser('foobar','foobar', ('Member',))
130        self.login('foobar')
131        self.group = self.newGroup('testgroup')
132
133        cases = [('test1','First post', 'Most inept that ever stepped'),
134            ('test2','Second post', 'TheseThingsTakeTime')]
135
136        for (ID, TITLE, BODY) in cases:
137            ob = self.construct('BlogPost',ID,self.portal.community.testgroup)
138            ob.processForm(values={'title':TITLE,'bodyText':BODY})
139            ob.at_post_edit_script()
140        result=self.publish(self.portal.absolute_url_path()+'/community', basic='foobar:foobar')
141        TITLE=cases[0][1]
142        GTITLE=self.group.title_or_id()
143        self.failIf(result.getBody().find(TITLE) != -1, "Found post titled %s from community front page when member is not member of group." % TITLE)
144        self.failIf(result.getBody().find(GTITLE) != -1, "Found group title %s from community front page when member is not member of group." % GTITLE)
145
146        self.group.join_group()
147        result=self.publish(self.portal.absolute_url_path()+'/community', basic='foobar:foobar')
148
149        for (ID, TITLE, BODY) in cases:
150            self.failUnless(result.getBody().find(TITLE) != -1, "can't find post %s from community front page: %s" % (TITLE,result.getBody()))
151            self.failUnless(result.getBody().find(GTITLE) != -1, "can't find group title %s from community front page: %s" % (GTITLE, result.getBody()))
152
153
154
155    def testSharingWithAGroup(self):
156        """ test sharing a material with a group """
157        self.loginAsPortalOwner()
158        self.portal._delObject('error_log')
159        ob = self.construct('PresentationMaterial', 'testMaterial', self.portal.content)
160        self.group = self.newGroup('testgroup')
161        self.group.join_group()       
162        ob.edit(groupEditing=None)
163        self.failUnless(ob.getGroupEditing()==None, 'Material shouldn\'t be shared with a group')
164        ob.setGroupEditing(self.group)
165
166        self.failUnless(ob.getRawGroupEditing()==self.group.UID(), 'Material isn\'t shared with a group')
167
168
169        self.addUser('foobar','foobar', ('Member',))
170        self.login('foobar')
171        bauth = ':'.join(('foobar', 'foobar'))
172        result = self.publish(ob.absolute_url_path()+'/edit', basic=bauth).getBody()
173        self.failIf(result.find('Body text') != -1, 'Not yet joined a group but can edit material already... somethings wrong')
174        joining = self.publish(self.portal.absolute_url_path()+'/community/testgroup/join_group', basic='foobar:foobar').getBody()
175        result = self.publish(ob.absolute_url_path()+'/edit', basic=bauth).getBody()
176        self.failUnless(result.find('Slides and captions') != -1, 'Joined a group but cannot edit material.')
177       
178   
179    def testMemberLinks(self):
180        # Anonymous links
181        self.group = self.newGroup('testgroup')
182        self.addUser('foobar','foobar', ('Member',))
183        self.login('foobar')
184        self.group.join_group()
185        result=self.publish(self.portal.absolute_url_path()+'/community/testgroup')
186        self.failUnless(result.getBody().find('community/foobar') != -1, "When viewing group page anonymously, members are not visible")
187        self.failIf(result.getBody().find('logout') != -1, "Oops, foobar is still logged in.")
188
189
190
191def test_suite():
192    from unittest import TestSuite, makeSuite
193    suite = TestSuite()
194    suite.addTest(makeSuite(TestGroups))
195    return suite
196
197if __name__ == '__main__':
198    framework()
Note: See TracBrowser for help on using the repository browser.