def afterSetUp(self): if not self.skin: raise NotImplementedError('Subclasses must define skin') gender = self.portal.portal_categories.gender if 'male' not in gender.objectIds(): gender.newContent(id='male') self.portal.portal_caches.clearAllCache() self.auth = 'ERP5TypeTestCase:' person_module = self.portal.person_module if person_module._getOb('pers', None) is None: person_module.newContent(id='pers', portal_type='Person') self.tic() person_module.pers.setFirstName('Bob') person_module.pers.setGender(None) person_module.pers.setCareerRole(None) if person_module.pers._getOb('img', None) is None: person_module.pers.newContent(portal_type='Embedded File', id='img') if person_module._getOb('pers_without_image', None) is None: person = person_module.newContent( portal_type='Person', id = 'pers_without_image', first_name = 'Test') self.tic() self.portal.changeSkin(self.skin) self.validator = Validator() # make sure selections are empty name = 'person_module_selection' self.portal.portal_selections.setSelectionFor(name, Selection(name))
def afterSetUp(self): uf = self.getPortal().acl_users uf._doAddUser('manager', '', ['Manager', 'Assignor'], []) user = uf.getUserById('manager').__of__(uf) newSecurityManager(None, user) self.portal_selections = self.getPortal().portal_selections name = 'test_selection' self.portal_selections.setSelectionFor(name, Selection(name)) self.portal_selections.setSelectionParamsFor('test_selection', {'key':'value'})
def setUp(self): # patch selection tool class so that we don't need a portal_membership to # find the current user name SelectionTool._getUserId_saved = SelectionTool._getUserId SelectionTool._getUserId = lambda self: 'user' SelectionTool.isAnonymous = lambda self: 0 self.db = ZODB.DB(ZODB.DemoStorage.DemoStorage()) self.cnx = self.db.open() self.portal_selections = \ self.cnx.root().portal_selections = SelectionTool() name = 'test_selection' self.portal_selections.setSelectionFor(name, Selection(name)) transaction.commit()
def test_05_EditSelectionWithFileUpload(self, quiet=quiet, run=run_all_test): """Listbox edits selection with request parameters. Special care must be taken for FileUpload objects that cannot be pickled, thus cannot be stored in the ZODB. """ portal = self.getPortal() portal.ListBoxZuite_reset() listbox = portal.FooModule_viewFooList.listbox # XXX isn't Selection automatically created ? name = listbox.get_value('selection_name') portal.portal_selections.setSelectionFor(name, Selection(name)) request = get_request() request['here'] = portal.foo_module request.form['my_file_upload'] = FileUpload(DummyFieldStorage()) listbox.get_value('default', render_format='list', REQUEST=request) try: self.commit() except TypeError, e: self.fail('Unable to commit transaction: %s' % e)
# Verbose is used when we do not want to use the user interface in order # to have a nice error message from Products.ERP5Type.Message import Message from Products.ERP5Type.Document import newTempBase request = context.REQUEST item_model = context.getPortalObject().restrictedTraverse(resource) # We must make sure that the selection is not None # or the validator of the Listbox will not work from Products.ERP5Form.Selection import Selection selection = context.portal_selections.getSelectionFor( 'Check_fastInputForm_selection') if selection is None: selection = Selection() context.portal_selections.setSelectionFor('Check_fastInputForm_selection', selection) global error_value error_value = 0 global field_error_dict field_error_dict = {} def generate_error(listbox_line, column_title, error_message): global error_value global field_error_dict # Generate an error which is displayed by the listbox error_id = 'listbox_%s_new_%s' % (column_title,\ listbox_line['listbox_key']) error = newTempBase(context, error_id)