예제 #1
0
 def testParseOneFieldValue_UrlType(self):
     fd = tracker_bizobj.MakeFieldDef(123, 789, 'Design Doc',
                                      tracker_pb2.FieldTypes.URL_TYPE, None,
                                      '', False, False, False, None, None,
                                      '', False, '', '',
                                      tracker_pb2.NotifyTriggers.NEVER,
                                      'no_action', 'doc', False)
     fv = field_helpers.ParseOneFieldValue(self.mr.cnxn, self.services.user,
                                           fd, 'www.google.com')
     self.assertEqual(fv.field_id, 123)
     self.assertEqual(fv.url_value, 'http://www.google.com')
예제 #2
0
 def testParseOneFieldValue_DateType(self):
     fd = tracker_bizobj.MakeFieldDef(123, 789, 'Deadline',
                                      tracker_pb2.FieldTypes.DATE_TYPE,
                                      None, '', False, False, False, None,
                                      None, '', False, '', '',
                                      tracker_pb2.NotifyTriggers.NEVER,
                                      'no_action', 'doc', False)
     fv = field_helpers.ParseOneFieldValue(self.mr.cnxn, self.services.user,
                                           fd, '2009-02-13')
     self.assertEqual(fv.field_id, 123)
     self.assertEqual(fv.date_value, 1234483200)
예제 #3
0
 def testParseOneFieldValue_StrType(self):
     fd = tracker_bizobj.MakeFieldDef(123, 789, 'Foo',
                                      tracker_pb2.FieldTypes.STR_TYPE, None,
                                      '', False, False, False, None, None,
                                      '', False, '', '',
                                      tracker_pb2.NotifyTriggers.NEVER,
                                      'no_action', 'doc', False)
     fv = field_helpers.ParseOneFieldValue(self.mr.cnxn, self.services.user,
                                           fd, '8675309')
     self.assertEqual(fv.field_id, 123)
     self.assertEqual(fv.str_value, '8675309')
예제 #4
0
 def testParseOneFieldValue_UserType(self):
     self.services.user.TestAddUser('*****@*****.**', 111)
     fd = tracker_bizobj.MakeFieldDef(123, 789, 'Foo',
                                      tracker_pb2.FieldTypes.USER_TYPE,
                                      None, '', False, False, False, None,
                                      None, '', False, '', '',
                                      tracker_pb2.NotifyTriggers.NEVER,
                                      'no_action', 'doc', False)
     fv = field_helpers.ParseOneFieldValue(self.mr.cnxn, self.services.user,
                                           fd, '*****@*****.**')
     self.assertEqual(fv.field_id, 123)
     self.assertEqual(fv.user_id, 111)
예제 #5
0
def convert_field_values(field_values, mar, services):
    """Convert user passed in field value list to FieldValue PB, or labels."""
    fv_list_add = []
    fv_list_remove = []
    fv_list_clear = []
    label_list_add = []
    label_list_remove = []
    field_name_dict = {fd.field_name: fd for fd in mar.config.field_defs}

    for fv in field_values:
        field_def = field_name_dict.get(fv.fieldName)
        if not field_def:
            logging.warning('Custom field %s of does not exist', fv.fieldName)
            continue

        if fv.operator == api_pb2_v1.FieldValueOperator.clear:
            fv_list_clear.append(field_def.field_id)
            continue

        # Enum fields are stored as labels
        if field_def.field_type == tracker_pb2.FieldTypes.ENUM_TYPE:
            raw_val = '%s-%s' % (fv.fieldName, fv.fieldValue)
            if fv.operator == api_pb2_v1.FieldValueOperator.remove:
                label_list_remove.append(raw_val)
            elif fv.operator == api_pb2_v1.FieldValueOperator.add:
                label_list_add.append(raw_val)
            else:  # pragma: no cover
                logging.warning('Unsupported field value operater %s',
                                fv.operator)
        else:
            new_fv = field_helpers.ParseOneFieldValue(mar.cnxn, services.user,
                                                      field_def, fv.fieldValue)
            if fv.operator == api_pb2_v1.FieldValueOperator.remove:
                fv_list_remove.append(new_fv)
            elif fv.operator == api_pb2_v1.FieldValueOperator.add:
                fv_list_add.append(new_fv)
            else:  # pragma: no cover
                logging.warning('Unsupported field value operater %s',
                                fv.operator)

    return (fv_list_add, fv_list_remove, fv_list_clear, label_list_add,
            label_list_remove)
예제 #6
0
def IngestFieldValues(cnxn, user_service, field_values, config, phases=None):
    """Ingest a list of protoc FieldValues and create protorpc FieldValues.

  Args:
    cnxn: connection to the DB.
    user_service: interface to user data storage.
    field_values: a list of protoc FieldValue used by the API.
    config: ProjectIssueConfig for this field_value's project.
    phases: a list of the issue's protorpc Phases.


  Returns: A protorpc FieldValue object.
  """
    fds_by_name = {fd.field_name.lower(): fd for fd in config.field_defs}
    phases_by_name = {phase.name: phase.phase_id for phase in phases or []}

    ingested_fvs = []
    for fv in field_values:
        fd = fds_by_name.get(fv.field_ref.field_name.lower())
        if fd:
            if not fv.value:
                logging.info('Ignoring blank field value: %r', fv)
                continue
            ingested_fv = field_helpers.ParseOneFieldValue(
                cnxn, user_service, fd, fv.value)
            if not ingested_fv:
                raise exceptions.InputException(
                    'Unparsable value for field %s' % fv.field_ref.field_name)
            if ingested_fv.user_id == field_helpers.INVALID_USER_ID:
                raise exceptions.NoSuchUserException()
            if fd.is_phase_field:
                ingested_fv.phase_id = phases_by_name.get(
                    fv.phase_ref.phase_name)
            ingested_fvs.append(ingested_fv)

    return ingested_fvs