Back to index

plone3  3.1.7
Public Member Functions | Public Attributes
kupu.plone.tests.test_plonedrawer.TestPloneDrawer Class Reference

List of all members.

Public Member Functions

def afterSetUp
def loginPortalOwner
def create
def setup_content
def test_FolderContents1
def test_FolderWithKeywords
def test_NoBrowseWithKeywords
def test_ResourceType

Public Attributes

 kupu

Detailed Description

Test the implementation of the PloneDrawer class

Definition at line 54 of file test_plonedrawer.py.


Member Function Documentation

Definition at line 57 of file test_plonedrawer.py.

00057 
00058     def afterSetUp(self):
00059         portal = self.portal
00060         self.setRoles(['Manager',])
00061         self.kupu = portal.kupu_library_tool
00062         typestool = self.portal.portal_types
00063         if not hasattr(typestool, 'ATDocument'):
00064             # Use the type names without the AT prefix
00065             for k in TypeMapping:
00066                 TypeMapping[k] = k

Here is the call graph for this function:

def kupu.plone.tests.test_plonedrawer.TestPloneDrawer.create (   self,
  id,
  metatype = 'ATDocument',
  folder = None,
  kwds 
)
Create an object in the cms portal

Definition at line 73 of file test_plonedrawer.py.

00073 
00074     def create(self, id, metatype='ATDocument', folder=None, **kwds):
00075         '''Create an object in the cms portal'''
00076         if folder is None:
00077             folder = self.portal
00078 
00079         folder.invokeFactory(MapType(metatype), id)
00080         obj = getattr(folder, id)
00081 
00082         if metatype=='Folder' and constraintypes:
00083             obj.setConstrainTypesMode(constraintypes.DISABLED)
00084 
00085         if metatype=='Document':
00086             obj.setTitle('Simple document')
00087             obj.setText('Sample document text')
00088             for k, v in kwds.items():
00089                 field = obj.getField(k)
00090                 mutator = field.getMutator(obj)(v)
00091 
00092             obj.reindexObject()
00093         return obj

Here is the call graph for this function:

Here is the caller graph for this function:

Use if you need to manipulate the portal itself.

Definition at line 67 of file test_plonedrawer.py.

00067 
00068     def loginPortalOwner(self):
00069         '''Use if you need to manipulate the portal itself.'''
00070         uf = self.app.acl_users
00071         user = uf.getUserById(portal_owner).__of__(uf)
00072         newSecurityManager(None, user)

Here is the caller graph for this function:

Definition at line 94 of file test_plonedrawer.py.

00094 
00095     def setup_content(self):
00096         self.setRoles(['Manager',])
00097         self.loginPortalOwner()
00098         f = self.create('folder', 'Folder')
00099 
00100         for id in ('alpha', 'beta'):
00101             self.create(id, 'Document', f, subject=['aspidistra'])
00102         self.create('gamma', 'Document', f)
00103 
00104         sub1 = self.create('sub1', 'Folder', f)
00105         sub1.setSubject(['aspidistra'])
00106         sub1.reindexObject()
00107         sub2 = self.create('sub2', 'Folder', f)
00108         self.create('delta', 'Folder', sub2)
00109 
00110         portal = self.portal
00111         tool = self.portal.kupu_library_tool
00112         types = tool.zmi_get_resourcetypes()
00113         #tool.deleteResource([ t.name for t in types])
00114         for k,v in RESOURCES.items():
00115             tool.addResourceType(k, [MapType(t) for t in v])

Here is the caller graph for this function:

Definition at line 116 of file test_plonedrawer.py.

