def testParseFieldValues_Empty(self): field_val_strs = {} field_values = field_helpers.ParseFieldValues(self.mr.cnxn, self.services.user, field_val_strs, self.config) self.assertEqual([], field_values)
def testParseFieldValues_EmptyPhases(self): field_val_strs = {126: ['70']} phase_field_val_strs = {} fd_phase = tracker_bizobj.MakeFieldDef( 126, 789, 'Target', tracker_pb2.FieldTypes.INT_TYPE, None, '', False, False, False, None, None, '', False, '', '', tracker_pb2.NotifyTriggers.NEVER, 'no_action', 'milestone target', False, is_phase_field=True) self.config.field_defs.extend([fd_phase]) field_values = field_helpers.ParseFieldValues(self.mr.cnxn, self.services.user, field_val_strs, phase_field_val_strs, self.config) self.assertEqual([], field_values)
def ProcessFormData(self, mr, post_data): """Process the issue entry form. Args: mr: commonly used info parsed from the request. post_data: The post_data dict for the current request. Returns: String URL to redirect the user to after processing. """ config = self.services.config.GetProjectConfig(mr.cnxn, mr.project_id) parsed = tracker_helpers.ParseIssueRequest( mr.cnxn, post_data, self.services, mr.errors, mr.project_name) bounce_labels = parsed.labels[:] bounce_fields = tracker_views.MakeBounceFieldValueViews( parsed.fields.vals, config) field_helpers.ShiftEnumFieldsIntoLabels( parsed.labels, parsed.labels_remove, parsed.fields.vals, parsed.fields.vals_remove, config) field_values = field_helpers.ParseFieldValues( mr.cnxn, self.services.user, parsed.fields.vals, config) labels = _DiscardUnusedTemplateLabelPrefixes(parsed.labels) component_ids = tracker_helpers.LookupComponentIDs( parsed.components.paths, config, mr.errors) reporter_id = mr.auth.user_id self.CheckCaptcha(mr, post_data) if not parsed.summary.strip() or parsed.summary == PLACEHOLDER_SUMMARY: mr.errors.summary = 'Summary is required' if not parsed.comment.strip(): mr.errors.comment = 'A description is required' if len(parsed.comment) > tracker_constants.MAX_COMMENT_CHARS: mr.errors.comment = 'Comment is too long' if len(parsed.summary) > tracker_constants.MAX_SUMMARY_CHARS: mr.errors.summary = 'Summary is too long' if _MatchesTemplate(parsed.comment, config): mr.errors.comment = 'Template must be filled out.' if parsed.users.owner_id is None: mr.errors.owner = 'Invalid owner username' else: valid, msg = tracker_helpers.IsValidIssueOwner( mr.cnxn, mr.project, parsed.users.owner_id, self.services) if not valid: mr.errors.owner = msg if None in parsed.users.cc_ids: mr.errors.cc = 'Invalid Cc username' field_helpers.ValidateCustomFields( mr, self.services, field_values, config, mr.errors) new_local_id = None if not mr.errors.AnyErrors(): try: if parsed.attachments: new_bytes_used = tracker_helpers.ComputeNewQuotaBytesUsed( mr.project, parsed.attachments) self.services.project.UpdateProject( mr.cnxn, mr.project.project_id, attachment_bytes_used=new_bytes_used) template_content = '' for wkp in config.templates: if wkp.name == parsed.template_name: template_content = wkp.content marked_comment = _MarkupDescriptionOnInput( parsed.comment, template_content) has_star = 'star' in post_data and post_data['star'] == '1' new_local_id = self.services.issue.CreateIssue( mr.cnxn, self.services, mr.project_id, parsed.summary, parsed.status, parsed.users.owner_id, parsed.users.cc_ids, labels, field_values, component_ids, reporter_id, marked_comment, blocked_on=parsed.blocked_on.iids, blocking=parsed.blocking.iids, attachments=parsed.attachments) self.services.project.UpdateRecentActivity( mr.cnxn, mr.project.project_id) issue = self.services.issue.GetIssueByLocalID( mr.cnxn, mr.project_id, new_local_id) if has_star: self.services.issue_star.SetStar( mr.cnxn, self.services, config, issue.issue_id, reporter_id, True) except tracker_helpers.OverAttachmentQuota: mr.errors.attachments = 'Project attachment quota exceeded.' counts = {actionlimit.ISSUE_COMMENT: 1, actionlimit.ISSUE_ATTACHMENT: len(parsed.attachments)} self.CountRateLimitedActions(mr, counts) if mr.errors.AnyErrors(): component_required = False for wkp in config.templates: if wkp.name == parsed.template_name: component_required = wkp.component_required self.PleaseCorrect( mr, initial_summary=parsed.summary, initial_status=parsed.status, initial_owner=parsed.users.owner_username, initial_cc=', '.join(parsed.users.cc_usernames), initial_components=', '.join(parsed.components.paths), initial_comment=parsed.comment, labels=bounce_labels, fields=bounce_fields, initial_blocked_on=parsed.blocked_on.entered_str, initial_blocking=parsed.blocking.entered_str, component_required=ezt.boolean(component_required)) return # Initial description is comment 0. notify.PrepareAndSendIssueChangeNotification( issue.issue_id, mr.request.host, reporter_id, 0) notify.PrepareAndSendIssueBlockingNotification( issue.issue_id, mr.request.host, parsed.blocked_on.iids, reporter_id) # format a redirect url return framework_helpers.FormatAbsoluteURL( mr, urls.ISSUE_DETAIL, id=new_local_id)
def testParseFieldValues_Normal(self): fd_int = tracker_bizobj.MakeFieldDef(123, 789, 'CPU', tracker_pb2.FieldTypes.INT_TYPE, None, '', False, False, False, None, None, '', False, '', '', tracker_pb2.NotifyTriggers.NEVER, 'no_action', 'doc', False) fd_date = tracker_bizobj.MakeFieldDef(124, 789, 'Deadline', tracker_pb2.FieldTypes.DATE_TYPE, None, '', False, False, False, None, None, '', False, '', '', tracker_pb2.NotifyTriggers.NEVER, 'no_action', 'doc', False) fd_url = tracker_bizobj.MakeFieldDef(125, 789, 'Design Doc', tracker_pb2.FieldTypes.URL_TYPE, None, '', False, False, False, None, None, '', False, '', '', tracker_pb2.NotifyTriggers.NEVER, 'no_action', 'doc', False) fd_phase = tracker_bizobj.MakeFieldDef( 126, 789, 'Target', tracker_pb2.FieldTypes.INT_TYPE, None, '', False, False, False, None, None, '', False, '', '', tracker_pb2.NotifyTriggers.NEVER, 'no_action', 'milestone target', False, is_phase_field=True) self.config.field_defs.extend([fd_int, fd_date, fd_url, fd_phase]) field_val_strs = { 123: ['80386', '68040'], 124: ['2009-02-13'], 125: ['www.google.com'], } phase_field_val_strs = { 126: { 'beta': ['89'], 'stable': ['70'], 'missing': ['234'], } } field_values = field_helpers.ParseFieldValues(self.mr.cnxn, self.services.user, field_val_strs, phase_field_val_strs, self.config, phase_ids_by_name={ 'stable': [30, 40], 'beta': [88] }) fv1 = tracker_bizobj.MakeFieldValue(123, 80386, None, None, None, None, False) fv2 = tracker_bizobj.MakeFieldValue(123, 68040, None, None, None, None, False) fv3 = tracker_bizobj.MakeFieldValue(124, None, None, None, 1234483200, None, False) fv4 = tracker_bizobj.MakeFieldValue(125, None, None, None, None, 'http://www.google.com', False) fv5 = tracker_bizobj.MakeFieldValue(126, 89, None, None, None, None, False, phase_id=88) fv6 = tracker_bizobj.MakeFieldValue(126, 70, None, None, None, None, False, phase_id=30) fv7 = tracker_bizobj.MakeFieldValue(126, 70, None, None, None, None, False, phase_id=40) self.assertEqual([fv1, fv2, fv3, fv4, fv5, fv6, fv7], field_values)