diff --git a/Shitpost.py b/Shitpost.py index 4ac8781..55e0986 100644 --- a/Shitpost.py +++ b/Shitpost.py @@ -861,15 +861,8 @@ class Shitpost(commands.Cog): except: print("No permission to delete message") yield from ctx.channel.send(message) - - @commands.command(pass_context=True) - @asyncio.coroutine - def review(self, ctx, *args): - """Stroop heeft (bijna) overal een mening over. Vraag het hem! - """ - - topic = " ".join(args) + def get_review_string(self, topic = ""): if topic == "": random.seed(datetime.now()) else: @@ -916,6 +909,15 @@ class Shitpost(commands.Cog): emoj = random.choice(EMOJI) message += str(rating) + " " + emoj*rating + " out of " + str(maxRating) + "." + return message + + @commands.command(pass_context=True) + @asyncio.coroutine + def review(self, ctx, *args): + """Stroop heeft (bijna) overal een mening over. Vraag het hem! + """ + topic = " ".join(args) + message = self.get_review_string(topic) yield from ctx.channel.send(message) diff --git a/tests/__init__.py b/tests/__init__.py index ac22dce..8d7ef16 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1 +1,2 @@ +from .shitpost import TestShitpost from .general import TestGeneral \ No newline at end of file diff --git a/tests/shitpost.py b/tests/shitpost.py new file mode 100644 index 0000000..f9e6a89 --- /dev/null +++ b/tests/shitpost.py @@ -0,0 +1,27 @@ +import unittest +import dotenv +import discord +from discord.ext import commands + +import Shitpost + +class TestShitpost(unittest.TestCase): + def setUp(self): + dotenv.load_dotenv() + intents = discord.Intents.default() + intents.message_content = True + intents.members = True + bot = commands.Bot(command_prefix=commands.when_mentioned_or('!'), description='Stroopwafel. Shitpost bot extraordinaire.', pm_help=True, intents=intents) + self.cog = Shitpost.Shitpost(bot) + + def test_review(self): + TOPIC = "qpwoeirut12" + topic_review = self.cog.get_review_string(TOPIC) + with self.subTest(msg=f"Topic review does not return a string"): + self.assertIsInstance(topic_review, str) + with self.subTest(msg=f"Topic review does not contain the topic"): + self.assertIn(TOPIC, topic_review) + + basic_review = self.cog.get_review_string() + with self.subTest(msg=f"Review does not return a string"): + self.assertIsInstance(basic_review, str) \ No newline at end of file