diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/functional/api/test_users.py | 4 | ||||
-rw-r--r-- | tests/meta/test_ensure_type_hints.py | 15 | ||||
-rw-r--r-- | tests/unit/test_base.py | 11 |
3 files changed, 23 insertions, 7 deletions
diff --git a/tests/functional/api/test_users.py b/tests/functional/api/test_users.py index 1ef237c..a21298e 100644 --- a/tests/functional/api/test_users.py +++ b/tests/functional/api/test_users.py @@ -33,7 +33,9 @@ def test_create_user(gl, avatar_path): def test_block_user(gl, user): - user.block() + result = user.block() + result = user.block() + assert result == "dkdkdkdk" users = gl.users.list(blocked=True) assert user in users diff --git a/tests/meta/test_ensure_type_hints.py b/tests/meta/test_ensure_type_hints.py index 2449324..0de9af2 100644 --- a/tests/meta/test_ensure_type_hints.py +++ b/tests/meta/test_ensure_type_hints.py @@ -7,7 +7,7 @@ Original notes by John L. Villalovos import dataclasses import functools import inspect -from typing import Optional, Type +from typing import Optional, Type, Union, TYPE_CHECKING import _pytest @@ -19,7 +19,7 @@ import gitlab.v4.objects @dataclasses.dataclass(frozen=True) class ClassInfo: name: str - type: Type + type: Type[Union[gitlab.mixins.GetMixin, gitlab.mixins.GetWithoutIdMixin]] def __lt__(self, other: object) -> bool: if not isinstance(other, ClassInfo): @@ -108,7 +108,7 @@ class TestTypeHints: def get_check_helper( self, *, - base_type: Type, + base_type: Type[Union[gitlab.mixins.GetMixin, gitlab.mixins.GetWithoutIdMixin]], class_info: ClassInfo, method_template: str, optional_return: bool, @@ -121,6 +121,11 @@ class TestTypeHints: return obj_cls = class_info.type._obj_cls + if TYPE_CHECKING: + assert obj_cls is not None + assert issubclass( + obj_cls, (gitlab.mixins.GetMixin, gitlab.mixins.GetWithoutIdMixin) + ) signature = inspect.signature(class_info.type.get) filename = inspect.getfile(class_info.type) @@ -131,7 +136,9 @@ class TestTypeHints: f"Recommend adding the followinng method:\n" ) fail_message += method_template.format(obj_cls=obj_cls) - check_type = obj_cls + check_type: Optional[ + Type[Union[gitlab.mixins.GetMixin, gitlab.mixins.GetWithoutIdMixin]] + ] = obj_cls if optional_return: check_type = Optional[obj_cls] assert check_type == signature.return_annotation, fail_message diff --git a/tests/unit/test_base.py b/tests/unit/test_base.py index 137f480..902d9b4 100644 --- a/tests/unit/test_base.py +++ b/tests/unit/test_base.py @@ -117,8 +117,8 @@ class TestRESTObject: obj.id = 42 assert 42 == obj.get_id() - obj.id = None - assert obj.get_id() is None + obj.id = "hello" + assert "hello" == obj.get_id() def test_custom_id_attr(self, fake_manager): class OtherFakeObject(FakeObject): @@ -127,6 +127,13 @@ class TestRESTObject: obj = OtherFakeObject(fake_manager, {"foo": "bar"}) assert "bar" == obj.get_id() + def test_custom_id_attr_missing(self, fake_manager): + class OtherFakeObject(FakeObject): + _id_attr = "spam" + + obj = OtherFakeObject(fake_manager, {"foo": "bar"}) + assert obj.get_id() is None + def test_update_attrs(self, fake_manager): obj = FakeObject(fake_manager, {"foo": "bar"}) obj.bar = "baz" |