source: trunk/tests/testGroups.py @ 423

Revision 423, 8.3 KB checked in by jukka, 13 years ago (diff)

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