00116 
00117     def test_FolderContents1(self):
00118         def assertKey(item, key, expected):
00119             actual =  item.get(key, None)
00120             self.assertEquals(expected, actual,
00121                 "Item %s.%s expected %s got %s" % (UIDS[item['id']], key, expected, actual))
00122 
00123         self.setup_content()
00124         portal = self.portal
00125         folder = portal['folder']
00126         UIDS = {}
00127         for id in folder.objectIds():
00128             UIDS[folder[id].UID()] = id
00129 
00130         # Allows browse: docs + folders
00131         items = self.kupu.getFolderItems(folder, resource_type='TestContent.multiRef')
00132         ids = [UIDS[t['id']] for t in items]
00133         self.assertEquals(['alpha', 'beta', 'gamma', 'sub1', 'sub2'], ids)
00134 
00135         # No browse: docs only.
00136         items = self.kupu.getFolderItems(folder, resource_type='TestContent.multiRef2')
00137         ids = [UIDS[t['id']] for t in items]
00138         self.assertEquals(['alpha', 'beta', 'gamma'], ids)

Here is the call graph for this function:

Definition at line 139 of file test_plonedrawer.py.

00139 
00140     def test_FolderWithKeywords(self):
00141         def assertKey(item, key, expected):
00142             actual =  item.get(key, None)
00143             self.assertEquals(expected, actual,
00144                 "Item %s.%s expected %s got %s" % (UIDS[item['id']], key, expected, actual))
00145 
00146         self.setup_content()
00147         portal = self.portal
00148         folder = portal['folder']
00149         UIDS = {}
00150         for id in folder.objectIds():
00151             UIDS[folder[id].UID()] = id
00152 
00153         # Query restriction: keyword match only, but should include
00154         # both folders.
00155         items = self.kupu.getFolderItems(folder, resource_type='TestContent.multiRef3')
00156         ids = [UIDS[t['id']] for t in items]
00157         self.assertEquals(['alpha', 'beta', 'sub1', 'sub2'], ids)
00158         # Now check that only the first of the two folders is linkable...
00159         for t in items[:-1]:
00160             assertKey(t, 'linkable', True)
00161         assertKey(items[-1], 'linkable', None)
00162 
00163         for t in items[:-2]:
00164             assertKey(t, 'anchor', True)
00165         assertKey(items[-2], 'anchor', False)
00166         assertKey(items[-1], 'anchor', False)
00167 
00168         # Both folders should contain a src element.
00169         self.assert_(items[-1]['src'])
00170         self.assert_(items[-2]['src'])

Here is the call graph for this function:

Definition at line 171 of file test_plonedrawer.py.

00171 
00172     def test_NoBrowseWithKeywords(self):
00173         def assertKey(item, key, expected):
00174             actual =  item.get(key, None)
00175             self.assertEquals(expected, actual,
00176                 "Item %s.%s expected %s got %s" % (UIDS[item['id']], key, expected, actual))
00177 
00178         self.setup_content()
00179         portal = self.portal
00180         folder = portal['folder']
00181         UIDS = {}
00182         for id in folder.objectIds():
00183             UIDS[folder[id].UID()] = id
00184 
00185         # Query restriction: keyword match only, and since we don't
00186         # allow browse only 1 folder (non-browsable)
00187         items = self.kupu.getFolderItems(folder, resource_type='TestContent.multiRef4')
00188         ids = [UIDS[t['id']] for t in items]
00189         self.assertEquals(['alpha', 'beta', 'sub1'], ids)
00190         # Now check that all are linkable and non browsable.
00191         for t in items[:-1]:
00192             assertKey(t, 'linkable', True)
00193             assertKey(t, 'src', None)

Here is the call graph for this function:

Definition at line 194 of file test_plonedrawer.py.

00194 
00195     def test_ResourceType(self):
00196         # Some tests that the ResourceType class is roughly working.
00197         kupu = self.kupu
00198         r = kupu.getResourceType('TestContent.multiRef2')
00199         self.assertEquals(r.allow_browse, False)
00200 
00201         r = kupu.getResourceType('linkable')
00202         self.assertEquals(r.allow_browse, True)
00203         


Member Data Documentation

Definition at line 60 of file test_plonedrawer.py.


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