diff --git a/src/devranta/api.py b/src/devranta/api.py index 8e529c3..227f56e 100644 --- a/src/devranta/api.py +++ b/src/devranta/api.py @@ -111,8 +111,7 @@ class Api: obj = await response.json() if not obj.get("success"): return - for result in obj.get("results", []): - yield result + return obj.get("results", []) async def get_rant(self, id): response = None @@ -133,8 +132,8 @@ class Api: obj = await response.json() if not obj.get("success"): return - for rant in obj.get("rants", []): - yield rant + return obj.get("rants", []) + async def get_user_id(self, username): response = None @@ -150,9 +149,7 @@ class Api: @property async def mentions(self): - async for notif in self.notifs: - if notif["type"] == "comment_mention": - yield notif + return [notif for notif in (await self.notifs) if notif['type'] == "comment_mention"] @property async def notifs(self): @@ -163,5 +160,5 @@ class Api: response = await session.get( url=self.patch_url("users/me/notif-feed"), params=self.patch_auth() ) - for item in (await response.json()).get("data", {}).get("items", []): - yield item + return (await response.json()).get("data", {}).get("items", []) + diff --git a/src/devranta/tests.py b/src/devranta/tests.py index e8ec7fb..123dcf6 100644 --- a/src/devranta/tests.py +++ b/src/devranta/tests.py @@ -8,20 +8,11 @@ class ApiTestCase(unittest.IsolatedAsyncioTestCase): def setUp(self): self.api = Api() - async def async_list(self, generator): - list_ = [] - async for v in generator: - list_.append(v) - return list_ - - async def async_len(self, generator): - return len(await self.async_list(generator)) - async def test_get_rants(self): - self.assertTrue(await self.async_len(self.api.get_rants())) + self.assertTrue(len(await self.api.get_rants())) async def test_search(self): - self.assertTrue(await self.async_len(self.api.search("retoor"))) + self.assertTrue(len(await self.api.search("retoor"))) async def test_get_user_id(self): self.assertTrue(await self.api.get_user_id("retoor"))