Move reports from FakeGithubConnection to github data
This is needed to handle comment pull as direct post request in the followup. Further the reports are better located in the github data since this needs to be global data. Further this will be needed as preparation for the HA scheduler as well since there will be more than one connection and the test data needs to be centralized then. Change-Id: I3fa96d43f0ffe62d50630856b23972221bf2c69a
This commit is contained in:
parent
ebb0b222ca
commit
688ecf6233
|
@ -2325,7 +2325,6 @@ class FakeGithubConnection(githubconnection.GithubConnection):
|
|||
self.upstream_root = upstream_root
|
||||
self.merge_failure = False
|
||||
self.merge_not_allowed_count = 0
|
||||
self.reports = []
|
||||
|
||||
self.github_data = tests.fakegithub.FakeGithubData(changes_db)
|
||||
self._github_client_manager.github_data = self.github_data
|
||||
|
@ -2417,27 +2416,28 @@ class FakeGithubConnection(githubconnection.GithubConnection):
|
|||
|
||||
def commentPull(self, project, pr_number, message, zuul_event_id=None):
|
||||
# record that this got reported
|
||||
self.reports.append((project, pr_number, 'comment'))
|
||||
self.github_data.reports.append((project, pr_number, 'comment'))
|
||||
pull_request = self.pull_requests[int(pr_number)]
|
||||
pull_request.addComment(message)
|
||||
|
||||
def setCommitStatus(self, project, sha, state, url='', description='',
|
||||
context='default', user='zuul', zuul_event_id=None):
|
||||
# record that this got reported and call original method
|
||||
self.reports.append((project, sha, 'status', (user, context, state)))
|
||||
self.github_data.reports.append(
|
||||
(project, sha, 'status', (user, context, state)))
|
||||
super(FakeGithubConnection, self).setCommitStatus(
|
||||
project, sha, state,
|
||||
url=url, description=description, context=context)
|
||||
|
||||
def labelPull(self, project, pr_number, label, zuul_event_id=None):
|
||||
# record that this got reported
|
||||
self.reports.append((project, pr_number, 'label', label))
|
||||
self.github_data.reports.append((project, pr_number, 'label', label))
|
||||
pull_request = self.pull_requests[int(pr_number)]
|
||||
pull_request.addLabel(label)
|
||||
|
||||
def unlabelPull(self, project, pr_number, label, zuul_event_id=None):
|
||||
# record that this got reported
|
||||
self.reports.append((project, pr_number, 'unlabel', label))
|
||||
self.github_data.reports.append((project, pr_number, 'unlabel', label))
|
||||
pull_request = self.pull_requests[pr_number]
|
||||
pull_request.removeLabel(label)
|
||||
|
||||
|
|
|
@ -506,7 +506,8 @@ class FakePull(object):
|
|||
pr = self._fake_pull_request
|
||||
|
||||
# record that this got reported
|
||||
conn.reports.append((pr.project, pr.number, 'merge', merge_method))
|
||||
conn.github_data.reports.append(
|
||||
(pr.project, pr.number, 'merge', merge_method))
|
||||
if conn.merge_failure:
|
||||
raise Exception('Unknown merge failure')
|
||||
if conn.merge_not_allowed_count > 0:
|
||||
|
@ -640,6 +641,7 @@ class FakeGithubData(object):
|
|||
def __init__(self, pull_requests):
|
||||
self.pull_requests = pull_requests
|
||||
self.repos = {}
|
||||
self.reports = []
|
||||
|
||||
|
||||
class FakeGithubClient(object):
|
||||
|
|
|
@ -567,10 +567,10 @@ class TestGithubDriver(ZuulTestCase):
|
|||
self.waitUntilSettled()
|
||||
|
||||
# there should only be one report, a status
|
||||
self.assertEqual(1, len(self.fake_github.reports))
|
||||
self.assertEqual(1, len(self.fake_github.github_data.reports))
|
||||
# Verify the user/context/state of the status
|
||||
status = ('zuul', 'tenant-one/push-reporting', 'pending')
|
||||
self.assertEqual(status, self.fake_github.reports[0][-1])
|
||||
self.assertEqual(status, self.fake_github.github_data.reports[0][-1])
|
||||
|
||||
# free the executor, allow the build to finish
|
||||
self.executor_server.hold_jobs_in_build = False
|
||||
|
@ -578,10 +578,10 @@ class TestGithubDriver(ZuulTestCase):
|
|||
self.waitUntilSettled()
|
||||
|
||||
# Now there should be a second report, the success of the build
|
||||
self.assertEqual(2, len(self.fake_github.reports))
|
||||
self.assertEqual(2, len(self.fake_github.github_data.reports))
|
||||
# Verify the user/context/state of the status
|
||||
status = ('zuul', 'tenant-one/push-reporting', 'success')
|
||||
self.assertEqual(status, self.fake_github.reports[-1][-1])
|
||||
self.assertEqual(status, self.fake_github.github_data.reports[-1][-1])
|
||||
|
||||
# now make a PR which should also comment
|
||||
self.executor_server.hold_jobs_in_build = True
|
||||
|
@ -591,7 +591,7 @@ class TestGithubDriver(ZuulTestCase):
|
|||
|
||||
# Now there should be a four reports, a new comment
|
||||
# and status
|
||||
self.assertEqual(4, len(self.fake_github.reports))
|
||||
self.assertEqual(4, len(self.fake_github.github_data.reports))
|
||||
self.executor_server.release()
|
||||
self.waitUntilSettled()
|
||||
|
||||
|
@ -1285,7 +1285,7 @@ class TestGithubDriver(ZuulTestCase):
|
|||
self.assertEqual(2, len(self.history))
|
||||
|
||||
# now check if the merge was done via rebase
|
||||
merges = [report for report in self.fake_github.reports
|
||||
merges = [report for report in self.fake_github.github_data.reports
|
||||
if report[2] == 'merge']
|
||||
assert(len(merges) == 1 and merges[0][3] == 'squash')
|
||||
|
||||
|
|
Loading…
Reference in New Issue