Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Static Public Attributes
ATContentTypes.tests.test_constraintypes.TestConstrainTypes Class Reference
Inheritance diagram for ATContentTypes.tests.test_constraintypes.TestConstrainTypes:
Inheritance graph
[legend]
Collaboration diagram for ATContentTypes.tests.test_constraintypes.TestConstrainTypes:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def afterSetUp
def test_isMixedIn
def test_enabled
def test_disabled
def test_acquireFromHomogenousParent
def test_acquireFromHetereogenousParent

Public Attributes

 tt
 af
 at

Static Public Attributes

string folder_type = 'Folder'
string image_type = 'Image'
string document_type = 'Document'
string file_type = 'File'

Detailed Description

Definition at line 37 of file test_constraintypes.py.


Member Function Documentation

Definition at line 43 of file test_constraintypes.py.

00043 
00044     def afterSetUp(self):
00045         atcttestcase.ATCTSiteTestCase.afterSetUp(self)
00046         self.folder.invokeFactory(self.folder_type, id='af')
00047         self.tt = self.portal.portal_types
00048         # an ATCT folder
00049         self.af = self.folder.af
00050         # portal_types object for ATCT folder
00051         self.at = self.tt.getTypeInfo(self.af)

Definition at line 141 of file test_constraintypes.py.

00141 
00142     def test_acquireFromHetereogenousParent(self):
00143     
00144         # Let folder use a restricted set of types
00145         self.portal.portal_types.Folder.filter_content_types = 1
00146         self.portal.portal_types.Folder.allowed_content_types = \
00147             ('Document', 'Image', 'News Item', 'Topic', 'Folder')
00148         
00149         # Set up outer folder with restrictions enabled
00150         self.af.setConstrainTypesMode(constraintypes.ENABLED)
00151         self.af.setLocallyAllowedTypes(['Folder', 'Image'])
00152         self.af.setImmediatelyAddableTypes(['Folder', 'Image'])
00153   
00154         # Create inner type to acquire (default)
00155         self.af.invokeFactory('Folder', 'outer', title='outer')
00156         outer = self.af.outer
00157         
00158         outer.invokeFactory('Folder', 'inner', title='inner')
00159         inner = outer.inner 
00160         
00161         inner.setConstrainTypesMode(constraintypes.ACQUIRE)
00162         
00163         # Test persistence
00164         inner.setLocallyAllowedTypes(['Document', 'Event'])
00165         inner.setImmediatelyAddableTypes(['Document'])
00166         
00167         self.failUnlessEqual(inner.getRawLocallyAllowedTypes(), 
00168                                 ('Document', 'Event',))
00169         self.failUnlessEqual(inner.getRawImmediatelyAddableTypes(),
00170                                 ('Document',))
00171         
00172         # Fail - we didn't acquire this, really, since we can't acquire
00173         # from parent folder of different type
00174         self.assertRaises((Unauthorized, ValueError), inner.invokeFactory, 'Topic', 'a')
00175         self.failIf('News Item' in inner.getLocallyAllowedTypes())
00176         
00177         # Make sure immediately-addable are set to default
00178         self.failUnlessEqual(inner.getImmediatelyAddableTypes(), 
00179                                 inner.getLocallyAllowedTypes())
00180 
00181 
00182 tests.append(TestConstrainTypes)

Definition at line 99 of file test_constraintypes.py.

