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 main(argv): """Main function.""" parser = _CreateOptParser() (options, _args) = parser.parse_args(argv) oper.verbose = options.verbose _CheckOptions(options) ss_key = ups.TEST_SS_KEY if options.test_ss else ups.REAL_SS_KEY # Prepare credentials for Docs and Tracker access. creds = PrepareCreds(options.cred_file, options.token_file, options.email) scomm = gdata_lib.SpreadsheetComm() scomm.Connect(creds, ss_key, PKGS_WS_NAME, source='Sync Package Status') tcomm = gdata_lib.TrackerComm() tcomm.Connect(creds, PROJECT_NAME, source='Sync Package Status') oper.Notice('Syncing between Tracker and spreadsheet %s' % ss_key) syncer = Syncer(tcomm, scomm, pretend=options.pretend, verbose=options.verbose) if options.team: syncer.SetTeamFilter(options.team) if options.owner: syncer.SetOwnerFilter(options.owner) if options.default_owner: syncer.SetDefaultOwner(options.default_owner) try: syncer.Sync() except SyncError as ex: oper.Die(str(ex)) # If --email, which is only effective when run interactively (because the # password must be entered), give the option of saving to a creds file for # next time. if options.email and options.cred_file: prompt = ('Do you want to save credentials for next time to %r?' % options.cred_file) if cros_build_lib.BooleanPrompt(prompt, False): creds.StoreCreds(options.cred_file) oper.Notice('Be sure to save the creds file to the same location' ' outside your chroot so it will also be used with' ' future chroots.')