diff options
author | John L. Villalovos <john@sodarock.com> | 2021-11-30 08:35:58 -0800 |
---|---|---|
committer | John L. Villalovos <john@sodarock.com> | 2021-11-30 08:35:58 -0800 |
commit | 1839c9e7989163a5cc9a201241942b7faca6e214 (patch) | |
tree | f6fcb4f19fb62e6db8234a6f96d367ec093cab27 /tests | |
parent | 09a973ee379d82af05a5080decfaec16d2f4eab3 (diff) | |
download | gitlab-jlvillal/attribute_help.tar.gz |
chore: attempt to be more informative for missing attributesjlvillal/attribute_help
A commonly reported issue from users on Gitter is that they get an
AttributeError for an attribute that should be present. This is often
caused due to the fact that they used the `list()` method to retrieve
the object and objects retrieved this way often only have a subset of
the full data.
Add more details in the AttributeError message that explains the
situation to users. This will hopefully allow them to resolve the
issue.
Update the FAQ in the docs to add a section discussing the issue.
Closes #1138
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/test_base.py | 24 |
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 |