def test_gitlab_api_delete_webhook(m_gitlab, app): class MockHooksManager: def delete(self, hook_id): assert hook_id == 12345 class MockBranchManager: def get(self, name): m = Mock(commit=dict(id='mybranchsha')) m.name = 'mybranch' return m class MockProjectManager: def get(self, name, lazy): return Mock(branches=MockBranchManager(), hooks=MockHooksManager(), id='123') m_gitlab.return_value = Mock(projects=MockProjectManager()) api = GitlabAPI('gitlab.cern.ch', 'owner_name', 'myrepository', 'mybranch') api.delete_webhook(12345)
def test_gitlab_api_delete_webhook_when_no_permission_to_webhook_raises_GitObjectNotFound( m_gitlab, app): class MockHooksManager: def delete(self, hook_id): raise GitlabAuthenticationError('Unauthorized', 401) class MockBranchManager: def get(self, name): m = Mock(commit=dict(id='mybranchsha')) m.name = 'mybranch' return m class MockProjectManager: def get(self, name, lazy): return Mock(branches=MockBranchManager(), hooks=MockHooksManager(), id='123') m_gitlab.return_value = Mock(projects=MockProjectManager()) api = GitlabAPI('gitlab.cern.ch', 'owner_name', 'myrepository', 'mybranch') with raises(GitObjectNotFound): api.delete_webhook(1245)