def testIndexOrLexicalList_ApprovalApprover(self): art = art = fake.MakeTestIssue(789, 1, 'sum 2', 'New', 111) art.labels = ['samename-approver-value1'] art.approval_values = [ tracker_pb2.ApprovalValue(approval_id=4, approver_ids=[333]) ] all_field_defs = [ tracker_bizobj.MakeFieldDef(4, 788, 'samename', tracker_pb2.FieldTypes.APPROVAL_TYPE, None, None, False, False, False, None, None, None, False, None, None, None, None, 'cow spots', False) ] users_by_id = { 333: framework_views.StuffUserView(333, '*****@*****.**', True) } accessor = sorting._IndexOrLexicalList([], all_field_defs, 'samename-approver', users_by_id) self.assertEqual(['*****@*****.**', 'value1'], accessor(art)) neg_accessor = MakeDescending(accessor) self.assertEqual([ sorting.DescendingValue('value1'), sorting.DescendingValue('*****@*****.**') ], neg_accessor(art))
def testIndexOrLexical(self): well_known_values = ['x-a', 'x-b', 'x-c', 'x-d'] art = 'this is a fake artifact' # Case 1: accessor generates no values. base_accessor = lambda art: None accessor = sorting._IndexOrLexical(well_known_values, base_accessor) self.assertEqual(sorting.MAX_STRING, accessor(art)) neg_accessor = MakeDescending(accessor) self.assertEqual(sorting.DescendingValue(sorting.MAX_STRING), neg_accessor(art)) # Case 2: accessor generates a value, but it is an empty value. base_accessor = lambda art: '' accessor = sorting._IndexOrLexical(well_known_values, base_accessor) self.assertEqual(sorting.MAX_STRING, accessor(art)) neg_accessor = MakeDescending(accessor) self.assertEqual(sorting.DescendingValue(sorting.MAX_STRING), neg_accessor(art)) # Case 3: A single well-known value base_accessor = lambda art: 'x-c' accessor = sorting._IndexOrLexical(well_known_values, base_accessor) self.assertEqual(2, accessor(art)) neg_accessor = MakeDescending(accessor) self.assertEqual(-2, neg_accessor(art)) # Case 4: A single odd-ball value base_accessor = lambda art: 'x-zzz' accessor = sorting._IndexOrLexical(well_known_values, base_accessor) self.assertEqual('x-zzz', accessor(art)) neg_accessor = MakeDescending(accessor) self.assertEqual(sorting.DescendingValue('x-zzz'), neg_accessor(art))
def testIndexOrLexicalList_ApprovalStatus(self): art = fake.MakeTestIssue(789, 1, 'sum 2', 'New', 111) art.labels = ['samename-value1'] art.approval_values = [tracker_pb2.ApprovalValue(approval_id=4)] all_field_defs = [ tracker_bizobj.MakeFieldDef(3, 789, 'samename', tracker_pb2.FieldTypes.INT_TYPE, None, None, False, False, False, None, None, None, False, None, None, None, None, 'cow spots', False), tracker_bizobj.MakeFieldDef(4, 788, 'samename', tracker_pb2.FieldTypes.APPROVAL_TYPE, None, None, False, False, False, None, None, None, False, None, None, None, None, 'cow spots', False) ] accessor = sorting._IndexOrLexicalList([], all_field_defs, 'samename', {}) self.assertEqual([0, 'value1'], accessor(art)) neg_accessor = MakeDescending(accessor) self.assertEqual( [sorting.DescendingValue('value1'), sorting.DescendingValue(0)], neg_accessor(art))
def testIndexOrLexicalList(self): well_known_values = ['Pri-High', 'Pri-Med', 'Pri-Low'] art = fake.MakeTestIssue(789, 1, 'sum 1', 'New', 111L, merged_into=200001) # Case 1: accessor generates no values. accessor = sorting._IndexOrLexicalList(well_known_values, [], 'pri', {}) self.assertEqual(sorting.MAX_STRING, accessor(art)) neg_accessor = MakeDescending(accessor) self.assertEqual(sorting.MAX_STRING, neg_accessor(art)) # Case 2: A single well-known value art.labels = ['Pri-Med'] accessor = sorting._IndexOrLexicalList(well_known_values, [], 'pri', {}) self.assertEqual([1], accessor(art)) neg_accessor = MakeDescending(accessor) self.assertEqual([-1], neg_accessor(art)) # Case 3: Multiple well-known and odd-ball values art.labels = ['Pri-zzz', 'Pri-Med', 'yyy', 'Pri-High'] accessor = sorting._IndexOrLexicalList(well_known_values, [], 'pri', {}) self.assertEqual([0, 1, 'zzz'], accessor(art)) neg_accessor = MakeDescending(accessor) self.assertEqual([sorting.DescendingValue('zzz'), -1, 0], neg_accessor(art))
def testIndexOrLexicalList_CustomFields(self): art = fake.MakeTestIssue(789, 1, 'sum 2', 'New', 111) art.labels = ['samename-value1'] art.field_values = [ tracker_bizobj.MakeFieldValue(3, 6078, None, None, None, None, False) ] all_field_defs = [ tracker_bizobj.MakeFieldDef(3, 789, 'samename', tracker_pb2.FieldTypes.INT_TYPE, None, None, False, False, False, None, None, None, False, None, None, None, None, 'cow spots', False), tracker_bizobj.MakeFieldDef(4, 788, 'samename', tracker_pb2.FieldTypes.APPROVAL_TYPE, None, None, False, False, False, None, None, None, False, None, None, None, None, 'cow spots', False), tracker_bizobj.MakeFieldDef(4, 788, 'notsamename', tracker_pb2.FieldTypes.APPROVAL_TYPE, None, None, False, False, False, None, None, None, False, None, None, None, None, 'should get filtered out', False) ] accessor = sorting._IndexOrLexicalList([], all_field_defs, 'samename', {}) self.assertEqual([6078, 'value1'], accessor(art)) neg_accessor = MakeDescending(accessor) self.assertEqual([sorting.DescendingValue('value1'), -6078], neg_accessor(art))
def testIndexOrLexicalList(self): well_known_values = ['Pri-High', 'Pri-Med', 'Pri-Low'] art = fake.MakeTestIssue(789, 1, 'sum 1', 'New', 111, merged_into=200001) # Case 1: accessor generates no values. accessor = sorting._IndexOrLexicalList(well_known_values, [], 'pri', {}) self.assertEqual(sorting.MAX_STRING, accessor(art)) neg_accessor = MakeDescending(accessor) self.assertEqual(sorting.MAX_STRING, neg_accessor(art)) # Case 2: A single well-known value art.labels = ['Pri-Med'] accessor = sorting._IndexOrLexicalList(well_known_values, [], 'pri', {}) self.assertEqual([1], accessor(art)) neg_accessor = MakeDescending(accessor) self.assertEqual([-1], neg_accessor(art)) # Case 3: Multiple well-known and odd-ball values art.labels = ['Pri-zzz', 'Pri-Med', 'yyy', 'Pri-High'] accessor = sorting._IndexOrLexicalList(well_known_values, [], 'pri', {}) self.assertEqual([0, 1, 'zzz'], accessor(art)) neg_accessor = MakeDescending(accessor) self.assertEqual([sorting.DescendingValue('zzz'), -1, 0], neg_accessor(art)) # Case 4: Multi-part prefix. well_known_values.extend(['X-Y-Header', 'X-Y-Footer']) art.labels = ['X-Y-Footer', 'X-Y-Zone', 'X-Y-Header', 'X-Y-Area'] accessor = sorting._IndexOrLexicalList(well_known_values, [], 'x-y', {}) self.assertEqual([3, 4, 'area', 'zone'], accessor(art)) neg_accessor = MakeDescending(accessor) self.assertEqual([ sorting.DescendingValue('zone'), sorting.DescendingValue('area'), -4, -3 ], neg_accessor(art))
def testIndexOrLexicalList_PhaseCustomFields(self): art = fake.MakeTestIssue(789, 1, 'sum 2', 'New', 111) art.labels = ['summer.goats-value1'] art.field_values = [ tracker_bizobj.MakeFieldValue(3, 33, None, None, None, None, False, phase_id=77), tracker_bizobj.MakeFieldValue(3, 34, None, None, None, None, False, phase_id=77), tracker_bizobj.MakeFieldValue(3, 1000, None, None, None, None, False, phase_id=78) ] art.phases = [ tracker_pb2.Phase(phase_id=77, name='summer'), tracker_pb2.Phase(phase_id=78, name='winter') ] all_field_defs = [ tracker_bizobj.MakeFieldDef(3, 789, 'goats', tracker_pb2.FieldTypes.INT_TYPE, None, None, False, False, True, None, None, None, False, None, None, None, None, 'goats love mineral', False, is_phase_field=True), tracker_bizobj.MakeFieldDef(4, 788, 'boo', tracker_pb2.FieldTypes.APPROVAL_TYPE, None, None, False, False, False, None, None, None, False, None, None, None, None, 'ahh', False), ] accessor = sorting._IndexOrLexicalList([], all_field_defs, 'summer.goats', {}) self.assertEqual([33, 34, 'value1'], accessor(art)) neg_accessor = MakeDescending(accessor) self.assertEqual([sorting.DescendingValue('value1'), -34, -33], neg_accessor(art))