def createReporter(self, auth=("username", "passwd"), **kwargs): self._http = yield fakehttpclientservice.HTTPClientService.getService( self.master, self, "serv", auth=auth, debug=None, verify=None) interpolated_auth = None if auth is not None: username, passwd = auth passwd = Interpolate(passwd) interpolated_auth = (username, passwd) self.sp = HttpStatusPush("serv", auth=interpolated_auth, **kwargs) yield self.sp.setServiceParent(self.master)
def createReporter(self, **kwargs): self._http = yield fakehttpclientservice.HTTPClientService.getService( self.master, "serv", auth=("username", "passwd")) self.sp = sp = HttpStatusPush("serv", auth=("username", Interpolate("passwd")), **kwargs) yield sp.setServiceParent(self.master)
class TestHttpStatusPush(TestReactorMixin, unittest.TestCase, ReporterTestMixin): @defer.inlineCallbacks def setUp(self): self.setUpTestReactor() self.setup_reporter_test() # ignore config error if txrequests is not installed config._errors = Mock() self.master = fakemaster.make_master(self, wantData=True, wantDb=True, wantMq=True) yield self.master.startService() @defer.inlineCallbacks def createReporter(self, auth=("username", "passwd"), **kwargs): self._http = yield fakehttpclientservice.HTTPClientService.getService( self.master, self, "serv", auth=auth, debug=None, verify=None) interpolated_auth = None if auth is not None: username, passwd = auth passwd = Interpolate(passwd) interpolated_auth = (username, passwd) self.sp = HttpStatusPush("serv", auth=interpolated_auth, **kwargs) yield self.sp.setServiceParent(self.master) @defer.inlineCallbacks def tearDown(self): yield self.master.stopService() config._errors = None @defer.inlineCallbacks def test_basic(self): yield self.createReporter() self._http.expect("post", "", json=BuildLookAlike(complete=False)) self._http.expect("post", "", json=BuildLookAlike(complete=True)) build = yield self.insert_build_new() yield self.sp._got_event(('builds', 20, 'new'), build) build['complete'] = True build['results'] = SUCCESS yield self.sp._got_event(('builds', 20, 'finished'), build) @defer.inlineCallbacks def test_basic_noauth(self): yield self.createReporter(auth=None) self._http.expect("post", "", json=BuildLookAlike(complete=False)) self._http.expect("post", "", json=BuildLookAlike(complete=True)) build = yield self.insert_build_new() yield self.sp._got_event(('builds', 20, 'new'), build) build['complete'] = True build['results'] = SUCCESS yield self.sp._got_event(('builds', 20, 'finished'), build) @defer.inlineCallbacks def test_filtering(self): with assertProducesWarnings(DeprecatedApiWarning, message_pattern='have been deprecated'): yield self.createReporter(builders=['foo']) build = yield self.insert_build_finished(SUCCESS) yield self.sp._got_event(('builds', 20, 'finished'), build) @defer.inlineCallbacks def test_filteringPass(self): with assertProducesWarnings(DeprecatedApiWarning, message_pattern='have been deprecated'): yield self.createReporter(builders=['Builder0']) self._http.expect("post", "", json=BuildLookAlike()) build = yield self.insert_build_finished(SUCCESS) yield self.sp._got_event(('builds', 20, 'finished'), build) @defer.inlineCallbacks def test_builderTypeCheck(self): with assertProducesWarnings(DeprecatedApiWarning, message_pattern='have been deprecated'): yield self.createReporter(builders='Builder0') config._errors.addError.assert_any_call( "builders must be a list or None") @defer.inlineCallbacks def test_wantKwargsCheck(self): with assertProducesWarnings(DeprecatedApiWarning, message_pattern='have been deprecated'): yield self.createReporter(builders='Builder0', wantProperties=True, wantSteps=True, wantPreviousBuild=True, wantLogs=True) self._http.expect("post", "", json=BuildLookAlike(keys=['steps', 'prev_build'])) build = yield self.insert_build_finished(SUCCESS) yield self.sp._got_event(('builds', 20, 'finished'), build) @defer.inlineCallbacks def http2XX(self, code, content): yield self.createReporter() self._http.expect('post', '', code=code, content=content, json=BuildLookAlike()) build = yield self.insert_build_finished(SUCCESS) yield self.sp._got_event(('builds', 20, 'finished'), build) @defer.inlineCallbacks def test_http200(self): yield self.http2XX(code=200, content="OK") @defer.inlineCallbacks def test_http201(self): # e.g. GitHub returns 201 yield self.http2XX(code=201, content="Created") @defer.inlineCallbacks def test_http202(self): yield self.http2XX(code=202, content="Accepted")
class TestHttpStatusPush(TestReactorMixin, unittest.TestCase, ReporterTestMixin, ConfigErrorsMixin): @defer.inlineCallbacks def setUp(self): self.setup_test_reactor() self.setup_reporter_test() self.master = fakemaster.make_master(self, wantData=True, wantDb=True, wantMq=True) yield self.master.startService() @defer.inlineCallbacks def createReporter(self, auth=("username", "passwd"), headers=None, **kwargs): self._http = yield fakehttpclientservice.HTTPClientService.getService( self.master, self, "serv", auth=auth, headers=headers, debug=None, verify=None) interpolated_auth = None if auth is not None: username, passwd = auth passwd = Interpolate(passwd) interpolated_auth = (username, passwd) self.sp = HttpStatusPush("serv", auth=interpolated_auth, headers=headers, **kwargs) yield self.sp.setServiceParent(self.master) @defer.inlineCallbacks def tearDown(self): yield self.master.stopService() @defer.inlineCallbacks def test_basic(self): yield self.createReporter() self._http.expect("post", "", json=BuildDictLookAlike(complete=False)) self._http.expect("post", "", json=BuildDictLookAlike(complete=True)) build = yield self.insert_build_new() yield self.sp._got_event(('builds', 20, 'new'), build) build['complete'] = True build['results'] = SUCCESS yield self.sp._got_event(('builds', 20, 'finished'), build) @defer.inlineCallbacks def test_basic_noauth(self): yield self.createReporter(auth=None) self._http.expect("post", "", json=BuildDictLookAlike(complete=False)) self._http.expect("post", "", json=BuildDictLookAlike(complete=True)) build = yield self.insert_build_new() yield self.sp._got_event(('builds', 20, 'new'), build) build['complete'] = True build['results'] = SUCCESS yield self.sp._got_event(('builds', 20, 'finished'), build) @defer.inlineCallbacks def test_header(self): yield self.createReporter(headers={'Custom header': 'On'}) self._http.expect("post", "", json=BuildDictLookAlike()) build = yield self.insert_build_finished(SUCCESS) yield self.sp._got_event(('builds', 20, 'finished'), build) @defer.inlineCallbacks def http2XX(self, code, content): yield self.createReporter() self._http.expect('post', '', code=code, content=content, json=BuildDictLookAlike()) build = yield self.insert_build_finished(SUCCESS) yield self.sp._got_event(('builds', 20, 'finished'), build) @defer.inlineCallbacks def test_http200(self): yield self.http2XX(code=200, content="OK") @defer.inlineCallbacks def test_http201(self): # e.g. GitHub returns 201 yield self.http2XX(code=201, content="Created") @defer.inlineCallbacks def test_http202(self): yield self.http2XX(code=202, content="Accepted")
def createReporter(self, **kwargs): self.sp = sp = HttpStatusPush("serv", "username", "passwd", **kwargs) sp.sessionFactory = Mock(return_value=Mock()) yield sp.setServiceParent(self.master) yield sp.startService()