source: cmfdeployment/branches/kenw-p4-wip/tests/testResource.py @ 2380

Last change on this file since 2380 was 2380, checked in by kenw, 8 years ago

Committing new branch intended for Plone 4 compatibility; mostly required imports of new zope packages

File size: 4.4 KB
Line 
1##################################################################
2#
3# (C) Copyright 2004 Kapil Thangavelu <k_vertigo@objectrealms.net>
4# All Rights Reserved
5#
6# This file is part of CMFDeployment.
7#
8# CMFDeployment is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 2 of the License, or
11# (at your option) any later version.
12#
13# CMFDeployment is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with CMFDeployment; if not, write to the Free Software
20# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21##################################################################
22"""
23Purpose: Unitests for Polixy Xml Import Export
24Author: kapil thangavelu <k_vertigo@objectrealms.net> @2002-2004
25License: GPL
26Created: 12/29/2002
27$Id: testResource.py 1660 2006-09-14 02:34:15Z hazmat $
28
29"""
30
31import os, sys, time
32if __name__ == '__main__':
33    execfile(os.path.join(sys.path[0], 'framework.py'))
34   
35from Testing import ZopeTestCase
36from Products.CMFPlone.tests.PloneTestCase import PloneTestCase
37
38ZopeTestCase.installProduct('CMFDeployment')
39ZopeTestCase.installProduct('MimetypesRegistry')
40ZopeTestCase.installProduct('PortalTransforms')
41ZopeTestCase.installProduct('Archetypes')
42
43import unittest
44from StringIO import StringIO
45from types import StringType, NoneType
46from Products.CMFCore.utils import getToolByName
47
48from Products.CMFDeployment.Descriptor import DescriptorFactory
49from Products.CMFDeployment import DeploymentProductHome
50from Products.CMFDeployment.ExpressionContainer import getDeployExprContext
51
52from sample import registerContent, SampleImageSchemaContent, SampleImageSchemaFolder
53
54class SiteResourceTests( PloneTestCase ):
55
56    def afterSetUp(self): 
57        installer = getToolByName(self.portal, 'portal_quickinstaller')
58        installer.installProduct('Archetypes')               
59        installer.installProduct('CMFDeployment')
60     
61        self.loginAsPortalOwner()
62
63        registerContent( self.portal )
64        self.portal._setObject('image_content', SampleImageSchemaContent('image_content'))
65        self.image_content = self.portal.image_content         
66        fh = open( os.path.join( DeploymentProductHome, 'www', 'identify.png'))
67        self.portal.image_content.setPortrait( fh )
68        fh.seek(0,0)
69        self.raw_image = fh.read()
70        fh.close()
71       
72        policy_file = os.path.join( DeploymentProductHome, 'examples', 'policies', 'plone21.xml')
73        fh = open( policy_file )
74        deployment_tool = getToolByName(self.portal, 'portal_deployment')
75        deployment_tool.addPolicy( policy_id="test21", policy_xml=fh )
76        fh.close()
77       
78        self.policy = policy = deployment_tool.getPolicy('test21')
79        self.resources = policy.getSiteResources()
80       
81##         self.rules = policy.getContentMastering().rules
82##         self.rules.manage_addProduct['CMFDeployment'].addATContentRule(
83##             id = "at_image_content",
84##             extension_expression="string:${object/getId}.html",           
85##             condition="python: object.portal_type == 'Sample Image Content'",
86##             view_method="string:base_view"
87##             )
88       
89    def beforeTearDown(self):
90        self.resources = None
91        self.image_content = None
92        self.raw_image = None
93        self.policy = None
94
95    def testAuthorIndexRule(self):
96        self.resources.manage_addProduct['CMFDeployment'].addAuthorIndexesRule(
97            id = "authors_index",
98            source_path = "/author/",
99            view_path = "/author/",
100            deployment_path = "/authors/"
101            )
102
103        self.portal._setObject( "image_folder", SampleImageSchemaFolder("image_folder") )
104        image_folder = self.portal._getOb( "image_folder")
105        image_folder.invokeFactory('Document', 'index_html')
106
107        descriptors = list(self.resources.authors_index.getDescriptors())
108        self.assertEqual( len(descriptors), 1 )
109
110def test_suite():
111    suite = unittest.TestSuite()
112    suite.addTest(unittest.makeSuite(SiteResourceTests))
113    return suite
114
115if __name__ == '__main__':
116    framework() 
Note: See TracBrowser for help on using the repository browser.