Fixed up unit test for buildbot 2.9

This commit is contained in:
Marvin Pohl 2021-03-09 20:37:00 +01:00
parent 56ef5a1d78
commit 7a50c7a064
2 changed files with 39 additions and 24 deletions

View File

@ -26,33 +26,36 @@ class TestGiteaStatusPush(
ReporterTestMixin, ReporterTestMixin,
logging.LoggingMixin, logging.LoggingMixin,
TestReactorMixin): TestReactorMixin):
# repository must be in the form http://gitea/<owner>/<project>
TEST_REPO = u'http://gitea/buildbot/buildbot'
@defer.inlineCallbacks @defer.inlineCallbacks
def setUp(self): def setUp(self):
self.setUpTestReactor() self.setUpTestReactor()
self.setup_reporter_test()
# repository must be in the form http://gitea/<owner>/<project>
self.reporter_test_repo = u'http://gitea/buildbot/buildbot'
# ignore config error if txrequests is not installed # ignore config error if txrequests is not installed
self.patch(config, '_errors', Mock()) self.patch(config, '_errors', Mock())
self.master = fakemaster.make_master(testcase=self, self.master = fakemaster.make_master(testcase=self,
wantData=True, wantDb=True, wantMq=True) wantData=True, wantDb=True, wantMq=True)
yield self.master.startService() yield self.master.startService()
self._http = yield fakehttpclientservice.HTTPClientService.getFakeService( self._http = yield fakehttpclientservice.HTTPClientService.getService(
self.master, self, self.master, self,
"http://gitea", headers={'Authorization': 'token XXYYZZ'}, "http://gitea", headers={'Authorization': 'token XXYYZZ'},
debug=None, verify=None) debug=None, verify=None)
self.sp = sp = GiteaStatusPush("http://gitea/", Interpolate('XXYYZZ')) self.sp = GiteaStatusPush("http://gitea/", Interpolate('XXYYZZ'))
sp.sessionFactory = Mock(return_value=Mock())
yield sp.setServiceParent(self.master) yield self.sp.setServiceParent(self.master)
def tearDown(self): def tearDown(self):
return self.master.stopService() return self.master.stopService()
def setupProps(self): def setupProps(self):
self.TEST_PROPS['owner'] = "buildbot" self.reporter_test_props['owner'] = "buildbot"
self.TEST_PROPS['repository_name'] = "buildbot" self.reporter_test_props['repository_name'] = "buildbot"
@defer.inlineCallbacks @defer.inlineCallbacks
def setupBuildResults(self, buildResults): def setupBuildResults(self, buildResults):
@ -85,11 +88,11 @@ class TestGiteaStatusPush(
'description': 'Build done.', 'context': 'buildbot/Builder0'}) 'description': 'Build done.', 'context': 'buildbot/Builder0'})
build['complete'] = False build['complete'] = False
self.sp.buildStarted(("build", 20, "started"), build) self.sp._got_event(('builds', 20, 'new'), build)
build['complete'] = True build['complete'] = True
self.sp.buildFinished(("build", 20, "finished"), build) self.sp._got_event(('builds', 20, 'finished'), build)
build['results'] = FAILURE build['results'] = FAILURE
self.sp.buildFinished(("build", 20, "finished"), build) self.sp._got_event(('builds', 20, 'finished'), build)
@defer.inlineCallbacks @defer.inlineCallbacks
def test_sshurl(self): def test_sshurl(self):
@ -104,11 +107,11 @@ class TestGiteaStatusPush(
'target_url': 'http://localhost:8080/#builders/79/builds/0', 'target_url': 'http://localhost:8080/#builders/79/builds/0',
'description': 'Build started.', 'context': 'buildbot/Builder0'}) 'description': 'Build started.', 'context': 'buildbot/Builder0'})
build['complete'] = False build['complete'] = False
self.sp.buildStarted(("build", 20, "started"), build) self.sp._got_event(('builds', 20, 'new'), build)
@defer.inlineCallbacks @defer.inlineCallbacks
def test_sshurl_noprops(self): def test_sshurl_noprops(self):
self.TEST_REPO = u'git@gitea:buildbot/buildbot.git' self.reporter_test_repo = u'git@gitea:buildbot/buildbot.git'
build = yield self.setupBuildResults(SUCCESS) build = yield self.setupBuildResults(SUCCESS)
# we make sure proper calls to txrequests have been made # we make sure proper calls to txrequests have been made
self._http.expect( self._http.expect(
@ -118,17 +121,17 @@ class TestGiteaStatusPush(
'target_url': 'http://localhost:8080/#builders/79/builds/0', 'target_url': 'http://localhost:8080/#builders/79/builds/0',
'description': 'Build started.', 'context': 'buildbot/Builder0'}) 'description': 'Build started.', 'context': 'buildbot/Builder0'})
build['complete'] = False build['complete'] = False
self.sp.buildStarted(("build", 20, "started"), build) self.sp._got_event(('builds', 20, 'new'), build)
@defer.inlineCallbacks @defer.inlineCallbacks
def test_noowner(self): def test_noowner(self):
self.setUpLogging() self.setUpLogging()
self.setupProps() self.setupProps()
del self.TEST_PROPS["owner"] del self.reporter_test_props["owner"]
self.TEST_REPO = u'' self.TEST_REPO = u''
build = yield self.setupBuildResults(SUCCESS) build = yield self.setupBuildResults(SUCCESS)
build['complete'] = False build['complete'] = False
self.sp.buildStarted(("build", 20, "started"), build) self.sp._got_event(('builds', 20, 'new'), build)
# implicit check that no http request is done # implicit check that no http request is done
self.assertLogged("Could not send status, " self.assertLogged("Could not send status, "
"build has no owner property for Gitea.") "build has no owner property for Gitea.")
@ -137,11 +140,11 @@ class TestGiteaStatusPush(
def test_noreponame(self): def test_noreponame(self):
self.setUpLogging() self.setUpLogging()
self.setupProps() self.setupProps()
del self.TEST_PROPS["repository_name"] del self.reporter_test_props["repository_name"]
self.TEST_REPO = u'' self.TEST_REPO = u''
build = yield self.setupBuildResults(SUCCESS) build = yield self.setupBuildResults(SUCCESS)
build['complete'] = False build['complete'] = False
self.sp.buildStarted(("build", 20, "started"), build) self.sp._got_event(('builds', 20, 'new'), build)
# implicit check that no http request is done # implicit check that no http request is done
self.assertLogged("Could not send status, " self.assertLogged("Could not send status, "
"build has no repository_name property for Gitea.") "build has no repository_name property for Gitea.")
@ -150,7 +153,7 @@ class TestGiteaStatusPush(
def test_senderror(self): def test_senderror(self):
self.setupProps() self.setupProps()
self.setUpLogging() self.setUpLogging()
build = yield self.setupBuildResults(SUCCESS) build = yield self.insert_build_new()
# we make sure proper calls to txrequests have been made # we make sure proper calls to txrequests have been made
self._http.expect( self._http.expect(
'post', 'post',
@ -164,7 +167,7 @@ class TestGiteaStatusPush(
}, },
code=500) code=500)
build['complete'] = False build['complete'] = False
self.sp.buildStarted(("build", 20, "started"), build) self.sp._got_event(("builds", 20, "new"), build)
self.assertLogged( self.assertLogged(
"Could not send status \"pending\" for " "Could not send status \"pending\" for "
"http://gitea/buildbot/buildbot at d34db33fd43db33f:" "http://gitea/buildbot/buildbot at d34db33fd43db33f:"
@ -174,10 +177,22 @@ class TestGiteaStatusPush(
def test_badchange(self): def test_badchange(self):
self.setupProps() self.setupProps()
self.setUpLogging() self.setUpLogging()
build = yield self.setupBuildResults(SUCCESS) build = yield self.insert_build_new()
# we make sure proper calls to txrequests have been made # we make sure proper calls to txrequests have been made
self._http.expect(
'post',
'/api/v1/repos/buildbot/buildbot/statuses/d34db33fd43db33f',
json={
'state': 'pending',
'description': 'Build started.',
'target_url': 'http://localhost:8080/#builders/79/builds/0',
'context': 'buildbot/Builder0'
},
content_json={"message": "Not found"},
code=404,
)
build['complete'] = False build['complete'] = False
self.sp.buildStarted(("build", 20, "started"), build) yield self.sp._got_event(("builds", 20, "new"), build)
self.assertLogged("Failed to send status \"pending\" for" self.assertLogged("Could not send status \"pending\" for"
" http://gitea/buildbot/buildbot at d34db33fd43db33f") " http://gitea/buildbot/buildbot at d34db33fd43db33f")
self.flushLoggedErrors(AssertionError) self.flushLoggedErrors(AssertionError)

View File

@ -77,7 +77,7 @@ class TestGitea(sourcesteps.SourceStepMixin, config.ConfigErrorsMixin, unittest.
+ 0, + 0,
# here we always ignore revision, and fetch the merge branch # here we always ignore revision, and fetch the merge branch
ExpectShell(workdir='wkdir', ExpectShell(workdir='wkdir',
command=['git', 'fetch', '-t', command=['git', 'fetch', '-f', '-t',
'git@gitea.example.com:base/awesome_project.git', 'HEAD', '--progress']) 'git@gitea.example.com:base/awesome_project.git', 'HEAD', '--progress'])
+ 0, + 0,
ExpectShell(workdir='wkdir', ExpectShell(workdir='wkdir',