summaryrefslogtreecommitdiff
path: root/tests/unit
diff options
context:
space:
mode:
authorNejc Habjan <hab.nejc@gmail.com>2021-12-01 01:32:57 +0100
committerGitHub <noreply@github.com>2021-12-01 01:32:57 +0100
commit387e59fda12c5b6608b1e59b8d79239891c32252 (patch)
tree8dea7b96de5bb85f9ebe7c1b1063cfd9991c5453 /tests/unit
parente6582a37a691880a69a75a347389eb4e4e95b20e (diff)
parent1839c9e7989163a5cc9a201241942b7faca6e214 (diff)
downloadgitlab-387e59fda12c5b6608b1e59b8d79239891c32252.tar.gz
Merge pull request #1702 from python-gitlab/jlvillal/attribute_help
chore: attempt to be more informative for missing attributes
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/test_base.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/unit/test_base.py b/tests/unit/test_base.py
index 137f480..3ca0206 100644
--- a/tests/unit/test_base.py
+++ b/tests/unit/test_base.py
@@ -90,6 +90,30 @@ class TestRESTObject:
with pytest.raises(gitlab.exceptions.GitlabParsingError):
FakeObject(fake_manager, ["a", "list", "fails"])
+ def test_missing_attribute_does_not_raise_custom(self, fake_gitlab, fake_manager):
+ """Ensure a missing attribute does not raise our custom error message
+ if the RESTObject was not created from a list"""
+ obj = FakeObject(manager=fake_manager, attrs={"foo": "bar"})
+ with pytest.raises(AttributeError) as excinfo:
+ obj.missing_attribute
+ exc_str = str(excinfo.value)
+ assert "missing_attribute" in exc_str
+ assert "was created via a list()" not in exc_str
+ assert base._URL_ATTRIBUTE_ERROR not in exc_str
+
+ def test_missing_attribute_from_list_raises_custom(self, fake_gitlab, fake_manager):
+ """Ensure a missing attribute raises our custom error message if the
+ RESTObject was created from a list"""
+ obj = FakeObject(
+ manager=fake_manager, attrs={"foo": "bar"}, created_from_list=True
+ )
+ with pytest.raises(AttributeError) as excinfo:
+ obj.missing_attribute
+ exc_str = str(excinfo.value)
+ assert "missing_attribute" in exc_str
+ assert "was created via a list()" in exc_str
+ assert base._URL_ATTRIBUTE_ERROR in exc_str
+
def test_picklability(self, fake_manager):
obj = FakeObject(fake_manager, {"foo": "bar"})
original_obj_module = obj._module