예제 #1
0
 def _clear(self, call_close_hook=0):
     '''Clears the fixture.'''
     if PLONE30:
         self._resetRAMCache()
     PortalTestCase._clear(self, call_close_hook)
     if PLONE30:
         _placefulTearDown()
예제 #2
0
 def logout(self):
   PortalTestCase.logout(self)
   # clean up certain cache related REQUEST keys that might be associated
   # with the logged in user
   if getattr(self, 'REQUEST', None) is not None:
     for key in ('_ec_cache', '_oai_cache'):
       self.REQUEST.other.pop(key, None)
예제 #3
0
 def test_MaximumRecursionDepthExceededWithComplexSecurity(self):
   skin = self.portal.portal_skins.custom
   colour = self.portal.portal_categories.colour
   colour.hasObject('green') or colour.newContent('green')
   login = str(time.time())
   script_id = ["ERP5Type_getSecurityCategoryMapping",
                "ERP5Type_getSecurityCategory"]
   createZODBPythonScript(skin, script_id[0], "",
     "return ((%r, ('colour',)),)" % script_id[1])
   createZODBPythonScript(skin, script_id[1],
     "base_category_list, user_name, object, portal_type, depth=[]", """if 1:
     # This should not be called recursively, or at least if should not fail.
     # Because RuntimeError is catched by 'except:' clauses, we detect it
     # with a static variable.
     depth.append(None)
     assert not portal_type, portal_type
     # the following line calls Base_zSearchRelatedObjectsByCategoryList
     object.getSourceDecisionRelatedValueList()
     bc, = base_category_list
     depth.pop()
     return [] if depth else [{bc: 'green'}]
     """)
   person = self.portal.person_module.newContent(reference=login)
   try:
     self.tic()
     PortalTestCase.login(self, person.Person_getUserId())
     self.assertEqual(['green'], getSecurityManager().getUser().getGroups())
     self.portal.portal_caches.clearAllCache()
     PortalTestCase.login(self, person.Person_getUserId())
     unittest.expectedFailure(self.assertEqual)(
       ['green'], getSecurityManager().getUser().getGroups())
   finally:
     skin.manage_delObjects(script_id)
     self.commit()
예제 #4
0
 def tearDown(self):
   '''Tears down the fixture. Do not override,
      use the hooks instead.
   '''
   if not int(os.environ.get('erp5_save_data_fs', 0)):
     # Drop remaining activities if some of them failed.
     # However, we should not do more activity cleaning, because properly
     # written unit tests should not leave unprocessed activity messages.
     # And the user may want to analyse the result of a failed unit test,
     # so we do nothing in persistent mode (--save).
     try:
       portal_activities = self.portal.portal_activities
       message_list = portal_activities.getMessageList()
     except StandardError: # AttributeError, TransactionFailedError ...
       pass
     else:
       for m in message_list:
         if m.processing_node < -1:
           self.abort()
           count = portal_activities.countMessage()
           portal_activities.manageClearActivities()
           self.commit()
           ZopeTestCase._print(' (dropped %d left-over activity messages) '
                               % count)
           break
   PortalTestCase.tearDown(self)
예제 #5
0
 def test_MaximumRecursionDepthExceededWithComplexSecurity(self):
   skin = self.portal.portal_skins.custom
   colour = self.portal.portal_categories.colour
   if not colour.hasObject('green'):
     colour.newContent('green')
   login = str(time.time())
   script_id = ["ERP5Type_getSecurityCategoryMapping",
                "ERP5Type_getSecurityCategory"]
   createZODBPythonScript(skin, script_id[0], "",
     "return ((%r, ('colour',)),)" % script_id[1])
   createZODBPythonScript(skin, script_id[1],
     "base_category_list, user_name, object, portal_type, depth=[]", """if 1:
     # This should not be called recursively, or at least if should not fail.
     # Because RuntimeError is catched by 'except:' clauses, we detect it
     # with a static variable.
     depth.append(None)
     assert not portal_type, portal_type
     object.getSourceDecisionRelatedValueList()
     bc, = base_category_list
     depth.pop()
     return [] if depth else [{bc: 'green'}]
     """)
   person = self.portal.person_module.newContent(reference=login)
   try:
     self.tic()
     PortalTestCase.login(self, person.Person_getUserId())
     self.assertEqual(['green'], getSecurityManager().getUser().getGroups())
     self.portal.portal_caches.clearAllCache()
     PortalTestCase.login(self, person.Person_getUserId())
     self.assertEqual(
       ['green'], getSecurityManager().getUser().getGroups())
   finally:
     skin.manage_delObjects(script_id)
     self.commit()
