def testInitOverride(self): owner = '*****@*****.**' status = 'Assigned' issue = gdata_lib.Issue(owner=owner, status=status) self.assertEquals(owner, issue.owner) self.assertEquals(status, issue.status)
def testGetTrackerIssueById(self): mocked_itclient = self.mox.CreateMock( gd_ph_client.ProjectHostingClient) tcomm = gdata_lib.TrackerComm() tcomm.it_client = mocked_itclient tcomm.project_name = 'TheProject' self.mox.StubOutClassWithMocks(gd_ph_client, 'Query') self.mox.StubOutClassWithMocks(gdata_lib, 'Issue') self.mox.StubOutWithMock(gdata_lib.Issue, 'InitFromTracker') issue_id = 12345 feed = cros_test_lib.EasyAttr(entry=['hi', 'there']) # Replay script mocked_query = gd_ph_client.Query(issue_id=str(issue_id)) mocked_itclient.get_issues('TheProject', query=mocked_query).AndReturn(feed) mocked_issue = gdata_lib.Issue() mocked_issue.InitFromTracker(feed.entry[0], 'TheProject') self.mox.ReplayAll() # Verify issue = tcomm.GetTrackerIssueById(issue_id) self.mox.VerifyAll() self.assertEquals(mocked_issue, issue)
def testGetTrackerIssuesByText(self): author = 'TheAuthor' project = 'TheProject' text = "find me" # Set up the fake tracker issue. tissue_id = 1 tissue_labels = ['auto-filed'] tissue_owner = '*****@*****.**' tissue_status = 'Available' tissue_content = 'find me in body' tissue_title = 'find me in title' tissue = createTrackerIssue(tid=tissue_id, labels=tissue_labels, owner=tissue_owner, status=tissue_status, content=tissue_content, title=tissue_title) issue = gdata_lib.Issue(id=tissue_id, labels=tissue_labels, owner=tissue_owner, status=tissue_status, title=tissue_title, summary=tissue_content) # This will get called as part of Issue.InitFromTracker. self.mox.StubOutWithMock(gdata_lib.Issue, 'GetTrackerIssueComments') mocked_itclient = self.mox.CreateMock( gd_ph_client.ProjectHostingClient) tcomm = gdata_lib.TrackerComm() tcomm.author = author tcomm.it_client = mocked_itclient tcomm.project_name = project # We expect a Query instance to be passed into get_issues. # pylint: disable=E1120 self.mox.StubOutClassWithMocks(gd_ph_client, 'Query') mocked_query = gd_ph_client.Query(text_query='%s is:open' % text) feed = cros_test_lib.EasyAttr(entry=[tissue]) mocked_itclient.get_issues(project, query=mocked_query).AndReturn(feed) gdata_lib.Issue.GetTrackerIssueComments(1, project).AndReturn([]) self.mox.ReplayAll() issues = tcomm.GetTrackerIssuesByText(text) self.assertEquals(issues, [issue])
def _GenIssueForRow(self, row): """Generate an Issue object for |row| if applicable""" # Row needs an issue if it "needs upgrade" on any platform. statuses = {} needs_issue = False for arch in ARCHES: state = self._GetRowValue(row, utable.UpgradeTable.COL_STATE, arch) statuses[arch] = state if state in self.UPGRADE_STATES: needs_issue = True if not needs_issue: return None pkg = row[COL_PACKAGE] team = self._ReduceTeamName(row[COL_TEAM]) if not team: oper.Error('Unable to create Issue for package "%s" because no ' 'team value is specified.' % pkg) raise SyncError() team_label = self.VALID_TEAMS[team] labels = ['Type-Task', 'Area-LinuxUserSpace', 'Pri-2', 'Team-%s' % team_label, ] owner = self._ReduceOwnerName(row[COL_OWNER]) status = 'Untriaged' if owner: owner = owner + '@chromium.org' status = 'Available' elif self.default_owner: owner = self.default_owner + '@chromium.org.' else: owner = None # Rather than '' title = '%s package needs upgrade from upstream Portage' % pkg lines = ['The %s package can be upgraded from upstream Portage' % pkg, '', 'At this moment the status on each arch is as follows:', ] for arch in sorted(statuses): arch_status = statuses[arch] if arch_status: # Get all versions for this arch right now. curr_ver_col = utable.UpgradeTable.COL_CURRENT_VER curr_ver = self._GetRowValue(row, curr_ver_col, arch) stable_upst_ver_col = utable.UpgradeTable.COL_STABLE_UPSTREAM_VER stable_upst_ver = self._GetRowValue(row, stable_upst_ver_col, arch) latest_upst_ver_col = utable.UpgradeTable.COL_LATEST_UPSTREAM_VER latest_upst_ver = self._GetRowValue(row, latest_upst_ver_col, arch) arch_vers = ['Current version: %s' % curr_ver, 'Stable upstream version: %s' % stable_upst_ver, 'Latest upstream version: %s' % latest_upst_ver] lines.append(' On %s: %s' % (arch, arch_status)) lines.append(' %s' % ', '.join(arch_vers)) else: lines.append(' On %s: not used' % arch) lines.append('') lines.append('Check the latest status for this package, including ' 'which upstream versions are available, at:\n %s' % _GetPkgSpreadsheetURL(self.scomm.ss_key)) lines.append('For help upgrading see: %s' % PKG_UPGRADE_PAGE) summary = '\n'.join(lines) issue = gdata_lib.Issue(title=title, summary=summary, status=status, owner=owner, labels=labels, ) return issue