source: trunk/tests/testGroups.py @ 439

Revision 439, 8.0 KB checked in by tarmo, 13 years ago (diff)

Fixed a few unit tests.

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 testGroupEdit(self):
41        self.loginAsPortalOwner() #GRUF's settings are a bit restrictive
42        self.grouptool=getToolByName(self.portal, "portal_groups")
43        self.group1 = self.newGroup('testgroup1')
44        self.workspace1 = self.getGroupBlog('testgroup1')
45        self.TOKENS1 = 'unit testing is foobar'
46        self.TOKENS2 = ['word','another']
47        self.workspace1.setProperties(description=self.TOKENS1, tags=self.TOKENS2)
48        result=self.publish(self.portal.absolute_url_path()+'/community/testgroup1/edit', basic=auth)
49        #result=self.publish(self.grouptool.getGroupareaURL('testgroup1')+'/group_edit', basic=auth)
50        # why that^^ works but that^ doesn't?
51        for prop in ['title','description','tags']:
52            self.failUnless(re.search(prop, result.getBody()), "edit form broken, missing property:"+prop+result.getBody())
53
54    # joining, leaving and such are not tested, because they're just calls to GroupUserFolder's methods in form handler scripts.
55   
56    def testGroupList(self):
57        self.loginAsPortalOwner() #GRUF's settings are a bit restrictive
58        self.grouptool=getToolByName(self.portal, "portal_groups")
59        self.group1 = self.newGroup('testgroup1')
60        self.TOKENS1 = 'titlefoobar'
61        self.workspace1 = self.getGroupBlog('testgroup1') # In LeMill modifying groups is always done by modifying groups workspace.
62        self.workspace1.setProperties(title=self.TOKENS1) # This should affect the group too.
63        result=self.publish(self.portal.absolute_url_path()+'/community/group_name', basic=auth)
64        self.failUnless(re.search(self.TOKENS1, result.getBody()), "can't find created group when browsing group names"+result.getBody())
65       
66    def testBlogPost(self):
67        self.loginAsPortalOwner()
68        TITLE='TheseThingsTakeTime'
69        VALUE='Most inept that ever stepped'
70        self.grouptool=getToolByName(self.portal, "portal_groups")
71        self.group = self.newGroup('testgroup')
72        self.workspace = self.getGroupBlog('testgroup')
73        ob = self.construct('BlogPost','TestPost',self.portal.community.testgroup)
74        ob.processForm(values={'title':TITLE,'bodyText':VALUE})
75        ob.at_post_edit_script()           
76        result=self.publish(self.portal.absolute_url_path()+'/community/testgroup', basic=auth)
77        self.failUnless(re.search(TITLE, result.getBody()), "can't find post title from group's blog"+result.getBody())
78        self.failUnless(re.search(VALUE, result.getBody()), "can't find post body from group's blog"+result.getBody())
79        result=self.publish(self.portal.absolute_url_path()+'/community/testgroup/thesethingstaketime', basic=auth)
80        self.failUnless(re.search('textarea', result.getBody()) and re.search('name="body_text"', result.getBody()), "comment box not visible for post"+result.getBody())
81       
82
83
84    def testBlogPostsInCommunityFrontPage(self):
85        self.addUser('foobar','foobar', ('Member',))
86        self.login('foobar')
87        self.grouptool=getToolByName(self.portal, "portal_groups")
88        self.group = self.newGroup('testgroup')
89        self.workspace = self.getGroupBlog('testgroup')
90
91        cases = [('test1','First post', 'Most inept that ever stepped', 'blog post'),
92            ('test2','Second post', 'TheseThingsTakeTime', 'collaboration proposal')]
93
94        for (ID, TITLE, BODY, CATEGORY) in cases:
95            ob = self.construct('BlogPost',ID,self.portal.community.testgroup)
96            ob.processForm(values={'title':TITLE,'bodyText':BODY, 'category':CATEGORY})
97            ob.at_post_edit_script()           
98        result=self.publish(self.portal.absolute_url_path()+'/community', basic='foobar:foobar')
99        TITLE=cases[0][1]
100        BODY=cases[0][2]
101        self.failIf(re.search(TITLE, result.getBody()), "Found post titled %s from community front page when member is not member of group." % TITLE)
102        self.failIf(re.search(BODY, result.getBody()), "Found post body %s from community front page when member is not member of group." % BODY)
103        TITLE=cases[1][1]
104        BODY=cases[1][2]       
105        self.failUnless(re.search(TITLE, result.getBody()), "can't find invitation %s from community front page: %s" % (TITLE,result.getBody()))
106        self.failUnless(re.search(BODY, result.getBody()), "can't find invitation body %s from community front page: %s" % (BODY, result.getBody()))
107
108        self.workspace.join_group()
109        result=self.publish(self.portal.absolute_url_path()+'/community', basic='foobar:foobar')
110
111        for (ID, TITLE, BODY, CATEGORY) in cases:
112            self.failUnless(re.search(TITLE, result.getBody()), "can't find post %s from community front page: %s" % (TITLE,result.getBody()))
113            self.failUnless(re.search(BODY, result.getBody()), "can't find post body %s from community front page: %s" % (BODY, result.getBody()))
114
115
116    def testGroupLinks(self):
117        # Anonymous links
118        self.grouptool=getToolByName(self.portal, "portal_groups")
119        self.group = self.newGroup('testgroup')
120        self.workspace = self.getGroupBlog('testgroup')
121        result=self.publish(self.portal.absolute_url_path()+'/community/testgroup')
122        self.failIf(re.search('community/testgroup/join_group', result.getBody()), "When viewing group page anonymously 'join this group' tries to add anonymous user to group when it should take to a login page.")
123        self.failUnless(re.search('community/testgroup/join_form', result.getBody()), "When viewing group page anonymously 'join this group' doesn't take to a login page.")       
124       
125        self.loginAsPortalOwner()
126        self.workspace.join_group()
127        result=self.publish(self.portal.absolute_url_path()+'/community/testgroup')       
128        self.failIf(re.search('Group links', result.getBody()), "Group links portlet is visible when there should be no group links.")
129        self.workspace.processForm(values={'links':"""
130        [http://www.yle.fi Yleisradio]
131        humbug
132        [http://www.helsinki.fi]"""})
133        self.workspace.at_post_edit_script()                   
134        result=self.publish(self.portal.absolute_url_path()+'/community/testgroup')       
135        self.failUnless(re.search('Group links', result.getBody()), "Group links portlet isn't visible when there should be links: %s" % result.getBody())
136        self.failUnless(re.search('href="http://www.yle.fi"', result.getBody()), 'Group link not correct: there should be href="http://www.yle.fi" in %s' % result.getBody())       
137       
138
139
140
141def test_suite():
142    from unittest import TestSuite, makeSuite
143    suite = TestSuite()
144    suite.addTest(makeSuite(TestGroups))
145    return suite
146
147if __name__ == '__main__':
148    framework()
Note: See TracBrowser for help on using the repository browser.