예제 #6
0
 def login(self, user_name='ERP5TypeTestCase', quiet=0):
   """
   Most of the time, we need to login before doing anything
   """
   try:
     PortalTestCase.login(self, user_name)
   except AttributeError:
     uf = self.getPortal().acl_users
     uf._doAddUser('ERP5TypeTestCase', '', ['Manager', 'Member', 'Assignee',
                   'Assignor', 'Author', 'Auditor', 'Associate'], [])
     return PortalTestCase.login(self, user_name)
예제 #7
0
    def setUp(self):
      '''Sets up the fixture. Do not override,
         use the hooks instead.
      '''
      from Products.CMFActivity.ActivityRuntimeEnvironment import BaseMessage
      # Activities in unit tests shall never fail.
      # Let's be a litte tolerant for the moment.
      BaseMessage.max_retry = property(lambda self:
        self.activity_kw.get('max_retry', 1))

      template_list = list(self.getBusinessTemplateList())
      erp5_catalog_storage = os.environ.get('erp5_catalog_storage',
                                            'erp5_mysql_innodb_catalog')
      update_business_templates = os.environ.get('update_business_templates') is not None
      erp5_load_data_fs = int(os.environ.get('erp5_load_data_fs', 0))
      if update_business_templates and erp5_load_data_fs:
        update_only = os.environ.get('update_only', None)
        template_list[:0] = (erp5_catalog_storage, 'erp5_property_sheets',
                             'erp5_core', 'erp5_xhtml_style')
        # Update only specified business templates, regular expression
        # can be used.
        if update_only is not None:
          update_only_list = update_only.split(',')
          matching_template_list = []
          # First parse the template list in order to keep same order
          for business_template in template_list:
            for expression in update_only_list:
              if re.search(expression, business_template):
                matching_template_list.append(business_template)
          template_list = matching_template_list

      # keep a mapping type info name -> property sheet list, to remove them in
      # tear down.
      self._added_property_sheets = {}
      light_install = self.enableLightInstall()
      create_activities = self.enableActivityTool()
      hot_reindexing = self.enableHotReindexing()
      for x, y in (("erp5_core_proxy_field_legacy", "erp5_base"),
                   ("erp5_stock_cache", "erp5_pdm")):
        if x not in template_list:
          try:
            template_list.insert(template_list.index(y), x)
          except ValueError:
            pass
      self.setUpERP5Site(business_template_list=template_list,
                         light_install=light_install,
                         create_activities=create_activities,
                         quiet=install_bt5_quiet,
                         hot_reindexing=hot_reindexing,
                         erp5_catalog_storage=erp5_catalog_storage)
      PortalTestCase.setUp(self)
예제 #8
0
    def _app(self):
      '''Opens a ZODB connection and returns the app object.

      We override it to patch HTTP_ACCEPT_CHARSET into REQUEST to get the zpt
      unicode conflict resolver to work properly'''
      app = PortalTestCase._app(self)
      app.REQUEST['HTTP_ACCEPT_CHARSET'] = 'utf-8'
      return app
예제 #9
0
 def tearDown(self):
     # avoid any premature tearing down
     PortalTestCase.tearDown(self)
예제 #10
0
 def _clear(self, call_close_hook=0):
     '''Clears the fixture.'''
     PortalTestCase._clear(self, call_close_hook)
     if PLONE30:
         _placefulTearDown()
예제 #11
0
 def _setup(self):
     '''Configures the portal.'''
     PortalTestCase._setup(self)
     if PLONE30 and self.portal is not None:
         self._refreshSkinData()