def testMakeHotlist_Everything(self): ts = 20011111111111 hotlist = features_pb2.MakeHotlist('summer-issues', [(1000, 1, 444L, ts, ''), (1001, 2, 333L, ts, ''), (1009, None, None, ts, '')], description='desc') self.assertEqual('summer-issues', hotlist.name) self.assertEqual([ features_pb2.MakeHotlistItem( 1000, rank=1, adder_id=444L, date_added=ts, note=''), features_pb2.MakeHotlistItem( 1001, rank=2, adder_id=333L, date_added=ts, note=''), features_pb2.MakeHotlistItem(1009, date_added=ts, note=''), ], hotlist.items) self.assertEqual('desc', hotlist.description)
def setUp(self): self.local_ids = [1, 2, 3, 4, 5] self.issues = [fake.MakeTestIssue(1000, local_id, '', 'New', 111) for local_id in self.local_ids] self.hotlistitems = [features_pb2.MakeHotlistItem( issue.issue_id, rank=rank*10, adder_id=111, date_added=3) for rank, issue in enumerate(self.issues)] self.iids = [item.issue_id for item in self.hotlistitems]
def UpdateHotlistItems(self, cnxn, hotlist_id, remove, added_tuples, commit=True): """Updates a hotlist's list of hotlistissues. Args: cnxn: connection to SQL database. hotlist_id: the ID of the hotlist to update remove: a list of issue_ids for be removed added_tuples: a list of (issue_id, user_id, ts, note) for issues to be added """ hotlist = self.GetHotlist(cnxn, hotlist_id, use_cache=False) if not hotlist: raise NoSuchHotlistException() # adding new Hotlistissues, ignoring pairs where issue_id is already in # hotlist's iid_rank_pairs current_issues_ids = {item.issue_id for item in hotlist.items} self.hotlist2issue_tbl.Delete(cnxn, hotlist_id=hotlist_id, issue_id=[ remove_id for remove_id in remove if remove_id in current_issues_ids ], commit=False) if hotlist.items: items_sorted = sorted(hotlist.items, key=lambda item: item.rank) rank_base = items_sorted[-1].rank + 10 else: rank_base = 1L insert_rows = [(hotlist_id, issue_id, rank * 10 + rank_base, user_id, ts, note) for (rank, (issue_id, user_id, ts, note)) in enumerate(added_tuples) if issue_id not in current_issues_ids] self.hotlist2issue_tbl.InsertRows(cnxn, cols=HOTLIST2ISSUE_COLS, row_values=insert_rows, commit=commit) self.hotlist_2lc.InvalidateKeys(cnxn, [hotlist_id]) # removing an issue that was never in the hotlist would not cause any # problems. items = [item for item in hotlist.items if item.issue_id not in remove] new_hotlist_items = [ features_pb2.MakeHotlistItem(issue_id, rank, user_id, ts, note) for (_hid, issue_id, rank, user_id, ts, note) in insert_rows ] items.extend(new_hotlist_items) hotlist.items = items logging.info(hotlist.items)
def testMakeHotlistItem(self): ts = 20011111111111 item_1 = features_pb2.MakeHotlistItem(1000, rank=1, adder_id=111L, date_added=ts, note='short note') self.assertEqual(1000, item_1.issue_id) self.assertEqual(1, item_1.rank) self.assertEqual(111L, item_1.adder_id) self.assertEqual(ts, item_1.date_added) self.assertEqual('short note', item_1.note) item_2 = features_pb2.MakeHotlistItem(1001) self.assertEqual(1001, item_2.issue_id) self.assertEqual(None, item_2.rank) self.assertEqual(None, item_2.adder_id) self.assertEqual('', item_2.note) self.assertIsNotNone(item_2.date_added)
def testMakeHotlistItem(self): ts = 20011111111111 item_1 = features_pb2.MakeHotlistItem(1000, rank=1, adder_id=111, date_added=ts, note='short note') self.assertEqual(1000, item_1.issue_id) self.assertEqual(1, item_1.rank) self.assertEqual(111, item_1.adder_id) self.assertEqual(ts, item_1.date_added) self.assertEqual('short note', item_1.note) item_2 = features_pb2.MakeHotlistItem(1001) self.assertEqual(1001, item_2.issue_id) self.assertEqual(None, item_2.rank) self.assertEqual(None, item_2.adder_id) self.assertEqual('', item_2.note) self.assertEqual(features_pb2.ADDED_TS_FEATURE_LAUNCH_TS, item_2.date_added)
def setUp(self): self.services = service_manager.Services( issue=fake.IssueService(), features=fake.FeaturesService(), issue_star=fake.AbstractStarService(), config=fake.ConfigService(), project=fake.ProjectService(), user=fake.UserService(), cache_manager=fake.CacheManager()) self.services.project.TestAddProject('ProjectName', project_id=1) self.services.user.TestAddUser('*****@*****.**', 111) self.services.user.TestAddUser('*****@*****.**', 222) issue1 = fake.MakeTestIssue(1, 1, 'issue_summary', 'New', 111, project_name='ProjectName') self.services.issue.TestAddIssue(issue1) issue2 = fake.MakeTestIssue(1, 2, 'issue_summary2', 'New', 111, project_name='ProjectName') self.services.issue.TestAddIssue(issue2) issue3 = fake.MakeTestIssue(1, 3, 'issue_summary3', 'New', 222, project_name='ProjectName') self.services.issue.TestAddIssue(issue3) issues = [issue1, issue2, issue3] hotlist_items = [(issue.issue_id, rank, 222, None, '') for rank, issue in enumerate(issues)] self.hotlist_items_list = [ features_pb2.MakeHotlistItem(issue_id, rank=rank, adder_id=adder_id, date_added=date, note=note) for (issue_id, rank, adder_id, date, note) in hotlist_items ] self.test_hotlist = self.services.features.TestAddHotlist( 'hotlist', hotlist_id=123, owner_ids=[111], hotlist_item_fields=hotlist_items) sorting.InitializeArtValues(self.services) self.mr = None
def _DeserializeHotlists(self, hotlist_rows, issue_rows, role_rows): """Convert database rows into a dictionary of Hotlist PB keyed by ID. Args: hotlist_rows: a list of hotlist rows from HOTLIST_TABLE_NAME. issue_rows: a list of issue rows from HOTLIST2ISSUE_TABLE_NAME, ordered by rank DESC, issue_id. role_rows: a list of role rows from HOTLIST2USER_TABLE_NAME Returns: a dict mapping hotlist_id to hotlist PB""" hotlist_dict = {} for hotlist_row in hotlist_rows: (hotlist_id, hotlist_name, summary, description, is_private, default_col_spec) = hotlist_row hotlist = features_pb2.MakeHotlist( hotlist_name, hotlist_id=hotlist_id, summary=summary, description=description, is_private=bool(is_private), default_col_spec=default_col_spec) hotlist_dict[hotlist_id] = hotlist for (hotlist_id, issue_id, rank, adder_id, added, note) in issue_rows: hotlist = hotlist_dict.get(hotlist_id) if hotlist: hotlist.items.append( features_pb2.MakeHotlistItem(issue_id=issue_id, rank=rank, adder_id=adder_id, date_added=added, note=note)) else: logging.warn('hotlist %d not found', hotlist_id) for (hotlist_id, user_id, role_name) in role_rows: hotlist = hotlist_dict.get(hotlist_id) if not hotlist: logging.warn('hotlist %d not found', hotlist_id) elif role_name == 'owner': hotlist.owner_ids.append(user_id) elif role_name == 'editor': hotlist.editor_ids.append(user_id) elif role_name == 'follower': hotlist.follower_ids.append(user_id) else: logging.info('unknown role name %s', role_name) return hotlist_dict
self.services.issue.TestAddIssue(issue2) issue3 = fake.MakeTestIssue(001, 3, 'issue_summary3', 'New', 222L, project_name='ProjectName') self.services.issue.TestAddIssue(issue3) issues = [issue1, issue2, issue3] hotlist_items = [(issue.issue_id, rank, 222L, None, '') for rank, issue in enumerate(issues)] self.hotlist_items_list = [ features_pb2.MakeHotlistItem(issue_id, rank=rank, adder_id=adder_id, date_added=date, note=note) for (issue_id, rank, adder_id, date, note) in hotlist_items ] self.test_hotlist = self.services.features.TestAddHotlist( 'hotlist', hotlist_id=123, owner_ids=[111L], hotlist_item_fields=hotlist_items) sorting.InitializeArtValues(self.services) self.mr = None def setUpCreateHotlistTableDataTestMR(self, **kwargs): self.mr = testing_helpers.MakeMonorailRequest(**kwargs) self.services.user.TestAddUser('*****@*****.**', 148L)
from proto import features_pb2 from features import features_bizobj from testing import fake class FeaturesBizobjTest(unittest.TestCase): def setUp(self): self.local_ids = [1L, 2L, 3L, 4L, 5L] self.issues = [ fake.MakeTestIssue(1000, local_id, '', 'New', 111L) for local_id in self.local_ids ] self.hotlistitems = [ features_pb2.MakeHotlistItem(issue.issue_id, rank=rank * 10, adder_id=111L, date_added=3) for rank, issue in enumerate(self.issues) ] self.iids = [item.issue_id for item in self.hotlistitems] def testIssueIsInHotlist(self): hotlist = features_pb2.Hotlist(items=self.hotlistitems) for issue in self.issues: self.assertTrue( features_bizobj.IssueIsInHotlist(hotlist, issue.issue_id)) self.assertFalse( features_bizobj.IssueIsInHotlist( hotlist, fake.MakeTestIssue(1000, 9L, '', 'New', 111L)))