Bye bye generators.
This commit is contained in:
parent
16fd773435
commit
fd2c47da45
@ -111,8 +111,7 @@ class Api:
|
|||||||
obj = await response.json()
|
obj = await response.json()
|
||||||
if not obj.get("success"):
|
if not obj.get("success"):
|
||||||
return
|
return
|
||||||
for result in obj.get("results", []):
|
return obj.get("results", [])
|
||||||
yield result
|
|
||||||
|
|
||||||
async def get_rant(self, id):
|
async def get_rant(self, id):
|
||||||
response = None
|
response = None
|
||||||
@ -133,8 +132,8 @@ class Api:
|
|||||||
obj = await response.json()
|
obj = await response.json()
|
||||||
if not obj.get("success"):
|
if not obj.get("success"):
|
||||||
return
|
return
|
||||||
for rant in obj.get("rants", []):
|
return obj.get("rants", [])
|
||||||
yield rant
|
|
||||||
|
|
||||||
async def get_user_id(self, username):
|
async def get_user_id(self, username):
|
||||||
response = None
|
response = None
|
||||||
@ -150,9 +149,7 @@ class Api:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
async def mentions(self):
|
async def mentions(self):
|
||||||
async for notif in self.notifs:
|
return [notif for notif in (await self.notifs) if notif['type'] == "comment_mention"]
|
||||||
if notif["type"] == "comment_mention":
|
|
||||||
yield notif
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
async def notifs(self):
|
async def notifs(self):
|
||||||
@ -163,5 +160,5 @@ class Api:
|
|||||||
response = await session.get(
|
response = await session.get(
|
||||||
url=self.patch_url("users/me/notif-feed"), params=self.patch_auth()
|
url=self.patch_url("users/me/notif-feed"), params=self.patch_auth()
|
||||||
)
|
)
|
||||||
for item in (await response.json()).get("data", {}).get("items", []):
|
return (await response.json()).get("data", {}).get("items", [])
|
||||||
yield item
|
|
||||||
|
@ -8,20 +8,11 @@ class ApiTestCase(unittest.IsolatedAsyncioTestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.api = Api()
|
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):
|
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):
|
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):
|
async def test_get_user_id(self):
|
||||||
self.assertTrue(await self.api.get_user_id("retoor"))
|
self.assertTrue(await self.api.get_user_id("retoor"))
|
||||||
|
Loading…
Reference in New Issue
Block a user