def createReporter(self, **kwargs): kwargs['auth_token'] = kwargs.get('auth_token', 'abc') self.sp = HipChatStatusPush(**kwargs) self._http = yield fakehttpclientservice.HTTPClientService.getFakeService( self.master, self, kwargs.get('endpoint', HOSTED_BASE_URL)) yield self.sp.setServiceParent(self.master) yield self.master.startService()
class TestHipchatStatusPush(unittest.TestCase, ReporterTestMixin, LoggingMixin): def setUp(self): # ignore config error if txrequests is not installed self.patch(config, '_errors', Mock()) self.master = fakemaster.make_master( testcase=self, wantData=True, wantDb=True, wantMq=True) @defer.inlineCallbacks def tearDown(self): if self.master.running: yield self.master.stopService() @defer.inlineCallbacks def createReporter(self, **kwargs): kwargs['auth_token'] = kwargs.get('auth_token', 'abc') self.sp = HipChatStatusPush(**kwargs) self._http = yield fakehttpclientservice.HTTPClientService.getFakeService( self.master, self, kwargs.get('endpoint', HOSTED_BASE_URL)) yield self.sp.setServiceParent(self.master) yield self.master.startService() @defer.inlineCallbacks def setupBuildResults(self): self.insertTestData([SUCCESS], SUCCESS) build = yield self.master.data.get(("builds", 20)) defer.returnValue(build) @defer.inlineCallbacks def test_authtokenTypeCheck(self): yield self.createReporter(auth_token=2) config._errors.addError.assert_any_call('auth_token must be a string') def test_endpointTypeCheck(self): HipChatStatusPush(auth_token="2", endpoint=2) config._errors.addError.assert_any_call('endpoint must be a string') @defer.inlineCallbacks def test_builderRoomMapTypeCheck(self): yield self.createReporter(builder_room_map=2) config._errors.addError.assert_any_call( 'builder_room_map must be a dict') @defer.inlineCallbacks def test_builderUserMapTypeCheck(self): yield self.createReporter(builder_user_map=2) config._errors.addError.assert_any_call( 'builder_user_map must be a dict') @defer.inlineCallbacks def test_build_started(self): yield self.createReporter(builder_user_map={'Builder0': '123'}) build = yield self.setupBuildResults() self._http.expect( 'post', '/v2/user/123/message', params=dict(auth_token='abc'), json={'message': 'Buildbot started build Builder0 here: http://localhost:8080/#builders/79/builds/0'}) self.sp.buildStarted(('build', 20, 'new'), build) @defer.inlineCallbacks def test_build_finished(self): yield self.createReporter(builder_room_map={'Builder0': '123'}) build = yield self.setupBuildResults() self._http.expect( 'post', '/v2/room/123/notification', params=dict(auth_token='abc'), json={'message': 'Buildbot finished build Builder0 with result success ' 'here: http://localhost:8080/#builders/79/builds/0'}) self.sp.buildFinished(('build', 20, 'finished'), build) @defer.inlineCallbacks def test_inject_extra_params(self): yield self.createReporter(builder_room_map={'Builder0': '123'}) self.sp.getExtraParams = Mock() self.sp.getExtraParams.return_value = {'format': 'html'} build = yield self.setupBuildResults() self._http.expect( 'post', '/v2/room/123/notification', params=dict(auth_token='abc'), json={'message': 'Buildbot finished build Builder0 with result success ' 'here: http://localhost:8080/#builders/79/builds/0', 'format': 'html'}) self.sp.buildFinished(('build', 20, 'finished'), build) @defer.inlineCallbacks def test_no_message_sent_empty_message(self): yield self.createReporter() build = yield self.setupBuildResults() self.sp.send(build, 'unknown') @defer.inlineCallbacks def test_no_message_sent_without_id(self): yield self.createReporter() build = yield self.setupBuildResults() self.sp.send(build, 'new') @defer.inlineCallbacks def test_private_message_sent_with_user_id(self): token = 'tok' endpoint = 'example.com' yield self.createReporter(auth_token=token, endpoint=endpoint) self.sp.getBuildDetailsAndSendMessage = Mock() message = {'message': 'hi'} postData = dict(message) postData.update({'id_or_email': '123'}) self.sp.getBuildDetailsAndSendMessage.return_value = postData self._http.expect( 'post', '/v2/user/123/message', params=dict(auth_token=token), json=message) self.sp.send({}, 'test') @defer.inlineCallbacks def test_room_message_sent_with_room_id(self): token = 'tok' endpoint = 'example.com' yield self.createReporter(auth_token=token, endpoint=endpoint) self.sp.getBuildDetailsAndSendMessage = Mock() message = {'message': 'hi'} postData = dict(message) postData.update({'room_id_or_name': '123'}) self.sp.getBuildDetailsAndSendMessage.return_value = postData self._http.expect( 'post', '/v2/room/123/notification', params=dict(auth_token=token), json=message) self.sp.send({}, 'test') @defer.inlineCallbacks def test_private_and_room_message_sent_with_both_ids(self): token = 'tok' endpoint = 'example.com' yield self.createReporter(auth_token=token, endpoint=endpoint) self.sp.getBuildDetailsAndSendMessage = Mock() message = {'message': 'hi'} postData = dict(message) postData.update({'room_id_or_name': '123', 'id_or_email': '456'}) self.sp.getBuildDetailsAndSendMessage.return_value = postData self._http.expect( 'post', '/v2/user/456/message', params=dict(auth_token=token), json=message) self._http.expect( 'post', '/v2/room/123/notification', params=dict(auth_token=token), json=message) self.sp.send({}, 'test') @defer.inlineCallbacks def test_postData_values_passed_through(self): token = 'tok' endpoint = 'example.com' yield self.createReporter(auth_token=token, endpoint=endpoint) self.sp.getBuildDetailsAndSendMessage = Mock() message = {'message': 'hi', 'notify': True, 'message_format': 'html'} postData = dict(message) postData.update({'id_or_email': '123'}) self.sp.getBuildDetailsAndSendMessage.return_value = postData self._http.expect( 'post', '/v2/user/123/message', params=dict(auth_token=token), json=message) self.sp.send({}, 'test') @defer.inlineCallbacks def test_postData_error(self): token = 'tok' endpoint = 'example.com' yield self.createReporter(auth_token=token, endpoint=endpoint) self.sp.getBuildDetailsAndSendMessage = Mock() message = {'message': 'hi', 'notify': True, 'message_format': 'html'} postData = dict(message) postData.update({'id_or_email': '123'}) self.sp.getBuildDetailsAndSendMessage.return_value = postData self._http.expect( 'post', '/v2/user/123/message', params=dict(auth_token=token), json=message, code=404, content_json={ "error_description": "This user is unknown to us", "error": "invalid_user"}) self.setUpLogging() self.sp.send({}, 'test') self.assertLogged('404: unable to upload status')
def test_endpointTypeCheck(self): HipChatStatusPush(auth_token="2", endpoint=2) config._errors.addError.assert_any_call('endpoint must be a string')
class TestHipchatStatusPush(TestReactorMixin, unittest.TestCase, ReporterTestMixin, LoggingMixin): def setUp(self): self.setUpTestReactor() # ignore config error if txrequests is not installed self.patch(config, '_errors', Mock()) self.master = fakemaster.make_master(self, wantData=True, wantDb=True, wantMq=True) @defer.inlineCallbacks def tearDown(self): if self.master.running: yield self.master.stopService() @defer.inlineCallbacks def createReporter(self, **kwargs): kwargs['auth_token'] = kwargs.get('auth_token', 'abc') self.sp = HipChatStatusPush(**kwargs) self._http = yield fakehttpclientservice.HTTPClientService.getFakeService( self.master, self, kwargs.get('endpoint', HOSTED_BASE_URL), debug=None, verify=None) yield self.sp.setServiceParent(self.master) yield self.master.startService() @defer.inlineCallbacks def setupBuildResults(self): self.insertTestData([SUCCESS], SUCCESS) build = yield self.master.data.get(("builds", 20)) return build @defer.inlineCallbacks def test_authtokenTypeCheck(self): yield self.createReporter(auth_token=2) config._errors.addError.assert_any_call('auth_token must be a string') def test_endpointTypeCheck(self): HipChatStatusPush(auth_token="2", endpoint=2) config._errors.addError.assert_any_call('endpoint must be a string') @defer.inlineCallbacks def test_builderRoomMapTypeCheck(self): yield self.createReporter(builder_room_map=2) config._errors.addError.assert_any_call( 'builder_room_map must be a dict') @defer.inlineCallbacks def test_builderUserMapTypeCheck(self): yield self.createReporter(builder_user_map=2) config._errors.addError.assert_any_call( 'builder_user_map must be a dict') @defer.inlineCallbacks def test_interpolateAuth(self): yield self.createReporter(auth_token=Interpolate('auth'), builder_user_map={'Builder0': '123'}) build = yield self.setupBuildResults() self._http.expect( 'post', '/v2/user/123/message', params=dict(auth_token='auth'), json={ 'message': 'Buildbot started build Builder0 here: http://localhost:8080/#builders/79/builds/0' }) self.sp.buildStarted(('build', 20, 'new'), build) @defer.inlineCallbacks def test_build_started(self): yield self.createReporter(builder_user_map={'Builder0': '123'}) build = yield self.setupBuildResults() self._http.expect( 'post', '/v2/user/123/message', params=dict(auth_token='abc'), json={ 'message': 'Buildbot started build Builder0 here: http://localhost:8080/#builders/79/builds/0' }) self.sp.buildStarted(('build', 20, 'new'), build) @defer.inlineCallbacks def test_build_finished(self): yield self.createReporter(builder_room_map={'Builder0': '123'}) build = yield self.setupBuildResults() self._http.expect( 'post', '/v2/room/123/notification', params=dict(auth_token='abc'), json={ 'message': 'Buildbot finished build Builder0 with result success ' 'here: http://localhost:8080/#builders/79/builds/0' }) self.sp.buildFinished(('build', 20, 'finished'), build) @defer.inlineCallbacks def test_inject_extra_params(self): yield self.createReporter(builder_room_map={'Builder0': '123'}) self.sp.getExtraParams = Mock() self.sp.getExtraParams.return_value = {'format': 'html'} build = yield self.setupBuildResults() self._http.expect( 'post', '/v2/room/123/notification', params=dict(auth_token='abc'), json={ 'message': 'Buildbot finished build Builder0 with result success ' 'here: http://localhost:8080/#builders/79/builds/0', 'format': 'html' }) self.sp.buildFinished(('build', 20, 'finished'), build) @defer.inlineCallbacks def test_no_message_sent_empty_message(self): yield self.createReporter() build = yield self.setupBuildResults() self.sp.send(build, 'unknown') @defer.inlineCallbacks def test_no_message_sent_without_id(self): yield self.createReporter() build = yield self.setupBuildResults() self.sp.send(build, 'new') @defer.inlineCallbacks def test_private_message_sent_with_user_id(self): token = 'tok' endpoint = 'example.com' yield self.createReporter(auth_token=token, endpoint=endpoint) self.sp.getBuildDetailsAndSendMessage = Mock() message = {'message': 'hi'} postData = dict(message) postData.update({'id_or_email': '123'}) self.sp.getBuildDetailsAndSendMessage.return_value = postData self._http.expect('post', '/v2/user/123/message', params=dict(auth_token=token), json=message) self.sp.send({}, 'test') @defer.inlineCallbacks def test_room_message_sent_with_room_id(self): token = 'tok' endpoint = 'example.com' yield self.createReporter(auth_token=token, endpoint=endpoint) self.sp.getBuildDetailsAndSendMessage = Mock() message = {'message': 'hi'} postData = dict(message) postData.update({'room_id_or_name': '123'}) self.sp.getBuildDetailsAndSendMessage.return_value = postData self._http.expect('post', '/v2/room/123/notification', params=dict(auth_token=token), json=message) self.sp.send({}, 'test') @defer.inlineCallbacks def test_private_and_room_message_sent_with_both_ids(self): token = 'tok' endpoint = 'example.com' yield self.createReporter(auth_token=token, endpoint=endpoint) self.sp.getBuildDetailsAndSendMessage = Mock() message = {'message': 'hi'} postData = dict(message) postData.update({'room_id_or_name': '123', 'id_or_email': '456'}) self.sp.getBuildDetailsAndSendMessage.return_value = postData self._http.expect('post', '/v2/user/456/message', params=dict(auth_token=token), json=message) self._http.expect('post', '/v2/room/123/notification', params=dict(auth_token=token), json=message) self.sp.send({}, 'test') @defer.inlineCallbacks def test_postData_values_passed_through(self): token = 'tok' endpoint = 'example.com' yield self.createReporter(auth_token=token, endpoint=endpoint) self.sp.getBuildDetailsAndSendMessage = Mock() message = {'message': 'hi', 'notify': True, 'message_format': 'html'} postData = dict(message) postData.update({'id_or_email': '123'}) self.sp.getBuildDetailsAndSendMessage.return_value = postData self._http.expect('post', '/v2/user/123/message', params=dict(auth_token=token), json=message) self.sp.send({}, 'test') @defer.inlineCallbacks def test_postData_error(self): token = 'tok' endpoint = 'example.com' yield self.createReporter(auth_token=token, endpoint=endpoint) self.sp.getBuildDetailsAndSendMessage = Mock() message = {'message': 'hi', 'notify': True, 'message_format': 'html'} postData = dict(message) postData.update({'id_or_email': '123'}) self.sp.getBuildDetailsAndSendMessage.return_value = postData self._http.expect('post', '/v2/user/123/message', params=dict(auth_token=token), json=message, code=404, content_json={ "error_description": "This user is unknown to us", "error": "invalid_user" }) self.setUpLogging() self.sp.send({}, 'test') self.assertLogged('404: unable to upload status')
def createReporter(self, **kwargs): kwargs['auth_token'] = kwargs.get('auth_token', 'abc') self.sp = HipChatStatusPush(**kwargs) self.sp.sessionFactory = Mock(return_value=Mock()) yield self.sp.setServiceParent(self.master) yield self.sp.startService()
class TestHipchatStatusPush(unittest.TestCase, ReporterTestMixin): def setUp(self): # ignore config error if txrequests is not installed config._errors = Mock() self.master = fakemaster.make_master( testcase=self, wantData=True, wantDb=True, wantMq=True) @defer.inlineCallbacks def tearDown(self): yield self.sp.stopService() self.assertEqual(self.sp.session.close.call_count, 1) config._errors = None @defer.inlineCallbacks def createReporter(self, **kwargs): kwargs['auth_token'] = kwargs.get('auth_token', 'abc') self.sp = HipChatStatusPush(**kwargs) self.sp.sessionFactory = Mock(return_value=Mock()) yield self.sp.setServiceParent(self.master) yield self.sp.startService() @defer.inlineCallbacks def setupBuildResults(self): self.insertTestData([SUCCESS], SUCCESS) build = yield self.master.data.get(("builds", 20)) defer.returnValue(build) @defer.inlineCallbacks def test_authtokenTypeCheck(self): yield self.createReporter(auth_token=2) config._errors.addError.assert_any_call('auth_token must be a string') @defer.inlineCallbacks def test_endpointTypeCheck(self): yield self.createReporter(endpoint=2) config._errors.addError.assert_any_call('endpoint must be a string') @defer.inlineCallbacks def test_builderRoomMapTypeCheck(self): yield self.createReporter(builder_room_map=2) config._errors.addError.assert_any_call( 'builder_room_map must be a dict') @defer.inlineCallbacks def test_builderUserMapTypeCheck(self): yield self.createReporter(builder_user_map=2) config._errors.addError.assert_any_call( 'builder_user_map must be a dict') @defer.inlineCallbacks def test_build_started(self): yield self.createReporter(builder_user_map={'Builder0': '123'}) build = yield self.setupBuildResults() self.sp.buildStarted(('build', 20, 'new'), build) expected = [call( 'https://api.hipchat.com/v2/user/123/message?auth_token=abc', {'message': 'Buildbot started build Builder0 here: http://localhost:8080/#builders/79/builds/0'})] self.assertEqual(self.sp.session.post.mock_calls, expected) @defer.inlineCallbacks def test_build_finished(self): yield self.createReporter(builder_room_map={'Builder0': '123'}) build = yield self.setupBuildResults() self.sp.buildFinished(('build', 20, 'finished'), build) expected = [call( 'https://api.hipchat.com/v2/room/123/notification?auth_token=abc', {'message': 'Buildbot finished build Builder0 with result success ' 'here: http://localhost:8080/#builders/79/builds/0'})] self.assertEqual(self.sp.session.post.mock_calls, expected) @defer.inlineCallbacks def test_inject_extra_params(self): yield self.createReporter(builder_room_map={'Builder0': '123'}) self.sp.getExtraParams = Mock() self.sp.getExtraParams.return_value = {'format': 'html'} build = yield self.setupBuildResults() self.sp.buildFinished(('build', 20, 'finished'), build) expected = [call( 'https://api.hipchat.com/v2/room/123/notification?auth_token=abc', {'message': 'Buildbot finished build Builder0 with result success ' 'here: http://localhost:8080/#builders/79/builds/0', 'format': 'html'})] self.assertEqual(self.sp.session.post.mock_calls, expected) @defer.inlineCallbacks def test_no_message_sent_empty_message(self): yield self.createReporter() build = yield self.setupBuildResults() self.sp.send(build, 'unknown') assert not self.sp.session.post.called @defer.inlineCallbacks def test_no_message_sent_without_id(self): yield self.createReporter() build = yield self.setupBuildResults() self.sp.send(build, 'new') assert not self.sp.session.post.called @defer.inlineCallbacks def test_private_message_sent_with_user_id(self): token = 'tok' endpoint = 'example.com' yield self.createReporter(auth_token=token, endpoint=endpoint) self.sp.getBuildDetailsAndSendMessage = Mock() message = {'message': 'hi'} postData = dict(message) postData.update({'id_or_email': '123'}) self.sp.getBuildDetailsAndSendMessage.return_value = postData self.sp.send({}, 'test') expected = [ call('%s/v2/user/123/message?auth_token=%s' % (endpoint, token), message)] self.assertEqual(self.sp.session.post.mock_calls, expected) @defer.inlineCallbacks def test_room_message_sent_with_room_id(self): token = 'tok' endpoint = 'example.com' yield self.createReporter(auth_token=token, endpoint=endpoint) self.sp.getBuildDetailsAndSendMessage = Mock() message = {'message': 'hi'} postData = dict(message) postData.update({'room_id_or_name': '123'}) self.sp.getBuildDetailsAndSendMessage.return_value = postData self.sp.send({}, 'test') expected = [ call('%s/v2/room/123/notification?auth_token=%s' % (endpoint, token), message)] self.assertEqual(self.sp.session.post.mock_calls, expected) @defer.inlineCallbacks def test_private_and_room_message_sent_with_both_ids(self): token = 'tok' endpoint = 'example.com' yield self.createReporter(auth_token=token, endpoint=endpoint) self.sp.getBuildDetailsAndSendMessage = Mock() message = {'message': 'hi'} postData = dict(message) postData.update({'room_id_or_name': '123', 'id_or_email': '456'}) self.sp.getBuildDetailsAndSendMessage.return_value = postData self.sp.send({}, 'test') expected = [call( '%s/v2/user/456/message?auth_token=%s' % (endpoint, token), message), call('%s/v2/room/123/notification?auth_token=%s' % (endpoint, token), message)] self.assertEqual(self.sp.session.post.mock_calls, expected) @defer.inlineCallbacks def test_postData_values_passed_through(self): token = 'tok' endpoint = 'example.com' yield self.createReporter(auth_token=token, endpoint=endpoint) self.sp.getBuildDetailsAndSendMessage = Mock() message = {'message': 'hi', 'notify': True, 'message_format': 'html'} postData = dict(message) postData.update({'id_or_email': '123'}) self.sp.getBuildDetailsAndSendMessage.return_value = postData self.sp.send({}, 'test') expected = [ call('%s/v2/user/123/message?auth_token=%s' % (endpoint, token), message)] self.assertEqual(self.sp.session.post.mock_calls, expected)
class TestHipchatStatusPush(unittest.TestCase, ReporterTestMixin): def setUp(self): # ignore config error if txrequests is not installed config._errors = Mock() self.master = fakemaster.make_master(testcase=self, wantData=True, wantDb=True, wantMq=True) @defer.inlineCallbacks def tearDown(self): yield self.sp.stopService() self.assertEqual(self.sp.session.close.call_count, 1) config._errors = None @defer.inlineCallbacks def createReporter(self, **kwargs): kwargs['auth_token'] = kwargs.get('auth_token', 'abc') self.sp = HipChatStatusPush(**kwargs) self.sp.sessionFactory = Mock(return_value=Mock()) yield self.sp.setServiceParent(self.master) yield self.sp.startService() @defer.inlineCallbacks def setupBuildResults(self): self.insertTestData([SUCCESS], SUCCESS) build = yield self.master.data.get(("builds", 20)) defer.returnValue(build) @defer.inlineCallbacks def test_authtokenTypeCheck(self): yield self.createReporter(auth_token=2) config._errors.addError.assert_any_call('auth_token must be a string') @defer.inlineCallbacks def test_endpointTypeCheck(self): yield self.createReporter(endpoint=2) config._errors.addError.assert_any_call('endpoint must be a string') @defer.inlineCallbacks def test_builderRoomMapTypeCheck(self): yield self.createReporter(builder_room_map=2) config._errors.addError.assert_any_call( 'builder_room_map must be a dict') @defer.inlineCallbacks def test_builderUserMapTypeCheck(self): yield self.createReporter(builder_user_map=2) config._errors.addError.assert_any_call( 'builder_user_map must be a dict') @defer.inlineCallbacks def test_build_started(self): yield self.createReporter(builder_user_map={'Builder0': '123'}) build = yield self.setupBuildResults() self.sp.buildStarted(('build', 20, 'new'), build) expected = [ call( 'https://api.hipchat.com/v2/user/123/message?auth_token=abc', { 'message': 'Buildbot started build Builder0 here: http://localhost:8080/#builders/79/builds/0' }) ] self.assertEqual(self.sp.session.post.mock_calls, expected) @defer.inlineCallbacks def test_build_finished(self): yield self.createReporter(builder_room_map={'Builder0': '123'}) build = yield self.setupBuildResults() self.sp.buildFinished(('build', 20, 'finished'), build) expected = [ call( 'https://api.hipchat.com/v2/room/123/notification?auth_token=abc', { 'message': 'Buildbot finished build Builder0 with result success ' 'here: http://localhost:8080/#builders/79/builds/0' }) ] self.assertEqual(self.sp.session.post.mock_calls, expected) @defer.inlineCallbacks def test_inject_extra_params(self): yield self.createReporter(builder_room_map={'Builder0': '123'}) self.sp.getExtraParams = Mock() self.sp.getExtraParams.return_value = {'format': 'html'} build = yield self.setupBuildResults() self.sp.buildFinished(('build', 20, 'finished'), build) expected = [ call( 'https://api.hipchat.com/v2/room/123/notification?auth_token=abc', { 'message': 'Buildbot finished build Builder0 with result success ' 'here: http://localhost:8080/#builders/79/builds/0', 'format': 'html' }) ] self.assertEqual(self.sp.session.post.mock_calls, expected) @defer.inlineCallbacks def test_no_message_sent_empty_message(self): yield self.createReporter() build = yield self.setupBuildResults() self.sp.send(build, 'unknown') assert not self.sp.session.post.called @defer.inlineCallbacks def test_no_message_sent_without_id(self): yield self.createReporter() build = yield self.setupBuildResults() self.sp.send(build, 'new') assert not self.sp.session.post.called @defer.inlineCallbacks def test_private_message_sent_with_user_id(self): token = 'tok' endpoint = 'example.com' yield self.createReporter(auth_token=token, endpoint=endpoint) self.sp.getBuildDetailsAndSendMessage = Mock() message = {'message': 'hi'} postData = dict(message) postData.update({'id_or_email': '123'}) self.sp.getBuildDetailsAndSendMessage.return_value = postData self.sp.send({}, 'test') expected = [ call('%s/v2/user/123/message?auth_token=%s' % (endpoint, token), message) ] self.assertEqual(self.sp.session.post.mock_calls, expected) @defer.inlineCallbacks def test_room_message_sent_with_room_id(self): token = 'tok' endpoint = 'example.com' yield self.createReporter(auth_token=token, endpoint=endpoint) self.sp.getBuildDetailsAndSendMessage = Mock() message = {'message': 'hi'} postData = dict(message) postData.update({'room_id_or_name': '123'}) self.sp.getBuildDetailsAndSendMessage.return_value = postData self.sp.send({}, 'test') expected = [ call( '%s/v2/room/123/notification?auth_token=%s' % (endpoint, token), message) ] self.assertEqual(self.sp.session.post.mock_calls, expected) @defer.inlineCallbacks def test_private_and_room_message_sent_with_both_ids(self): token = 'tok' endpoint = 'example.com' yield self.createReporter(auth_token=token, endpoint=endpoint) self.sp.getBuildDetailsAndSendMessage = Mock() message = {'message': 'hi'} postData = dict(message) postData.update({'room_id_or_name': '123', 'id_or_email': '456'}) self.sp.getBuildDetailsAndSendMessage.return_value = postData self.sp.send({}, 'test') expected = [ call('%s/v2/user/456/message?auth_token=%s' % (endpoint, token), message), call( '%s/v2/room/123/notification?auth_token=%s' % (endpoint, token), message) ] self.assertEqual(self.sp.session.post.mock_calls, expected) @defer.inlineCallbacks def test_postData_values_passed_through(self): token = 'tok' endpoint = 'example.com' yield self.createReporter(auth_token=token, endpoint=endpoint) self.sp.getBuildDetailsAndSendMessage = Mock() message = {'message': 'hi', 'notify': True, 'message_format': 'html'} postData = dict(message) postData.update({'id_or_email': '123'}) self.sp.getBuildDetailsAndSendMessage.return_value = postData self.sp.send({}, 'test') expected = [ call('%s/v2/user/123/message?auth_token=%s' % (endpoint, token), message) ] self.assertEqual(self.sp.session.post.mock_calls, expected)