Back to index

plone3  3.1.7
site_creation_view.py
Go to the documentation of this file.
00001 import logging
00002 
00003 # XXX Make this package to run with the earlier version
00004 # of kss.demo (<=1.4.0)
00005 # where this module does not exist and this test won't
00006 # be used anyway
00007 try:
00008     from kss.demo.browser.setupbase import SetupBase
00009     SetupBase = SetupBase       # to satisfy pyflakes
00010 except:
00011     # No problem.
00012     class SetupBase(object):
00013         pass
00014 
00015 from Products.CMFPlone.factory import addPloneSite
00016 
00017 logger=logging.getLogger('kss')
00018 
00019 class SiteCreationView(SetupBase):
00020 
00021     # objects_tree defines the tree of kss contents used in our tests
00022     # You can add your objects used in kss tests and generic attributes
00023     objects_tree = [{'id':'kssfolder', 
00024                  'portal_type':'Folder',
00025                  'attrs':{
00026                           'title':'KssFolder',
00027                           'description':'Folder for KSS contents',
00028                          },
00029                  'transitions': ('publish',),
00030                  'children': [{'id':'documentitem',
00031                               'portal_type':'Document',
00032                               'children':[],
00033                               'transitions': ('publish',),
00034                               'attrs':{
00035                                        'title':'KssDocument',
00036                                        'text':"""
00037                                               KSS is a javascript framework that aims to allow Ajax development 
00038                                               without javascript. It uses stylesheets with CSS-compliant syntax 
00039                                               to setup behaviours in the client and a set of well-defined commands 
00040                                               that are marshalled back from the server to manipulate the DOM.
00041                                               We'll also add an external link also (<a href="http://www.plone.org">
00042                                               [bug #6343] click here to test if the external link works!</a>).
00043                                               """,
00044                                        'description':"""
00045                                                      KSS is a javascript framework that aims to allow Ajax development 
00046                                                      without javascript.
00047                                                      """,
00048                                       }
00049                              },
00050                              {'id':'newsitem',
00051                               'portal_type':'News Item',
00052                               'children':[],
00053                               'attrs':{
00054                                        'title':'KssNews',
00055                                        'text':"""
00056                                               An early spring sprint at a beautiful location on the Italian coast. 
00057                                               The sprint will focus on topics of interest for Plone 4.0. Potential 
00058                                               topics include custom membership, extending Plone's use of AJAX, 
00059                                               content export-import, and much more.
00060                                               """,
00061                                        'description':"""
00062                                                  a    Sorrento sprint
00063                                                      """,
00064                                       }
00065                              },
00066                             ],
00067                 }]
00068 
00069     users = [ { 'username': 'testuser',
00070                 'password': 'secret',
00071                 'roles': [ 'Member' ]
00072               },
00073               { 'username': 'testmanager',
00074                 'password': 'secret',
00075                 'roles': [ 'Manager', 'Member' ]
00076               } ]
00077 
00078     def addUsers(self, portal):
00079         for user in self.users:
00080             portal.acl_users._doAddUser(user['username'], user['password'], user['roles'], [])
00081  
00082     def createSite(self, root):
00083         site_id = 'ksstestportal'
00084         if hasattr(root, site_id):
00085             logger.info('Deleting previous site "%s".' % (site_id, ))
00086             root.manage_delObjects([site_id])
00087         logger.info('Adding new site "%s".' % (site_id, ))
00088         addPloneSite(dispatcher=root, id=site_id, extension_ids=())
00089         return root[site_id]
00090 
00091     def createNodes(self, node, objs_tree, portal):
00092         """Recursive method that create the tree structure of content types used for kss tests."""
00093         for item in objs_tree:
00094             obj_id = item.get('id')
00095             obj_pt = item.get('portal_type')
00096             obj_attrs = item.get('attrs')
00097             obj_children = item.get('children')
00098             obj_transitions = item.get('transitions', ())
00099             if hasattr(node, obj_id):
00100                 # if the object exists, we'll delete it
00101                 node.manage_delObjects([obj_id])
00102             node.invokeFactory(obj_pt, obj_id)
00103             new_obj = getattr(node, obj_id, None)
00104             # writing object attributes
00105             new_obj.update(**obj_attrs)
00106             # applying the transitions in order
00107             for transition in obj_transitions:
00108                 portal.portal_workflow.doActionFor(new_obj, transition)
00109           
00110             # recursive call for creating other nodes
00111             self.createNodes(new_obj, obj_children, portal)
00112 
00113     def run(self, zoperoot):
00114         """This method invokes the recursive method createNodes which creates the tree structure of
00115         objects used by.
00116         """
00117         site = self.createSite(zoperoot)
00118         
00119         self.addUsers(site)
00120         
00121         self.createNodes(site, self.objects_tree, site)
00122 
00123         status_message='Selenium Test Site has been created'
00124         logger.info(status_message)
00125 
00126         # The method must return a tag with id "ok", containing the text "OK".
00127         # to signal success to the testsuite. 
00128         return '<html><body><div id="OK">OK</div><div>Site creation succesful.</div></body></html>'