def testProcessFormData_AcceptPhases(self): post_data = fake.PostData(name=['TestTemplate'], members_only=['on'], summary=['TLDR'], summary_must_be_edited=[''], content=['HEY WHY'], status=['Accepted'], owner=['*****@*****.**'], label=['label-One', 'label-Two'], custom_1=['NO'], custom_2=['MOOD'], components=['BackEnd'], component_required=['on'], owner_defaults_to_member=['on'], add_approvals=['on'], phase_0=['Canary'], phase_1=['Stable'], phase_2=[''], phase_3=[''], phase_4=[''], phase_5=[''], approval_3=['phase_0'], approval_4=['phase_1']) url = self.servlet.ProcessFormData(self.mr, post_data) self.assertTrue( '/templates/detail?saved=1&template=TestTemplate&' in url) self.services.template.UpdateIssueTemplateDef.assert_called_once_with( self.mr.cnxn, 47925, 12345, status='Accepted', component_required=True, phases=[ tracker_pb2.Phase(name='Canary', rank=0, phase_id=0), tracker_pb2.Phase(name='Stable', rank=1, phase_id=1) ], approval_values=[ tracker_pb2.ApprovalValue(approval_id=3, phase_id=0), tracker_pb2.ApprovalValue(approval_id=4, phase_id=1) ], name='TestTemplate', field_values=[ tracker_pb2.FieldValue(field_id=1, str_value='NO', derived=False), tracker_pb2.FieldValue(field_id=2, str_value='MOOD', derived=False) ], labels=['label-One', 'label-Two'], owner_defaults_to_member=True, admin_ids=[], content='HEY WHY', component_ids=[1], summary_must_be_edited=False, summary='TLDR', members_only=True, owner_id=333)
def testIssuesGet_GetIssue(self): """Get the requested issue.""" self.services.project.TestAddProject( 'test-project', owner_ids=[2], project_id=12345) self.SetUpComponents(12345, 1, 'API') self.SetUpFieldDefs(1, 12345, 'Field1', tracker_pb2.FieldTypes.INT_TYPE) fv = tracker_pb2.FieldValue( field_id=1, int_value=11) issue1 = fake.MakeTestIssue( project_id=12345, local_id=1, owner_id=2, reporter_id=1, status='New', summary='sum', component_ids=[1], field_values=[fv]) self.services.issue.TestAddIssue(issue1) resp = self.call_api('issues_get', self.request).json_body self.assertEqual(1, resp['id']) self.assertEqual('New', resp['status']) self.assertEqual('open', resp['state']) self.assertFalse(resp['canEdit']) self.assertTrue(resp['canComment']) self.assertEqual('*****@*****.**', resp['author']['name']) self.assertEqual('*****@*****.**', resp['owner']['name']) self.assertEqual('API', resp['components'][0]) self.assertEqual('Field1', resp['fieldValues'][0]['fieldName']) self.assertEqual('11', resp['fieldValues'][0]['fieldValue'])
def testUsersInvolvedInIssues_Normal(self): issue1 = tracker_pb2.Issue( reporter_id=111L, owner_id=222L, cc_ids=[222L, 333L]) issue2 = tracker_pb2.Issue( reporter_id=333L, owner_id=444L, derived_cc_ids=[222L, 444L]) issue2.field_values = [tracker_pb2.FieldValue(user_id=555L)] self.assertEqual( set([0L, 111L, 222L, 333L, 444L, 555L]), tracker_bizobj.UsersInvolvedInIssues([issue1, issue2]))
def testGetGrantedPerms_NothingGranted(self): config = tracker_bizobj.MakeDefaultProjectIssueConfig(789) fd = tracker_pb2.FieldDef(field_id=1) # Nothing granted config.field_defs = [fd] fv = tracker_pb2.FieldValue(field_id=1, user_id=222L) issue = tracker_pb2.Issue(field_values=[fv]) self.assertEqual( set(), tracker_bizobj.GetGrantedPerms(issue, {111L, 222L}, config))
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: logging.warning('Unsupported field value operater %s', fv.operator) else: new_fv = tracker_pb2.FieldValue( field_id=field_def.field_id) if field_def.field_type == tracker_pb2.FieldTypes.USER_TYPE: try: new_fv.user_id = services.user.LookupUserID(mar.cnxn, fv.fieldValue) except user_svc.NoSuchUserException: new_fv.user_id = 0 elif field_def.field_type == tracker_pb2.FieldTypes.STR_TYPE: new_fv.str_value = fv.fieldValue elif field_def.field_type == tracker_pb2.FieldTypes.INT_TYPE: new_fv.int_value = int(fv.fieldValue) else: logging.warning( 'Unsupported field value type %s', field_def.field_type) 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: 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)
def _ParseFieldValue(self, cnxn, project_id, user_id_dict, field_json): field = tracker_pb2.FieldValue( field_id=self.services.config.LookupFieldID( cnxn, project_id, field_json['field'])) if 'int_value' in field_json: field.int_value = field_json['int_value'] if 'str_value' in field_json: field.str_value = field_json['str_value'] if 'user_value' in field_json: field.user_value = user_id_dict.get(field_json['user_value']) return field
def testGetGrantedPerms_Normal(self): config = tracker_bizobj.MakeDefaultProjectIssueConfig(789) fd = tracker_pb2.FieldDef(field_id=1, grants_perm='Highlight') config.field_defs = [fd] fv = tracker_pb2.FieldValue(field_id=1, user_id=222L) issue = tracker_pb2.Issue(field_values=[fv]) self.assertEqual( set(), tracker_bizobj.GetGrantedPerms(issue, {111L}, config)) self.assertEqual( set(['highlight']), tracker_bizobj.GetGrantedPerms(issue, {111L, 222L}, config))
def testProcessFormData_AcceptPhases(self): self.services.template.GetTemplateByName = Mock(return_value=None) post_data = fake.PostData(name=['secondtemplate'], members_only=['on'], summary=['TLDR'], summary_must_be_edited=['on'], content=['HEY WHY'], status=['Accepted'], label=['label-One', 'label-Two'], custom_1=['NO'], component_required=['on'], owner_defaults_to_member=['no'], add_approvals=['on'], phase_0=['Canary'], phase_1=['Stable'], phase_2=[''], phase_3=[''], phase_4=[''], phase_5=[''], approval_2=['phase_0'], approval_3=['phase_1'], approval_3_required=['on']) url = self.servlet.ProcessFormData(self.mr, post_data) self.assertTrue('/adminTemplates?saved=1&ts' in url) fv = tracker_pb2.FieldValue(field_id=1, str_value='NO', derived=False) phases = [ tracker_pb2.Phase(name='Canary', rank=0, phase_id=0), tracker_pb2.Phase(name='Stable', rank=1, phase_id=1) ] approval_values = [ tracker_pb2.ApprovalValue(approval_id=2, phase_id=0), tracker_pb2.ApprovalValue( approval_id=3, status=tracker_pb2.ApprovalStatus( tracker_pb2.ApprovalStatus.NEEDS_REVIEW), phase_id=1) ] self.services.template.CreateIssueTemplateDef.assert_called_once_with( self.mr.cnxn, 47925, 'secondtemplate', 'HEY WHY', 'TLDR', True, 'Accepted', True, False, True, 0, ['label-One', 'label-Two'], [], [], [fv], phases=phases, approval_values=approval_values)
def MakeFieldValue(field_id, int_value, str_value, user_id, date_value, derived): """Make a FieldValue based on the given information.""" fv = tracker_pb2.FieldValue(field_id=field_id, derived=derived) if int_value is not None: fv.int_value = int_value elif str_value is not None: fv.str_value = str_value elif user_id is not None: fv.user_id = user_id elif date_value is not None: fv.date_value = date_value else: raise ValueError('Unexpected field value') return fv
def testMakeIssueJSON(self): config = self.services.config.GetProjectConfig(self.cnxn, 789) config.field_defs.extend([ tracker_pb2.FieldDef( field_id=1, field_name='UXReview', field_type=tracker_pb2.FieldTypes.APPROVAL_TYPE), tracker_pb2.FieldDef(field_id=2, field_name='approvalsubfield', field_type=tracker_pb2.FieldTypes.STR_TYPE, approval_id=1), tracker_pb2.FieldDef(field_id=3, field_name='phasefield', field_type=tracker_pb2.FieldTypes.INT_TYPE, is_phase_field=True), tracker_pb2.FieldDef(field_id=4, field_name='normalfield', field_type=tracker_pb2.FieldTypes.STR_TYPE) ]) self.services.config.StoreConfig(self.cnxn, config) phases = [ tracker_pb2.Phase(phase_id=1, name='Phase1', rank=1), tracker_pb2.Phase(phase_id=2, name='Phase2', rank=2) ] avs = [ tracker_pb2.ApprovalValue( approval_id=1, status=tracker_pb2.ApprovalStatus.APPROVED, setter_id=111, set_on=7, approver_ids=[333, 444], phase_id=1) ] fvs = [ tracker_pb2.FieldValue(field_id=2, str_value='two'), tracker_pb2.FieldValue(field_id=3, int_value=3, phase_id=2), tracker_pb2.FieldValue(field_id=4, str_value='four') ] labels = ['test', 'Type-FLT-Launch'] issue = fake.MakeTestIssue(self.project.project_id, 1, 'summary', 'Open', 111, labels=labels, issue_id=78901, reporter_id=222, opened_timestamp=1, closed_timestamp=2, modified_timestamp=3, project_name='project', field_values=fvs, phases=phases, approval_values=avs) email_dict = { 111: '*****@*****.**', 222: '*****@*****.**', 333: '*****@*****.**', 444: '*****@*****.**' } comment_list = [ tracker_pb2.IssueComment(content='simple'), tracker_pb2.IssueComment(content='issue desc', is_description=True) ] starrer_id_list = [222, 333] issue_JSON = self.jsonfeed._MakeIssueJSON(self.mr, issue, email_dict, comment_list, starrer_id_list) expected_JSON = { 'local_id': 1, 'reporter': '*****@*****.**', 'summary': 'summary', 'owner': '*****@*****.**', 'status': 'Open', 'cc': [], 'labels': labels, 'phases': [{ 'id': 1, 'name': 'Phase1', 'rank': 1 }, { 'id': 2, 'name': 'Phase2', 'rank': 2 }], 'fields': [{ 'field': 'approvalsubfield', 'phase': None, 'approval': 'UXReview', 'str_value': 'two' }, { 'field': 'phasefield', 'phase': 'Phase2', 'int_value': 3 }, { 'field': 'normalfield', 'phase': None, 'str_value': 'four' }], 'approvals': [{ 'approval': 'UXReview', 'status': 'APPROVED', 'setter': '*****@*****.**', 'set_on': 7, 'approvers': ['*****@*****.**', '*****@*****.**'], 'phase': 'Phase1' }], 'starrers': ['*****@*****.**', '*****@*****.**'], 'comments': [ { 'content': 'simple', 'timestamp': None, 'amendments': [], 'commenter': None, 'attachments': [], 'description_num': None }, { 'content': 'issue desc', 'timestamp': None, 'amendments': [], 'commenter': None, 'attachments': [], 'description_num': '1' }, ], 'opened': 1, 'modified': 3, 'closed': 2, } self.assertEqual(expected_JSON, issue_JSON)