import unittest import configparser import praw import random import requests import json import discord from discord.ext import commands import General class TestGeneral(unittest.TestCase): def setUp(self): config = configparser.ConfigParser() config.read('stroopwafel.ini') self.tokens = config["tokens"] self.r = praw.Reddit( user_agent='StroopwafelBot', client_secret=self.tokens["redditSecret"], client_id=self.tokens["redditId"] ) self.r.read_only = True 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) bot.tokens = self.tokens self.cog = General.General(bot) def test_aww(self): # Duplicate code is tijdelijk!!!11one raww = self.r.subreddit('aww+catloaf+tuckedinkitties+babyelephantgifs+babybigcatgifs+blep+holdmynip+gingerkitty+cathighfive+catsstandingup+catsareassholes+eyebleach') post = raww.top('month', limit=250) listing = list(post) random.shuffle(listing) post = listing[0] print(post) self.assertIsInstance(post,praw.models.Submission) def test_playlist(self): data = self.cog.get_playlist_json() with self.subTest(msg="Reddit doesn't return 200"): self.assertEqual(data.status_code, 200) with self.subTest(msg="Not a good response"): self.assertIsInstance(data, requests.Response) with self.subTest(msg="Does not convert to json"): self.assertIsInstance(json.loads(data.content), dict)