diff --git a/core/config.py b/core/config.py index 137d7be30..159d88b13 100644 --- a/core/config.py +++ b/core/config.py @@ -118,17 +118,29 @@ class Group(Value): return not isinstance(default, dict) - def get_attr(self, item: str, default=None): + def get_attr(self, item: str, default=None, resolve=True): """ You should avoid this function whenever possible. :param item: :param default: + :param resolve: + If this is True, actual data will be returned, if false a Group/Value will be returned. :return: """ value = getattr(self, item) - return value(default=default) + if resolve: + return value(default=default) + else: + return value def all(self) -> dict: + """ + Gets all data from current User/Member/Guild etc. + :return: + """ + return self() + + def all_from_kind(self) -> dict: """ Gets all entries of the given kind. If this kind is member then this method returns all members from the same diff --git a/tests/core/test_config.py b/tests/core/test_config.py index 8db6176c8..2e34218c3 100644 --- a/tests/core/test_config.py +++ b/tests/core/test_config.py @@ -278,12 +278,20 @@ async def test_member_clear_all(config, member_factory): # Get All testing @pytest.mark.asyncio -async def test_user_get_all(config, user_factory): +async def test_user_get_all_from_kind(config, user_factory): for _ in range(5): user = user_factory.get() await config.user(user).foo.set(True) user = user_factory.get() - all_data = config.user(user).all() + all_data = config.user(user).all_from_kind() assert len(all_data) == 5 + + +@pytest.mark.asyncio +async def test_user_getalldata(config, user_factory): + user = user_factory.get() + await config.user(user).foo.set(False) + + assert "foo" in config.user(user).all()