source: trunk/tests/LeMillTestCase.py @ 1930

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

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

  • Property svn:eol-style set to native
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
19#
20# LeMillTestCase
21#
22
23# XXX: Suppress DeprecationWarnings
24import warnings
25from urllib import urlencode
26warnings.simplefilter('ignore', DeprecationWarning, append=1)
27
28from Products.CMFCore.utils import getToolByName
29from Products.PloneTestCase import PloneTestCase
30from Products.PloneTestCase.setup import portal_owner
31from Products.LeMill.MemberFolder import MemberFolder
32from Products.LeMill.config import PLONE25
33
34PloneTestCase.installProduct('LeMill')
35PloneTestCase.installProduct('ExtendedPathIndex')
36PloneTestCase.installProduct('PloneLanguageTool')
37
38if PLONE25:
39    PloneTestCase.setupPloneSite(extension_profiles=['Archetypes:Archetypes','LeMill:LeMill'])
40else:
41    PloneTestCase.setupPloneSite(policy='LeMill Site')
42
43class LeMillTestCase(PloneTestCase.FunctionalTestCase):
44    '''TestCase for LeMill testing'''
45
46    def construct(self, portal_type, id, folder=None):
47        if not folder:
48            folder=self.portal.content
49        if not isinstance(folder.getMember(),MemberFolder):
50            #print "POSSIBLE PROBLEM: Not logged in with a proper LeMill user (%s)!" % folder.whoami()
51            UNAME = "temporary"
52            #print 'Creating user "%s" and logging in now.' % UNAME
53            self.addUser(UNAME,UNAME)
54            self.login(UNAME)
55        folder.invokeFactory(type_name=portal_type,id=id)
56        self.failUnless(id in folder.objectIds())
57        return getattr(folder, id)
58
59    def addUser(self,id,passwd,roles=('Member',),domains=(),groups=()):
60        mtool = getToolByName(self.portal,'portal_membership')
61        lusertool = getToolByName(self.portal, 'lemill_usertool')
62        if mtool.getAuthenticatedMember().getId() != portal_owner:
63            #print "POSSIBLE PROBLEM: Non-manager %s creating account %s." % (mtool.getAuthenticatedMember().getId(),id)
64            #print "Logging in as portal owner."
65            self.loginAsPortalOwner()
66        rtool = getToolByName(self.portal,'portal_registration')
67        if rtool.isMemberIdAllowed(id):
68            member = rtool.addMember(id,passwd,roles,domains)
69            self.portal.acl_users.userSetGroups(id,groups)
70            self.login(id)
71            self.portal.portal_membership.createMemberArea(id)
72            mfolder = lusertool.getLeMillMemberFolder(id)
73            mfolder.getCollectionsFolder()
74            self.loginAsPortalOwner()
75
76    def newGroup(self, id):
77        community=self.portal.community
78        group=self.construct('GroupBlog', id, folder=community)
79        group.edit(title=id)
80        return group
81
82    def editObject(self,ob,params,basic):
83        """Edit a given object with the supplied parameters"""
84        params['form.submitted']='1'
85        path = "%s?%s" % ('/'.join((ob.absolute_url_path(),'base_edit')),urlencode(params))
86        return self.publishFollowRedirect(path,basic=basic)
87       
88    def publishFollowRedirect(self,path,basic):
89        """Execute http request to "path" with credentials given.
90        If results is a redirect, follow it. Finally, if you get anything
91        except status 200, report as a failure."""
92        result = self.publish(path,basic=basic)
93        status = result.getStatus()
94        if status == 302:
95            path = result.getBody()
96            path = '/'.join(path.split('/')[3:])
97            #print "REDIRECTED: %s" % path
98            result = self.publish(path,basic=basic)
99            status = result.getStatus()
100        self.failUnless(status==200,"Erroneous status %s from http request: %s" % (status,result.getBody()))
101        return result
102
103    def cookText(self,text):
104        """ This should mirror cookText-script skins/lemill/cookText.py """
105        lt=getToolByName(self.portal, 'lemill_tool')
106        if type(text)==list or type(text)==tuple:
107            return [lt.shorten_link_names(lt.htmlify(x)) for x in text]
108        return lt.shorten_link_names(lt.htmlify(text))
109
Note: See TracBrowser for help on using the repository browser.