def test_is_message_needed_ignores_unspecified_tags(self): build = yield self.insert_build_finished_get_props(SUCCESS) # force tags build['builder']['tags'] = ['tag'] g = BuildStartEndStatusGenerator(tags=['not_existing_tag']) self.assertFalse(g.is_message_needed_by_props(build))
def test_is_message_needed_tags(self): build = yield self.insert_build_finished_get_props(SUCCESS) # force tags build['builder']['tags'] = ['tag'] g = BuildStartEndStatusGenerator(tags=['tag']) self.assertTrue(g.is_message_needed_by_props(build))
def setUp(self): self.setup_test_reactor() self.setup_reporter_test() self.reporter_test_repo = 'https://example.org/user/repo' self.master = fakemaster.make_master(self, wantData=True, wantDb=True, wantMq=True) self._http = yield fakehttpclientservice.HTTPClientService.getService( self.master, self, _BASE_URL, debug=None, verify=None) self.oauthhttp = yield fakehttpclientservice.HTTPClientService.getService( self.master, self, _OAUTH_URL, auth=('key', 'secret'), debug=None, verify=None) self.bsp = BitbucketStatusPush( Interpolate('key'), Interpolate('secret'), status_key=Interpolate( "%(prop:buildername)s/%(prop:buildnumber)s"), status_name=Interpolate( "%(prop:buildername)s-%(prop:buildnumber)s"), generators=[ BuildStartEndStatusGenerator( start_formatter=MessageFormatter( subject="{{ status_detected }}"), end_formatter=MessageFormatter(subject="{{ summary }}")) ]) yield self.bsp.setServiceParent(self.master) yield self.bsp.startService()
def setup_generator(self, results=SUCCESS, start_message=None, end_message=None, **kwargs): if start_message is None: start_message = { "body": "start body", "type": "plain", "subject": "start subject" } if end_message is None: end_message = { "body": "end body", "type": "plain", "subject": "end subject" } g = BuildStartEndStatusGenerator(**kwargs) g.start_formatter = Mock(spec=g.start_formatter) g.start_formatter.format_message_for_build.return_value = start_message g.end_formatter = Mock(spec=g.end_formatter) g.end_formatter.format_message_for_build.return_value = end_message return g
def _create_default_generators(self): return [ BuildStartEndStatusGenerator( start_formatter=MessageFormatter(subject=""), end_formatter=MessageFormatter(subject="") ) ]
def _create_default_generators(self): start_formatter = MessageFormatterRenderable('Build started.') end_formatter = MessageFormatterRenderable('Build done.') return [ BuildStartEndStatusGenerator(start_formatter=start_formatter, end_formatter=end_formatter) ]
def checkConfig(self, endpoint, token, stream=None, debug=None, verify=None): if not isinstance(endpoint, str): config.error("Endpoint must be a string") if not isinstance(token, str): config.error("Token must be a string") super().checkConfig(generators=[BuildStartEndStatusGenerator()]) httpclientservice.HTTPClientService.checkAvailable(self.__class__.__name__)
def reconfigService(self, endpoint, token, stream=None, debug=None, verify=None): self.debug = debug self.verify = verify yield super().reconfigService(generators=[BuildStartEndStatusGenerator()]) self._http = yield httpclientservice.HTTPClientService.getService( self.master, endpoint, debug=self.debug, verify=self.verify) self.token = token self.stream = stream
def test_setting_options(self): generator = BuildStartEndStatusGenerator( start_formatter=MessageFormatterRenderable('Build started.'), end_formatter=MessageFormatterRenderable('Build finished.')) self.setupReporter(statusName='Build', generators=[generator]) build = yield self.insert_build_finished(SUCCESS) # we make sure proper calls to txrequests have been made self._http.expect('post', '/rest/build-status/1.0/commits/d34db33fd43db33f', json={ 'url': 'http://localhost:8080/#builders/79/builds/0', 'state': 'INPROGRESS', 'key': 'Builder0', 'name': 'Build', 'description': 'Build started.' }, code=HTTP_PROCESSED) self._http.expect('post', '/rest/build-status/1.0/commits/d34db33fd43db33f', json={ 'url': 'http://localhost:8080/#builders/79/builds/0', 'state': 'SUCCESSFUL', 'key': 'Builder0', 'name': 'Build', 'description': 'Build finished.' }, code=HTTP_PROCESSED) self._http.expect('post', '/rest/build-status/1.0/commits/d34db33fd43db33f', json={ 'url': 'http://localhost:8080/#builders/79/builds/0', 'state': 'FAILED', 'key': 'Builder0', 'name': 'Build', 'description': 'Build finished.' }, code=HTTP_PROCESSED) build['complete'] = False yield self.sp._got_event(('builds', 20, 'new'), build) build['complete'] = True yield self.sp._got_event(('builds', 20, 'finished'), build) build['results'] = FAILURE yield self.sp._got_event(('builds', 20, 'finished'), build)
def test_custom_description(self): start_formatter = MessageFormatterRenderable( Interpolate("started %(prop:buildername)s")) end_formatter = MessageFormatterRenderable( Interpolate("finished %(prop:buildername)s")) generator = BuildStartEndStatusGenerator( start_formatter=start_formatter, end_formatter=end_formatter) yield self.createGerritStatus(generators=[generator]) build = yield self.insert_build_new() # we make sure proper calls to txrequests have been made self._http.expect( method='post', ep='/a/changes/12/revisions/2/verify-status~verifications', json={ 'comment': 'started Builder0', 'abstain': False, 'name': 'Builder0', 'reporter': 'buildbot', 'url': 'http://localhost:8080/#builders/79/builds/0', 'value': 0, 'duration': 'pending' }) self._http.expect( method='post', ep='/a/changes/12/revisions/2/verify-status~verifications', json={ 'comment': 'finished Builder0', 'abstain': False, 'name': 'Builder0', 'reporter': 'buildbot', 'url': 'http://localhost:8080/#builders/79/builds/0', 'value': 1, 'duration': '2h 1m 4s' }) yield self.sp._got_event(('builds', 20, 'new'), build) build['complete'] = True build['complete_at'] = build['started_at'] + \ datetime.timedelta(hours=2, minutes=1, seconds=4) build['results'] = SUCCESS yield self.sp._got_event(('builds', 20, 'finished'), build)
def test_list_params_check_raises(self, arg_name, arg_value): kwargs = {arg_name: arg_value} g = BuildStartEndStatusGenerator(**kwargs) with self.assertRaisesConfigError('must be a list or None'): g.check()
def _create_default_generators(self): return [BuildStartEndStatusGenerator()]