File: test_exceptions.py

package info (click to toggle)
python-gitlab 1%3A4.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,048 kB
  • sloc: python: 24,168; makefile: 171; ruby: 27; javascript: 3
file content (30 lines) | stat: -rw-r--r-- 800 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import pytest

from gitlab import exceptions


@pytest.mark.parametrize(
    "kwargs,expected",
    [
        ({"error_message": "foo"}, "foo"),
        ({"error_message": "foo", "response_code": "400"}, "400: foo"),
    ],
)
def test_gitlab_error(kwargs, expected):
    error = exceptions.GitlabError(**kwargs)
    assert str(error) == expected


def test_error_raises_from_http_error():
    """Methods decorated with @on_http_error should raise from GitlabHttpError."""

    class TestError(Exception):
        pass

    @exceptions.on_http_error(TestError)
    def raise_error_from_http_error():
        raise exceptions.GitlabHttpError

    with pytest.raises(TestError) as context:
        raise_error_from_http_error()
    assert isinstance(context.value.__cause__, exceptions.GitlabHttpError)