Repository: Dan6erbond/Banhammer.py (language: python)

Issue:
[FEATURE] Make RedditItem.reactions Property
Replace the `get_reactions()` method with an auto-property for easier access.


Discussion / hints:

Fix patch:
diff --git a/banhammer/models/item.py b/banhammer/models/item.py
index 3d1ac78..688df0b 100644
--- a/banhammer/models/item.py
+++ b/banhammer/models/item.py
@@ -84,11 +84,12 @@ async def get_author_name(self):
             else:
                 return author["name"]
 
-    def get_reactions(self):
+    @property
+    def reactions(self):
         return self.subreddit.get_reactions(self.item)
 
     async def add_reactions(self, message: discord.Message):
-        for r in self.get_reactions():
+        for r in self.reactions:
             try:
                 await message.add_reaction(r.emoji)
             except Exception as e:


Test patch:
diff --git a/tests/models/test_item.py b/tests/models/test_item.py
index 60cec62..ac02809 100644
--- a/tests/models/test_item.py
+++ b/tests/models/test_item.py
@@ -80,7 +80,7 @@ async def test_get_author_name(self, reddit: apraw.Reddit, subreddit: Subreddit)
             assert author_name.lower() == author.name.lower()
 
     @pytest.mark.asyncio
-    async def test_get_reactions(self, reddit: apraw.Reddit, subreddit: Subreddit):
+    async def test_item_reactions(self, reddit: apraw.Reddit, subreddit: Subreddit):
         await subreddit.load_reactions()
 
         sub = await reddit.subreddit("banhammerdemo")
@@ -91,7 +91,7 @@ async def test_get_reactions(self, reddit: apraw.Reddit, subreddit: Subreddit):
             break
 
         if item:
-            for r in item.get_reactions():
+            for r in item.reactions:
                 assert isinstance(r, Reaction)
 
     @pytest.mark.asyncio
@@ -106,10 +106,10 @@ async def test_get_reaction(self, reddit: apraw.Reddit, subreddit: Subreddit):
             break
 
         if item:
-            emojis = [r.emoji for r in item.get_reactions()]
+            emojis = [r.emoji for r in item.reactions]
             if emojis:
                 reaction = item.get_reaction(emojis[0])
-                assert reaction == item.get_reactions()[0]
+                assert reaction == item.reactions[0]
 
     @pytest.mark.asyncio
     async def test_url(self, reddit: apraw.Reddit, subreddit: Subreddit):