def test_ensure_webhook_replace(self): testee = BridgeProviderBitbucket({ 'username': '******', 'password': '******', 'incoming_token': 'glig', }) dest=MagicMock() def replacement_api(version,url,form_data={},method=None,request_type=None): if url.endswith('hooks/'): return [{ 'uuid': 1, 'url': 'http://me.com/bla', 'description': 'Greg2', 'skip_cert_verification': False, 'active': True, 'events': [u'pullrequest:comment_created', u'repo:push'], }] else: return dest(version,url,form_data=form_data,method=method,request_type=request_type) testee.api = replacement_api testee.ensure_webhook('on','aboat','http://me.com') dest.assert_called_once_with('2.0','repositories/on/aboat/hooks/1',form_data={ 'url': 'http://me.com', 'description': 'Greg2', 'skip_cert_verification': False, 'active': True, 'events': [u'pullrequest:comment_created', u'repo:push'], },method='PUT',request_type='json')
def test_ensure_webhook_remove(self): testee = BridgeProviderBitbucket({ 'username': '******', 'password': '******', 'incoming_token': 'glig', }) dest = MagicMock() def replacement_api(*args, **kwargs): if args[1].endswith('hooks/'): return [{ 'uuid': 1, 'url': 'http://me.com/bla', 'description': 'Greg2', 'skip_cert_verification': False, 'active': True, 'events': [u'pullrequest:comment_created', u'repo:push'], }, { 'uuid': 2, 'url': 'http://me.com/', 'description': 'Grog2', 'skip_cert_verification': False, 'active': True, 'events': [u'pullrequest:comment_created', u'repo:push'], }] else: return dest(*args, **kwargs) testee.api = replacement_api testee.ensure_webhook('on', 'aboat', 'http://me.com') dest.assert_any_call('2.0', 'repositories/on/aboat/hooks/1', method='DELETE') dest.assert_any_call('2.0', 'repositories/on/aboat/hooks/2', method='DELETE') dest.assert_any_call( '2.0', 'repositories/on/aboat/hooks', form_data={ 'url': 'http://me.com', 'description': 'Greg2', 'skip_cert_verification': False, 'active': True, 'events': [u'pullrequest:comment_created', u'repo:push'], }, method='POST', request_type='json') self.assertEquals(dest.call_count, 3)
def test_ensure_webhook_replace(self): testee = BridgeProviderBitbucket({ 'username': '******', 'password': '******', 'incoming_token': 'glig', }) dest = MagicMock() def replacement_api(version, url, form_data={}, method=None, request_type=None): if url.endswith('hooks/'): return [{ 'uuid': 1, 'url': 'http://me.com/bla', 'description': 'Greg2', 'skip_cert_verification': False, 'active': True, 'events': [u'pullrequest:comment_created', u'repo:push'], }] else: return dest(version, url, form_data=form_data, method=method, request_type=request_type) testee.api = replacement_api testee.ensure_webhook('on', 'aboat', 'http://me.com') dest.assert_called_once_with( '2.0', 'repositories/on/aboat/hooks/1', form_data={ 'url': 'http://me.com', 'description': 'Greg2', 'skip_cert_verification': False, 'active': True, 'events': [u'pullrequest:comment_created', u'repo:push'], }, method='PUT', request_type='json')
def test_ensure_webhook_remove(self): testee = BridgeProviderBitbucket({ 'username': '******', 'password': '******', 'incoming_token': 'glig', }) dest=MagicMock() def replacement_api(*args, **kwargs): if args[1].endswith('hooks/'): return [ { 'uuid': 1, 'url': 'http://me.com/bla', 'description': 'Greg2', 'skip_cert_verification': False, 'active': True, 'events': [u'pullrequest:comment_created', u'repo:push'], }, { 'uuid': 2, 'url': 'http://me.com/', 'description': 'Grog2', 'skip_cert_verification': False, 'active': True, 'events': [u'pullrequest:comment_created', u'repo:push'], } ] else: return dest(*args, **kwargs) testee.api = replacement_api testee.ensure_webhook('on','aboat','http://me.com') dest.assert_any_call('2.0','repositories/on/aboat/hooks/1',method='DELETE') dest.assert_any_call('2.0','repositories/on/aboat/hooks/2',method='DELETE') dest.assert_any_call('2.0','repositories/on/aboat/hooks',form_data={ 'url': 'http://me.com', 'description': 'Greg2', 'skip_cert_verification': False, 'active': True, 'events': [u'pullrequest:comment_created', u'repo:push'], },method='POST',request_type='json') self.assertEquals(dest.call_count,3)