def MakeAmendment(field, new_value, added_ids, removed_ids, custom_field_name=None, old_value=None): """Utility function to populate an Amendment PB. Args: field: enum for the field being updated. new_value: new string value of that field. added_ids: list of user IDs being added. removed_ids: list of user IDs being removed. custom_field_name: optional name of a custom field. old_value: old string value of that field. Returns: An instance of Amendment. """ amendment = tracker_pb2.Amendment() amendment.field = field amendment.newvalue = new_value amendment.added_user_ids.extend(added_ids) amendment.removed_user_ids.extend(removed_ids) if old_value is not None: amendment.oldvalue = old_value if custom_field_name is not None: amendment.custom_field_name = custom_field_name return amendment
def testConvertAmendments(self): """Test convert_amendments.""" self.services.user.TestAddUser('*****@*****.**', 222) mar = mock.Mock() mar.cnxn = None issue = mock.Mock() issue.project_name = 'test-project' amendment_summary = tracker_pb2.Amendment( field=tracker_pb2.FieldID.SUMMARY, newvalue='new summary') amendment_status = tracker_pb2.Amendment( field=tracker_pb2.FieldID.STATUS, newvalue='new status') amendment_owner = tracker_pb2.Amendment( field=tracker_pb2.FieldID.OWNER, added_user_ids=[111]) amendment_labels = tracker_pb2.Amendment( field=tracker_pb2.FieldID.LABELS, newvalue='label1 -label2') amendment_cc_add = tracker_pb2.Amendment( field=tracker_pb2.FieldID.CC, added_user_ids=[111]) amendment_cc_remove = tracker_pb2.Amendment( field=tracker_pb2.FieldID.CC, removed_user_ids=[222]) amendment_blockedon = tracker_pb2.Amendment( field=tracker_pb2.FieldID.BLOCKEDON, newvalue='1') amendment_blocking = tracker_pb2.Amendment( field=tracker_pb2.FieldID.BLOCKING, newvalue='other:2 -3') amendment_mergedinto = tracker_pb2.Amendment( field=tracker_pb2.FieldID.MERGEDINTO, newvalue='4') amendments = [ amendment_summary, amendment_status, amendment_owner, amendment_labels, amendment_cc_add, amendment_cc_remove, amendment_blockedon, amendment_blocking, amendment_mergedinto] result = api_pb2_v1_helpers.convert_amendments( issue, amendments, mar, self.services) self.assertEquals(amendment_summary.newvalue, result.summary) self.assertEquals(amendment_status.newvalue, result.status) self.assertEquals('*****@*****.**', result.owner) self.assertEquals(['label1', '-label2'], result.labels) self.assertEquals(['*****@*****.**', '*****@*****.**'], result.cc) self.assertEquals(['test-project:1'], result.blockedOn) self.assertEquals(['other:2', '-test-project:3'], result.blocking) self.assertEquals(amendment_mergedinto.newvalue, result.mergedInto)
def testUsersInvolvedInCommentList(self): self.assertEqual(set(), tracker_bizobj.UsersInvolvedInCommentList([])) c1 = tracker_pb2.IssueComment() c1.user_id = 111L c1.amendments.append(tracker_pb2.Amendment(newvalue='foo')) c2 = tracker_pb2.IssueComment() c2.user_id = 111L c2.amendments.append(tracker_pb2.Amendment( added_user_ids=[222L], removed_user_ids=[333L])) self.assertEqual({111L}, tracker_bizobj.UsersInvolvedInCommentList([c1])) self.assertEqual({111L, 222L, 333L}, tracker_bizobj.UsersInvolvedInCommentList([c2])) self.assertEqual({111L, 222L, 333L}, tracker_bizobj.UsersInvolvedInCommentList([c1, c2]))
def testUsersInvolvedInComment(self): comment = tracker_pb2.IssueComment() self.assertEqual({0}, tracker_bizobj.UsersInvolvedInComment(comment)) comment.user_id = 111L self.assertEqual( {111L}, tracker_bizobj.UsersInvolvedInComment(comment)) amendment = tracker_pb2.Amendment(newvalue='foo') comment.amendments.append(amendment) self.assertEqual( {111L}, tracker_bizobj.UsersInvolvedInComment(comment)) amendment.added_user_ids.append(222L) amendment.removed_user_ids.append(333L) self.assertEqual({111L, 222L, 333L}, tracker_bizobj.UsersInvolvedInComment(comment))
def _ParseAmendment(self, amendment_json, user_id_dict, _event_log): amendment = tracker_pb2.Amendment( field=tracker_pb2.FieldID(amendment_json['field'])) if 'new_value' in amendment_json: amendment.newvalue = amendment_json['new_value'] if 'custom_field_name' in amendment_json: amendment.custom_field_name = amendment_json['custom_field_name'] if 'added_users' in amendment_json: amendment.added_user_ids.extend([ user_id_dict[email] for email in amendment_json['added_users'] ]) if 'removed_users' in amendment_json: amendment.removed_user_ids.extend([ user_id_dict[email] for email in amendment_json['removed_users'] ]) return amendment