00099 
00100     def test_acquireFromHomogenousParent(self):
00101         # Set up outer folder with restrictions enabled
00102         self.af.setConstrainTypesMode(constraintypes.ENABLED)
00103         self.af.setLocallyAllowedTypes(['Folder', 'Image'])
00104         self.af.setImmediatelyAddableTypes(['Folder'])
00105         
00106         # Create inner type to acquire (default)
00107         self.af.invokeFactory('Folder', 'inner', title='inner')
00108         inner = self.af.inner
00109         
00110         inner.setConstrainTypesMode(constraintypes.ACQUIRE)
00111         
00112         # Test persistence
00113         inner.setLocallyAllowedTypes(['Document', 'Event'])
00114         inner.setImmediatelyAddableTypes(['Document'])
00115         
00116         self.failUnlessEqual(inner.getRawLocallyAllowedTypes(), 
00117                                 ('Document', 'Event',))
00118         self.failUnlessEqual(inner.getRawImmediatelyAddableTypes(),
00119                                 ('Document',))
00120         
00121         self.assertRaises(Unauthorized, inner.invokeFactory, 'Event', 'a')
00122         try:
00123             inner.invokeFactory('Image', 'whatever', title='life')
00124         except Unauthorized:
00125             self.fail()
00126         
00127         # Make sure immediately-addable are inherited
00128         self.failUnlessEqual(inner.getImmediatelyAddableTypes(), 
00129                                 self.af.getImmediatelyAddableTypes())
00130 
00131         
00132         # Create a new unprivileged user who can only access the inner folder
00133         self.portal.acl_users._doAddUser('restricted', 'secret', ['Member'], [])
00134         inner.manage_addLocalRoles('restricted', ('Manager',))
00135         # Login the new user
00136         user = self.portal.acl_users.getUserById('restricted')
00137         newSecurityManager(None, user)
00138         self.failUnlessEqual(inner.getLocallyAllowedTypes(),
00139                         ('Folder', 'Image'))
00140 
        

Here is the call graph for this function:

Definition at line 77 of file test_constraintypes.py.

00077 
00078     def test_disabled(self):
00079         self.af.setConstrainTypesMode(constraintypes.DISABLED)
00080         self.af.setLocallyAllowedTypes(['Folder', 'Image'])
00081         self.af.setImmediatelyAddableTypes(['Folder'])
00082         
00083         # We can still set and persist, even though it is disabled - must
00084         # remember!
00085         self.failUnlessEqual(self.af.getRawLocallyAllowedTypes(), 
00086                                 ('Folder', 'Image',))
00087         self.failUnlessEqual(self.af.getRawImmediatelyAddableTypes(), 
00088                                 ('Folder',))
00089         
00090         try:
00091             self.af.invokeFactory('Document', 'whatever', title='life')
00092             self.af.invokeFactory('Image', 'image', title="more life")
00093         except Unauthorized:
00094             self.fail()
00095             
00096         # Make sure immediately-addable are all types if we are disabled
00097         allowedIds = [ctype.getId() for ctype in self.af.allowedContentTypes()]
00098         self.failUnlessEqual(allowedIds, self.af.getImmediatelyAddableTypes())
        

Here is the call graph for this function:

Definition at line 61 of file test_constraintypes.py.

00061 
00062     def test_enabled(self):
00063         self.af.setConstrainTypesMode(constraintypes.ENABLED)
00064         self.af.setLocallyAllowedTypes(['Folder', 'Image'])
00065         self.af.setImmediatelyAddableTypes(['Folder'])
00066         
00067         self.failUnlessEqual(self.af.getLocallyAllowedTypes(), 
00068                                 ('Folder', 'Image',))
00069         self.failUnlessEqual(self.af.getImmediatelyAddableTypes(),
00070                                 ('Folder',))
00071         
00072         self.assertRaises(Unauthorized, self.af.invokeFactory, 'Document', 'a')
00073         try:
00074             self.af.invokeFactory('Image', 'image', title="death")
00075         except Unauthorized:
00076             self.fail()
        

Here is the call graph for this function:

Definition at line 52 of file test_constraintypes.py.

00052 
00053     def test_isMixedIn(self):
00054         self.failUnless(isinstance(self.af,
00055                                    constraintypes.ConstrainTypesMixin),
00056                         "ConstrainTypesMixin was not mixed in to ATFolder")
00057         self.failUnless(ZopeTwoISelectableConstrainTypes.isImplementedBy(self.af),
00058                         "ISelectableConstrainTypes not implemented by ATFolder instance")
00059         self.failUnless(ISelectableConstrainTypes.providedBy(self.af),
00060                         "ISelectableConstrainTypes not implemented by ATFolder instance")


Member Data Documentation

Definition at line 48 of file test_constraintypes.py.

Definition at line 50 of file test_constraintypes.py.

Definition at line 40 of file test_constraintypes.py.

Definition at line 41 of file test_constraintypes.py.

Definition at line 38 of file test_constraintypes.py.

Definition at line 39 of file test_constraintypes.py.

Definition at line 46 of file test_constraintypes.py.


The documentation for this class was generated from the following file: