def getTestSuiteSortKey(test_suite):
     test_result_list = portal.portal_catalog(
         portal_type="Test Result",
         title=SimpleQuery(title=test_suite.getTitle()),
         creation_date=SimpleQuery(
             creation_date=from_date,
             comparison_operator='>=',
         ),
         sort_on=[("modification_date", "descending")],
         limit=1)
     if len(test_result_list):
         test_result = test_result_list[0].getObject()
         key = test_result.getModificationDate().timeTime()
         # if a test result has all it's tests already ongoing, it is not a
         # priority at all to process it, therefore push it at the end of the list
         if test_result.getSimulationState() == "started":
             result_line_list = test_result.objectValues(
                 portal_type="Test Result Line")
             if len(result_line_list):
                 if len([
                         x for x in result_line_list
                         if x.getSimulationState() == "draft"
                 ]) == 0:
                     key = now.timeTime()
     else:
         key = random.random()
     return key
Exemple #2
0
    def getAllDocuments(self, option_json):
        response = {"rows": []}
        kw = {}
        if isinstance(option_json.get('query'), dict):
            kw['query'] = self.parseQuery(option_json["query"])
            kw['query'] = ComplexQuery(
              kw['query'],
              ComplexQuery(
                operator='or',
                *[SimpleQuery(comparison_operator="=", portal_type=x) \
                  for x in self.allowed_portal_type_list]
              ),
              comparison_operator='and'
            )
        else:
            kw['query'] = ComplexQuery(
              operator='or',
              *[SimpleQuery(comparison_operator="=", portal_type=x) \
                for x in self.allowed_portal_type_list]
            )

        if isinstance(option_json.get('limit'), list):
            kw['limit'] = tuple(option_json['limit'])

        c = self.simple_conversion_dict
        if isinstance(option_json.get('sort_on'), list):
            for i in range(len(option_json['sort_on'])):
                s = option_json['sort_on'][i]
                option_json['sort_on'][i] = dictGetKeyFromValue(c, s[0], s[0])
            kw['sort_on'] = option_json['sort_on']

        if not isinstance(option_json.get('select_list'), list):
            option_json['select_list'] = []
        if option_json['select_list'] != []:
            id_list = context.portal_catalog.getSQLCatalog().getColumnIds()
            i = len(option_json['select_list']) - 1
            while i >= 0:
                s = option_json['select_list'][i]
                option_json['select_list'][i] = dictGetKeyFromValue(c, s, s)
                if option_json['select_list'][i] not in id_list:
                    option_json['select_list'].pop(i)
                i -= 1
        kw['select_list'] = option_json['select_list']
        #portal.person_module.log("catalog ----------===============>", kw);
        for document in context.portal_catalog(**kw):
            url = tool.getUrlFromDocument(document)
            row = {"id": url, "key": url, "value": {}}
            for erp5_meta in option_json['select_list']:
                jio_meta = c.get(erp5_meta, erp5_meta)
                row['value'][jio_meta] = getattr(document, erp5_meta, None)
                if isinstance(row['value'][jio_meta], DateTime):
                    row['value'][jio_meta] = row['value'][jio_meta].ISO8601()
            if option_json.get('include_docs') is True:
                row["doc"] = self.getDocumentMetadata({"_id": url})
            response["rows"].append(row)
        response["total_rows"] = len(response["rows"])
        return response
Exemple #3
0
 def createTestResultLineList(test_result, test_name_list):
   test_priority_list = []
   previous_test_result_list = portal.test_result_module.searchFolder(
          title=SimpleQuery(comparison_operator='=', title=test_result.getTitle()),
          sort_on=[('creation_date','descending')],
          simulation_state=('stopped', 'public_stopped'),
          limit=1)
   if len(previous_test_result_list):
     previous_test_result = previous_test_result_list[0].getObject()
     for line in previous_test_result.objectValues():
       if line.getSimulationState() in ('stopped', 'public_stopped'):
         # Execute first the tests that failed on previous run (so that we
         # can see quickly if a fix was effective) and the slowest tests (to
         # make sure slow tests are executed in parrallel and prevent
         # situations where at the end all test nodes are waiting for the
         # latest to finish).
         test_priority_list.append(
             (line.getStringIndex() == 'PASSED',
              -line.getProperty('duration'),
              line.getTitle()))
   sorted_test_list = [x[2] for x in sorted(test_priority_list)]
   # Sort tests by name to have consistent ids for test result line on a
   # test suite.
   for test_name in sorted(test_name_list):
     index = 0
     if sorted_test_list:
       try:
         index = sorted_test_list.index(test_name)
       except ValueError:
         pass
     line = test_result.newContent(portal_type='Test Result Line',
                                   title=test_name,
                                   int_index=index)
def check(node_uid, section_uid, mirror_section_uid):
    precision = precision_by_section_uid[section_uid]
    if mirror_section_uid is None:
        mirror_section_uid = SimpleQuery(mirror_section_uid=None)
    line_list = portal.portal_simulation.getMovementHistoryList(
        portal_type=portal.getPortalAccountingMovementTypeList(),
        grouping_reference=context.getGroupingReference(),
        node_uid=node_uid,
        section_uid=section_uid,
        mirror_section_uid=mirror_section_uid)
    if not line_list:
        return
    total = round(sum([(l.total_price or 0) for l in line_list]), precision)
    if total != 0:
        # XXX if n transactions that do not match are grouped together, the same
        # problem will be reported n times.
        portal.restrictedTraverse(active_process).postResult(
            ActiveResult(summary=script.getId(),
                         detail='%s has wrong grouping (%s)' %
                         (context.getRelativeUrl(), total),
                         result='',
                         severity=100))

    # XXX we could check this as well
    """
Exemple #5
0
 def createTestResultLineList(test_result, test_name_list):
     duration_list = []
     previous_test_result_list = portal.test_result_module.searchFolder(
         title=SimpleQuery(comparison_operator='=',
                           title=test_result.getTitle()),
         sort_on=[('creation_date', 'descending')],
         simulation_state=('stopped', 'public_stopped'),
         limit=1)
     if len(previous_test_result_list):
         previous_test_result = previous_test_result_list[0].getObject()
         for line in previous_test_result.objectValues():
             if line.getSimulationState() in ('stopped',
                                              'public_stopped'):
                 duration_list.append(
                     (line.getTitle(), line.getProperty('duration')))
     duration_list.sort(key=lambda x: -x[1])
     sorted_test_list = [x[0] for x in duration_list]
     # Sort tests by name to have consistent numbering of test result line on
     # a test suite.
     for test_name in sorted(test_name_list):
         index = 0
         if sorted_test_list:
             try:
                 index = sorted_test_list.index(test_name)
             except ValueError:
                 pass
         line = test_result.newContent(portal_type='Test Result Line',
                                       title=test_name,
                                       int_index=index)
def getOptimisedPriceCalculationOperandDict(default=None, context=None, **kw):
    """
   Price Method optimised by the preference 
  """
    movement_portal_type = context.portal_type
    preferences = context.portal_preferences
    supply_portal_type_list = []
    if movement_portal_type in context.getPortalSaleTypeList():
        supply_portal_type_list = preferences.getPreferredSaleMovementSupplyPathTypeList(
        )
    elif movement_portal_type in context.getPortalPurchaseTypeList():
        supply_portal_type_list = preferences.getPreferredPurchaseMovementSupplyPathTypeList(
        )
    elif movement_portal_type in context.getPortalInternalTypeList():
        supply_portal_type_list = preferences.getPreferredInternalMovementSupplyPathTypeList(
        )
    if supply_portal_type_list:
        supply_kw = dict(portal_type=supply_portal_type_list)
        for key in preferences.getPreferredPricingSupplyPathKeyCategoryList():
            key_uid = '%s_uid' % key
            supply_kw['default_%s' % key_uid] = context.getProperty(key_uid)
        supply_uid_list = [
            brain.uid for brain in context.portal_catalog(**supply_kw)
        ]
        if supply_uid_list:
            kw['query'] = SimpleQuery(uid=supply_uid_list)
        else:
            return default
    return resource.getPriceCalculationOperandDict(default=default,
                                                   context=context,
                                                   **kw)
Exemple #7
0
def getBankAccountByTitle(title):
  document_list = [x.getObject().getRelativeUrl() for x in
    portal.portal_catalog(portal_type='Bank Account',
                          title=SimpleQuery(title=title, comparison_operator='='))]
  assert len(document_list) == 1, \
      '%d Bank Account with title "%s"' % (len(document_list), title)
  return document_list[0]
Exemple #8
0
    def subscribeNode(self, title, computer_guid, batch_mode=0):
        """
    subscribeNode doc
    """
        test_node_module = self._getTestNodeModule()
        portal = self.getPortalObject()

        tag = "%s_%s" % (self.getRelativeUrl(), title)
        if portal.portal_activities.countMessageWithTag(tag) == 0:
            test_node_list = test_node_module.searchFolder(
                portal_type="Test Node",
                title=SimpleQuery(comparison_operator='=', title=title),
            )
            assert len(test_node_list) in (
                0, 1), "Unable to find testnode : %s" % title
            test_node = None
            if len(test_node_list) == 1:
                test_node = test_node_list[0].getObject()
                if test_node.getValidationState() != 'validated':
                    try:
                        test_node.validate()
                    except e:
                        LOG('Test Node Validate', ERROR, '%s' % e)
            if test_node is None:
                test_node = test_node_module.newContent(
                    portal_type="Test Node",
                    title=title,
                    computer_guid=computer_guid,
                    specialise=self.getRelativeUrl(),
                    activate_kw={'tag': tag})
                self.activate(after_tag=tag).optimizeConfiguration()
            test_node.setPingDate()
            return test_node
        return None
 def getTestSuiteSortKey(test_suite):
     test_result = portal.portal_catalog(
         portal_type="Test Result",
         title=SimpleQuery(title=test_suite.getTitle()),
         creation_date=SimpleQuery(
             creation_date=from_date,
             comparison_operator='>=',
         ),
         sort_on=[("modification_date", "descending")],
         limit=1)
     if len(test_result):
         key = test_result[0].getObject().getModificationDate(
         ).timeTime()
     else:
         key = random.random()
     return key
Exemple #10
0
 def _getTestNodeRelativeUrl(self, node_title):
   portal = self.getPortalObject()
   test_node_list = portal.portal_catalog(
       portal_type="Test Node",
       title=SimpleQuery(comparison_operator='=', title=node_title),
   )
   if len(test_node_list) == 1:
     return test_node_list[0].getRelativeUrl()
 def _getTestSuiteFromTitle(self, suite_title):
     test_suite_list = self._getTestSuiteModule().searchFolder(
         portal_type='Test Suite',
         title=SimpleQuery(comparison_operator='=', title=suite_title),
         validation_state='validated')
     assert len(test_suite_list) == 1, "We found %i test suite for %s" % (
         len(test_suite_list), name)
     test_suite = test_suite_list[0].getObject()
def get_object_by_title(portal_type, title):
    """Use portal catalog to search&fetch the object."""
    result = portal.portal_catalog(portal_type=portal_type,
                                   title=SimpleQuery(title=title,
                                                     comparison_operator='='))
    if len(result) == 1:
        return result[0].getObject()
    return None
def getSecurityCategoryFromAssignment(self, base_category_list, user_name, object, portal_type,
                                      child_category_list=[]):
  """
  This script returns a list of dictionaries which represent
  the security groups which a person is member of. It extracts
  the categories from the current user assignment.
  It is useful in the following cases:
  
  - associate a document (ex. an accounting transaction)
    to the division which the user was assigned to
    at the time it was created
  
  - calculate security membership of a user
  
  The parameters are
  
    base_category_list -- list of category values we need to retrieve
    user_name          -- string obtained from getSecurityManager().getUser().getId()
    object             -- object which we want to assign roles to
    portal_type        -- portal type of object
  """
  context = self
  
  category_list = []
  
  person_object_list = self.portal_catalog.unrestrictedSearchResults(
    query=SimpleQuery(reference=user_name), portal_type='Person')
  
  if len(person_object_list) != 1:
    if len(person_object_list) > 1:
      raise ConsistencyError, "Error: There is more than one Person with reference '%s'" % user_name
    else:
      # if a person_object was not found in the module, we do nothing more
      # this happens for example when a manager with no associated person object
      # creates a person_object for a new user
      return []
  person_object = person_object_list[0].getObject()
  
  # We look for every valid assignments of this user
  for assignment in person_object.contentValues(filter={'portal_type': 'Assignment'}):
    if assignment.getValidationState() == 'open':
      category_dict = {}
      for base_category in base_category_list:
        category_value_list = assignment.getAcquiredValueList(base_category)
        if category_value_list:
          for category_value in category_value_list:
            if base_category in child_category_list:
              if category_value.getPortalType() not in ('Base Category', 'ERP5 Site'):
                while category_value.getPortalType() not in ('Base Category', 'ERP5 Site'):
                  category_dict.setdefault(base_category, []).append('%s*' % category_value.getRelativeUrl())
                  category_value = category_value.getParentValue()
              else:
                category_dict.setdefault(base_category, []).append(category_value.getRelativeUrl())
            else:
              category_dict.setdefault(base_category, []).append(category_value.getRelativeUrl())
      category_list.append(category_dict)
  
  return category_list
Exemple #14
0
 def getTestSuiteSortKey(test_suite):
     test_result_list = portal.portal_catalog(
         portal_type="Test Result",
         title=SimpleQuery(title=test_suite.getTitle()),
         creation_date=SimpleQuery(
             creation_date=from_date,
             comparison_operator='>=',
         ),
         sort_on=[("modification_date", "descending")],
         limit=1)
     if len(test_result_list):
         test_result = test_result_list[0].getObject()
         modification_date = test_result.getModificationDate().timeTime(
         )
         key = (1, modification_date)
         # if a test result has all it's tests already ongoing, it is not a
         # priority at all to process it, therefore push it at the end of the list
         if test_result.getSimulationState() == "started":
             result_line_list = test_result.objectValues(
                 portal_type="Test Result Line")
             check_priority = True
             if len(result_line_list):
                 if len([
                         x for x in result_line_list
                         if x.getSimulationState() == "draft"
                 ]) == 0:
                     key = (1000, now.timeTime())
                     check_priority = False
             if check_priority:
                 # calculate key[0] in such a way that more the test suite has high
                 # priority and the more test result lack test node, the lower is key[0]
                 # This allows to affect more test nodes to test suites with higher priority
                 wanted_test_core_quantity = PRIORITY_MAPPING[
                     test_suite.getIntIndex()][1]
                 factor = float(max_test_core_per_suite
                                ) / wanted_test_core_quantity
                 missing_quantity = wanted_test_core_quantity / 3 - len(
                     test_result.objectValues(
                         portal_type="Test Result Node"))
                 key = (max_test_core_per_suite -
                        missing_quantity * 3 * factor,
                        modification_date)
     else:
         key = (0, random.random())
     return key
Exemple #15
0
 def _getTestNodeFromTitle(self, node_title):
     test_node_list = self._getTestNodeModule().searchFolder(
         portal_type="Test Node",
         title=SimpleQuery(comparison_operator='=', title=node_title),
         limit=2)
     assert len(test_node_list) == 1, "We found %i test nodes for %s" % (
         len(test_node_list), node_title)
     test_node = test_node_list[0].getObject()
     return test_node
Exemple #16
0
 def test_NoneValueToSimpleQuery(self):
   """
     When a SimpleQuery receives a python None value and an "=" comparison
     operator (be it the default or explictely provided), it must change that
     operator into an "is" operator.
     If "is" compariton operator is explicitely provided with a non-None
     value, raise.
     If non-"=" compariton operator is provided with a None value, raise.
   """
   self.assertEqual(ReferenceQuery(operator='is', default=None),
                    SimpleQuery(default=None))
   self.assertEqual(ReferenceQuery(operator='is', default=None),
                    SimpleQuery(default=None, comparison_operator='='))
   self.assertEqual(ReferenceQuery(operator='is not', default=None),
                    SimpleQuery(default=None, comparison_operator='!='))
   self.assertEqual(ReferenceQuery(operator='is not', default=None),
                    SimpleQuery(default=None, comparison_operator='is not'))
   self.assertRaises(ValueError, SimpleQuery, default=None, comparison_operator='>=')
   self.assertRaises(ValueError, SimpleQuery, default=1, comparison_operator='is')
 def _portal_catalog(self, **kw):
     result_list = self.portal.portal_catalog(**kw)
     uid_list = [x.uid for x in result_list]
     if len(uid_list):
         return self.portal.portal_catalog(
             uid=uid_list,
             query=SimpleQuery(creation_date=self.test_launch_date,
                               comparison_operator='>'),
         )
     else:
         return result_list
Exemple #18
0
    def _searchAndActivate(self,
                           method_id,
                           method_args=(),
                           method_kw={},
                           activate_kw={},
                           min_uid=None,
                           **kw):
        """Search the catalog and run a script by activity on all found objects

      This method is configurable (via 'packet_size' & 'activity_count'
      parameters) so that it can work efficiently with databases of any size.
      'select_method_id', if provided, will be called with partial catalog
      results and returned value will be provided to the callable identified by
      'method_id' (which will no longer be invoked in the context of a given
      document returned by catalog) as first positional argument.

      'activate_kw' may specify an active process to collect results.
      """
        catalog_kw = dict(kw)
        packet_size = catalog_kw.pop('packet_size', 30)
        limit = packet_size * catalog_kw.pop('activity_count', 100)
        select_method_id = catalog_kw.pop('select_method_id', None)
        if min_uid:
            catalog_kw['min_uid'] = SimpleQuery(uid=min_uid,
                                                comparison_operator='>')
        if catalog_kw.pop('restricted', False):
            search = self
        else:
            search = self.unrestrictedSearchResults
        r = search(sort_on=(('uid', 'ascending'), ), limit=limit, **catalog_kw)
        result_count = len(r)
        if result_count:
            if result_count == limit:
                next_kw = dict(activate_kw,
                               priority=1 + activate_kw.get('priority', 1))
                self.activate(activity='SQLQueue', **next_kw) \
                    ._searchAndActivate(method_id,method_args, method_kw,
                                        activate_kw, r[-1].getUid(), **kw)
            portal_activities = self.getPortalObject().portal_activities
            active_portal_activities = portal_activities.activate(
                activity='SQLQueue', **activate_kw)
            if select_method_id is None:
                r = [x.getPath() for x in r]
                r.sort()
                activate = active_portal_activities.callMethodOnObjectList
                method_args = (method_id, ) + method_args
            else:
                r = getattr(portal_activities, select_method_id)(r)
                activate = getattr(active_portal_activities, method_id)
            for i in xrange(0, result_count, packet_size):
                activate(r[i:i + packet_size], *method_args, **method_kw)
 def isMasterTestnode(self, title, batch_mode=0):
     """
 isMasterTestnode : return True if the node given in parameter exists and is a validated master
 """
     test_node_module = self._getTestNodeModule()
     test_node_master = [
         node for node in test_node_module.searchFolder(
             portal_type="Test Node",
             title=SimpleQuery(comparison_operator='=', title=title),
             specialise_uid=self.getUid(),
             validation_state="validated") if node.getMaster() == 1
     ]
     if len(test_node_master) == 1:
         return True
     else:
         return False
Exemple #20
0
 def rec(query_dict):
     if query_dict.get("type") == "simple":
         # if query_dict.get("key") not in self.allowed_property_id_list:
         #   return None
         for erp5_key, jio_key in self.simple_conversion_dict.items():
             if query_dict["key"] == jio_key:
                 query_dict["key"] = erp5_key
                 break
         return SimpleQuery(comparison_operator=query_dict['operator'],
                            **{query_dict['key']: query_dict['value']})
     if query_dict.get("type") == "complex":
         tool.listMapReplace(rec, query_dict['query_list'])
         try:
             while True:
                 query_dict['query_list'].remove(None)
         except ValueError:
             pass
         return ComplexQuery(operator=query_dict['operator'],
                             *query_dict['query_list'])
     return None
    def getTestNode(self, title, batch_mode=0):
        """
    getTestNode doc
    """
        test_node_module = self._getTestNodeModule()
        portal = self.getPortalObject()

        tag = "%s_%s" % (self.getRelativeUrl(), title)
        if portal.portal_activities.countMessageWithTag(tag) == 0:
            test_node_list = test_node_module.searchFolder(
                portal_type="Test Node",
                title=SimpleQuery(comparison_operator='=', title=title),
            )
            assert len(test_node_list) in (
                0, 1), "Unable to find testnode : %s" % title
            test_node = None
            if len(test_node_list) == 1:
                test_node = test_node_list[0].getObject()
                if test_node.getValidationState() != 'validated':
                    try:
                        test_node.validate()
                    except Exception, e:
                        LOG('Test Node Validate', ERROR, '%s' % e)
            return test_node
Exemple #22
0
    def createTestResult(self,
                         name,
                         revision,
                         test_name_list,
                         allow_restart,
                         test_title=None,
                         node_title=None,
                         project_title=None):
        """(temporary)
      - name (string)
      - revision (string representation of an integer)
      - test_name_list (list of strings)
      - allow_restart (boolean)

      XXX 'revision' should be a string representing the full revision
          of the tested code, because some projects are tested with different
          revisions of ERP5.

      -> (test_result_path, revision) or None if already completed
    """
        LOG('createTestResult', 0, (name, revision, test_title, project_title))
        portal = self.getPortalObject()
        if test_title is None:
            test_title = name

        def createNode(test_result, node_title):
            if node_title is not None:
                node = self._getTestResultNode(test_result, node_title)
                if node is None:
                    node = test_result.newContent(
                        portal_type='Test Result Node', title=node_title)
                    node.start()

        def createTestResultLineList(test_result, test_name_list):
            duration_list = []
            previous_test_result_list = portal.test_result_module.searchFolder(
                title=SimpleQuery(comparison_operator='=',
                                  title=test_result.getTitle()),
                sort_on=[('creation_date', 'descending')],
                simulation_state=('stopped', 'public_stopped'),
                limit=1)
            if len(previous_test_result_list):
                previous_test_result = previous_test_result_list[0].getObject()
                for line in previous_test_result.objectValues():
                    if line.getSimulationState() in ('stopped',
                                                     'public_stopped'):
                        duration_list.append(
                            (line.getTitle(), line.getProperty('duration')))
            duration_list.sort(key=lambda x: -x[1])
            sorted_test_list = [x[0] for x in duration_list]
            # Sort tests by name to have consistent numbering of test result line on
            # a test suite.
            for test_name in sorted(test_name_list):
                index = 0
                if sorted_test_list:
                    try:
                        index = sorted_test_list.index(test_name)
                    except ValueError:
                        pass
                line = test_result.newContent(portal_type='Test Result Line',
                                              title=test_name,
                                              int_index=index)

        reference_list_string = None
        if type(revision) is str and '=' in revision:
            reference_list_string = revision
            int_index, reference = None, revision
        elif type(revision) is str:
            # backward compatibility
            int_index, reference = revision, None
        else:
            # backward compatibility
            int_index, reference = revision
        catalog_kw = {
            'portal_type': 'Test Result',
            'title': SimpleQuery(comparison_operator='=', title=test_title),
            'sort_on': (("creation_date", "descending"), ),
            'query': NegatedQuery(SimpleQuery(simulation_state="cancelled")),
            'limit': 1
        }
        result_list = portal.test_result_module.searchFolder(**catalog_kw)
        if result_list:
            test_result = result_list[0].getObject()
            if test_result is not None:
                last_state = test_result.getSimulationState()
                last_revision = str(test_result.getIntIndex())
                if last_state == 'started':
                    createNode(test_result, node_title)
                    reference = test_result.getReference()
                    if reference_list_string:
                        last_revision = reference
                    elif reference:
                        last_revision = last_revision, reference
                    result_line_list = test_result.objectValues(
                        portal_type="Test Result Line")
                    result_line_list_len = len(result_line_list)
                    if result_line_list_len == 0 and len(test_name_list):
                        test_result.serialize(
                        )  # prevent duplicate test result lines
                        createTestResultLineList(test_result, test_name_list)
                    elif result_line_list_len:
                        # Do not process test result if all test result lines are already affected
                        if len([
                                x for x in result_line_list
                                if x.getSimulationState() == 'draft'
                        ]) == 0:
                            return
                    return test_result.getRelativeUrl(), last_revision
                if last_state in ('stopped', 'public_stopped'):
                    if not allow_restart:
                        if reference_list_string is not None:
                            if reference_list_string == test_result.getReference(
                            ):
                                return
                            if portal.test_result_module.searchFolder(
                                    reference=SimpleQuery(
                                        comparison_operator='=',
                                        reference=reference_list_string),
                                    **catalog_kw):
                                return
                        if last_revision == int_index:
                            return
        test_result = portal.test_result_module.newContent(
            portal_type='Test Result',
            title=test_title,
            reference=reference,
            is_indexable=False)
        if int_index is not None:
            test_result._setIntIndex(int_index)
        if project_title is not None:
            project_list = portal.portal_catalog(portal_type='Project',
                                                 title=SimpleQuery(
                                                     comparison_operator='=',
                                                     title=project_title))
            if len(project_list) != 1:
                raise ValueError('found this list of project : %r for title %r' % \
                              ([x.path for x in project_list], project_title))
            test_result._setSourceProjectValue(project_list[0].getObject())
        test_result.updateLocalRolesOnSecurityGroups()  # XXX
        test_result.start()
        del test_result.isIndexable
        test_result.immediateReindexObject()
        self.serialize()  # prevent duplicate test result
        # following 2 functions only call 'newContent' on test_result
        createTestResultLineList(test_result, test_name_list)
        createNode(test_result, node_title)
        return test_result.getRelativeUrl(), revision
Exemple #23
0
from Products.ZSQLCatalog.SQLCatalog import SimpleQuery

record = context
search_kw = {
    'portal_type': record.getPortalType(),
    'strict_follow_up_uid': record.getFollowUpUid(),
    'simulation_state': "stopped",
    # exclude current workflow changed document
    'uid': SimpleQuery(uid=record.getUid(), comparison_operator='!='),
}

# We can now archive all previous records
for old_document in context.getPortalObject().portal_catalog(**search_kw):
    old_document = old_document.getObject()
    if old_document.getSimulationState() in ("stopped"):
        old_document.deliver()
Exemple #24
0
    def _searchPredicateList(self,
                             context,
                             test=1,
                             sort_method=None,
                             ignored_category_list=None,
                             tested_base_category_list=None,
                             filter_method=None,
                             acquired=1,
                             sort_key_method=None,
                             query=None,
                             restricted=False,
                             **kw):
        """
      Search all predicates which corresponds to this particular
      context.

      - sort_method parameter should not be used, if possible, because
        it can be very slow. Use sort_key_method instead.

      - sort_key_method parameter is passed to list.sort as key parameter if it
        is not None. This allows to sort the list of predicates found. The most
        important predicate is the first one in the list.

      - ignored_category_list:  this is the list of category that we do
        not want to test. For example, we might want to not test the
        destination or the source of a predicate.

      - tested_base_category_list:  this is the list of category that we do
        want to test. For example, we might want to test only the
        destination or the source of a predicate.

      - the acquired parameter allows to define if we want to use
        acquisition for categories. By default we want.
    """
        if not kw.pop('strict', True):
            raise ValueError('"strict" mode cannot be disabled anymore')
        portal = self.getPortalObject()
        portal_catalog = portal.portal_catalog
        portal_categories = portal.portal_categories
        # Search the columns of the predicate table
        query_list = [] if query is None else [query]
        for column in portal_catalog.getSQLCatalog().getTableColumnList(
                'predicate'):
            # Arbitrary suffix choice, this code expects COLUMN, COLUMN_range_min
            # and COLUMN_range_max to be simultaneously present for ranged
            # properties. Only checking one suffix simplifies the code flow.
            if column.endswith('_range_min'):
                property_name = column[:-10]
                # We have to check a range property
                equality = 'predicate.' + property_name
                range_min = equality + '_range_min'
                range_max = equality + '_range_max'

                value = context.getProperty(property_name)

                query = ComplexQuery(SimpleQuery(**{equality: None}),
                                     SimpleQuery(**{range_min: None}),
                                     SimpleQuery(**{range_max: None}),
                                     logical_operator='AND')

                if value is not None:
                    query = ComplexQuery(
                        query,
                        SimpleQuery(**{equality: value}),
                        ComplexQuery(
                            SimpleQuery(comparison_operator='<=',
                                        **{range_min: value}),
                            SimpleQuery(**{range_max: None}),
                            logical_operator='AND',
                        ),
                        ComplexQuery(
                            SimpleQuery(**{range_min: None}),
                            SimpleQuery(comparison_operator='>=',
                                        **{range_max: value}),
                            logical_operator='AND',
                        ),
                        ComplexQuery(
                            SimpleQuery(comparison_operator='<=',
                                        **{range_min: value}),
                            SimpleQuery(comparison_operator='>=',
                                        **{range_max: value}),
                            logical_operator='AND',
                        ),
                        logical_operator='OR',
                    )

                query_list.append(query)

        if tested_base_category_list != []:
            # Add category selection
            if tested_base_category_list is None:
                if acquired:
                    category_list = context.getAcquiredCategoryList()
                else:
                    category_list = context.getCategoryList()
            else:
                if acquired:
                    getter = context.getAcquiredCategoryMembershipList
                else:
                    getter = context.getCategoryMembershipList
                category_list = []
                extend = category_list.extend
                for tested_base_category in tested_base_category_list:
                    if portal_categories.get(tested_base_category) is None:
                        raise ValueError('Unknown base category: %r' %
                                         (tested_base_category, ))
                    tested_category_list = getter(tested_base_category, base=1)
                    if tested_category_list:
                        extend(tested_category_list)
                    else:
                        # Developer requested specific base categories, but context do not
                        # declare one of these. Skipping this criterion risks matching too
                        # many predicates, breaking the system performance-wise. So let
                        # developer know there is an unexpected situation by raising.
                        raise ValueError('%r does not have any %r relation' % (
                            context.getPath(),
                            tested_base_category,
                        ))
            left_join_list = kw.get('left_join_list', [])[:]
            inner_join_list = kw.get('inner_join_list', [])[:]
            if category_list:
                preferred_predicate_category_list = portal.portal_preferences.getPreferredPredicateCategoryList(
                    [])
                left_join_category_list = []
                inner_join_category_list = []
                for category in category_list:
                    if portal_categories.getBaseCategoryId(
                            category) in preferred_predicate_category_list:
                        inner_join_category_list.append(category)
                    else:
                        left_join_category_list.append(category)

                def onMissing(category):
                    # BBB: ValueError would seem more appropriate here, but original code
                    # was raising TypeError - and this is explicitely tested for.
                    raise TypeError('Unknown category: %r' % (category, ))

                def onInnerJoin(column_name):
                    inner_join_list.append(column_name)
                    # Base category is part of preferred predicate categories, predicates
                    # which ignore it are indexed with category_uid=0.
                    return SimpleQuery(**{column_name: 0})

                query_list.append(
                    portal_catalog.getCategoryParameterDict(
                        inner_join_category_list,
                        category_table='predicate_category',
                        onMissing=onMissing,
                        onJoin=onInnerJoin,
                    ))

                def onLeftJoin(column_name):
                    left_join_list.append(column_name)
                    # Base category is not part of preferred predicate categories,
                    # predicates which ignore it get no predicate_category row inserted
                    # for it, so an SQL NULL appears, translating to None.
                    return SimpleQuery(**{column_name: None})

                query_list.append(
                    portal_catalog.getCategoryParameterDict(
                        left_join_category_list,
                        category_table='predicate_category',
                        onMissing=onMissing,
                        onJoin=onLeftJoin,
                    ))
            else:
                # No category to match against, so predicates expecting any relation
                # would not apply, so we can exclude these.
                # Note: this relies on a special indexation mechanism for predicate
                # categories, which inserts a base_category_uid=0 line when indexed
                # predicate membership_criterion_category_list is empty.
                base_category_uid_column = 'predicate_category.base_category_uid'
                kw[base_category_uid_column] = 0
                inner_join_list.append(base_category_uid_column)
            kw['left_join_list'] = left_join_list
            kw['inner_join_list'] = inner_join_list
        if query_list:
            kw['query'] = ComplexQuery(logical_operator='AND', *query_list)

        if restricted:
            sql_result_list = portal_catalog.searchResults(**kw)
        else:
            sql_result_list = portal_catalog.unrestrictedSearchResults(**kw)
        if kw.get('src__'):
            return sql_result_list
        result_list = []
        if sql_result_list:
            if test:
                cache = {}

                def isMemberOf(context, c, strict_membership):
                    if c in cache:
                        return cache[c]
                    cache[c] = result = portal_categories.isMemberOf(
                        context, c, strict_membership=strict_membership)
                    return result

            for predicate in sql_result_list:
                predicate = predicate.getObject()
                if not test or predicate.test(context,
                                              tested_base_category_list,
                                              isMemberOf=isMemberOf):
                    result_list.append(predicate)
            if filter_method is not None:
                result_list = filter_method(result_list)
            if sort_key_method is not None:
                result_list.sort(key=sort_key_method)
            elif sort_method is not None:
                result_list.sort(cmp=sort_method)
        return result_list
Exemple #25
0
 def onLeftJoin(column_name):
     left_join_list.append(column_name)
     # Base category is not part of preferred predicate categories,
     # predicates which ignore it get no predicate_category row inserted
     # for it, so an SQL NULL appears, translating to None.
     return SimpleQuery(**{column_name: None})
Exemple #26
0
 def onInnerJoin(column_name):
     inner_join_list.append(column_name)
     # Base category is part of preferred predicate categories, predicates
     # which ignore it are indexed with category_uid=0.
     return SimpleQuery(**{column_name: 0})
Exemple #27
0
portal.portal_selections.setSelectionFor('account_module_selection', None)

# set sort order on accounting module
portal.portal_selections.setSelectionParamsFor(
    'accounting_selection', {})  # (this recreates selection)
portal.portal_selections.setSelectionSortOrder('accounting_selection',
                                               sort_on=(('operation_date',
                                                         'ascending'), ))

# set sort order and columns on account module
portal.portal_selections.setSelectionParamsFor(
    'account_module_selection', {})  # (this recreates selection)
portal.portal_selections.setSelectionSortOrder('account_module_selection',
                                               sort_on=(('preferred_gap_id',
                                                         'ascending'), ))
portal.portal_selections.setSelectionColumns(
    'account_module_selection',
    [('preferred_gap_id', 'GAP Number'), ('translated_title', 'Account Name'),
     ('translated_validation_state_title', 'State'),
     ('AccountModule_getAccountingTransactionCount', 'Count'),
     ('debit', 'Debit'), ('credit', 'Credit'),
     ('debit_balance', 'Debit Balance'), ('credit_balance', 'Credit Balance')])

# delete the "dummy account" we create in test_account_gap_parallel_list_field
dummy_account_list = portal.account_module.searchFolder(title=SimpleQuery(
    title='Dummy Account for UI Test', comparison_operator='='))
if dummy_account_list:
    portal.account_module.manage_delObjects([dummy_account_list[0].getId()])

return "Reset Successfully."
Exemple #28
0
category_uid_list = ('payment_uid', 'project_uid', 'funding_uid',
                     'function_uid', 'ledger_uid', 'payment_request_uid',
                     'default_aggregate_uid')
for category_uid in category_uid_list:
    category_uid_value = kw.get(category_uid)
    if category_uid_value:
        if category_uid_value == 'None':
            # XXX Jerome: this code needs some clarification. It is used after a dialog
            # with a list field for project (same for function, payment_request,
            # funding) where the user can select an empty item which means no filter
            # on project, can select a project which means only transactions for
            # that specific project, or select a special value "None" which means
            # transactions that are not related to a project. For that we need a
            # query that will be translated as stock.project_uid IS NULL.
            params[category_uid] = SimpleQuery(**{category_uid: None})
        else:
            params[category_uid] = category_uid_value

funding_category = kw.get('funding_category')
if funding_category:
    if funding_category == 'None':
        params['funding_uid'] = SimpleQuery(funding_uid=None)
    else:
        params['funding_category'] = funding_category
function_category = kw.get('function_category')
if function_category:
    if function_category == 'None':
        params['function_uid'] = SimpleQuery(function_uid=None)
    else:
        params['function_category'] = function_category
            portal_type='Organisation',
            title=SimpleQuery(title=title, comparison_operator='='))
    ]
    assert len(document_list) == 1, \
          '%d organisation with title "%s"' % (len(document_list), title)
    return document_list[0]


section = getOrganisationByTitle(section_title)

euro_resource = 'currency_module/euro'

product_list = [
    o.getObject() for o in portal.portal_catalog(
        portal_type='Product',
        title=SimpleQuery(title='Dummy Product for testing',
                          comparison_operator='='))
]
if product_list:
    product = product_list[0]
else:
    product = portal.product_module.newContent(
        portal_type='Product', title='Dummy Product for testing')

for _ in range(random.randint(5, 10)):
    pl = portal.sale_packing_list_module.newContent(
        portal_type='Sale Packing List',
        title='Dummy Packing List for testing',
        source_section=section,
        source=section,
        destination_section=getOrganisationByTitle('Client 1'),
        destination=getOrganisationByTitle('Client 1'),
Exemple #30
0
 def startTestSuite(self, title, computer_guid=None, batch_mode=0):
     """
 startTestSuite doc
 """
     test_node_module = self._getTestNodeModule()
     test_suite_module = self._getTestSuiteModule()
     portal = self.getPortalObject()
     config_list = []
     tag = "%s_%s" % (self.getRelativeUrl(), title)
     if portal.portal_activities.countMessageWithTag(tag) == 0:
         test_node_list = test_node_module.searchFolder(
             portal_type="Test Node",
             title=SimpleQuery(comparison_operator='=', title=title),
         )
         assert len(test_node_list) in (
             0, 1), "Unable to find testnode : %s" % title
         test_node = None
         if len(test_node_list) == 1:
             test_node = test_node_list[0].getObject()
             if test_node.getValidationState() != 'validated':
                 test_node.validate()
         if test_node is None:
             test_node = test_node_module.newContent(
                 portal_type="Test Node",
                 title=title,
                 specialise=self.getRelativeUrl(),
                 activate_kw={'tag': tag})
             self.activate(after_tag=tag).optimizeConfiguration()
         test_node.setPingDate()
         choice_list = self._getSortedNodeTestSuiteToRun(test_node)
         for test_suite in choice_list:
             config = {}
             config["project_title"] = test_suite.getSourceProjectTitle()
             config["test_suite"] = test_suite.getTestSuite()
             config["test_suite_title"] = test_suite.getTitle()
             config[
                 "additional_bt5_repository_id"] = test_suite.getAdditionalBt5RepositoryId(
                 )
             config["test_suite_reference"] = test_suite.getReference()
             vcs_repository_list = []
             #In this case objectValues is faster than searchFolder
             for repository in test_suite.objectValues(
                     portal_type="Test Suite Repository"):
                 repository_dict = {}
                 for property_name in [
                         "git_url", "profile_path", "buildout_section_id",
                         "branch"
                 ]:
                     property_value = repository.getProperty(property_name)
                     # the property name url returns the object's url, so it is mandatory use another name.
                     if property_name == "git_url":
                         property_name = "url"
                     if property_value is not None:
                         repository_dict[property_name] = property_value
                 vcs_repository_list.append(repository_dict)
             config["vcs_repository_list"] = vcs_repository_list
             to_delete_key_list = [
                 x for x, y in config.items() if y == None
             ]
             [config.pop(x) for x in to_delete_key_list]
             config_list.append(config)
     LOG('ERP5ProjectUnitTestDistributor.startTestSuite, config_list',
         DEBUG, config_list)
     if batch_mode:
         return config_list
     return json.dumps(config_list)