def test_gitlab_api_ping_webhook(m_get_branch_and_sha, m_gitlab):
    class MockHooksManager:
        def get(self, id):
            assert id == 123
            return Mock(id=123)

    class MockProjectManager:
        def get(self, name, lazy):
            return Mock(hooks=MockHooksManager())

    m_gitlab.return_value = Mock(projects=MockProjectManager())

    api = GitlabAPI('gitlab.com', 'owner', 'repository', 'my-branch')

    api.ping_webhook(123)
def test_gitlab_api_ping_webhook_when_user_have_no_permission_raises_GitObjectNotFound(
        m_get_branch_and_sha, m_gitlab):
    class MockHooksManager:
        def get(self, id):
            raise GitlabAuthenticationError('Unauthorized', 401)

    class MockProjectManager:
        def get(self, name, lazy):
            return Mock(hooks=MockHooksManager())

    m_gitlab.return_value = Mock(projects=MockProjectManager())

    api = GitlabAPI('gitlab.com', 'owner', 'repository')

    with raises(GitObjectNotFound):
        api.ping_webhook(123)
def test_gitlab_api_ping_webhook_when_hook_doesnt_exist_raises_GitObjectNotFound(
        m_get_branch_and_sha, m_gitlab):
    class MockHooksManager:
        def get(self, id):
            raise GitlabGetError('Not Found', 404)

    class MockProjectManager:
        def get(self, name, lazy):
            return Mock(hooks=MockHooksManager())

    m_gitlab.return_value = Mock(projects=MockProjectManager())

    api = GitlabAPI('gitlab.com', 'owner', 'repository')

    with raises(GitObjectNotFound):
        api.ping_webhook(123)