117 lines
4.3 KiB
Python
117 lines
4.3 KiB
Python
import unittest
|
|
import dotenv
|
|
import os
|
|
import discord
|
|
import requests
|
|
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)
|
|
|
|
def test_watspelenwe_sass(self):
|
|
once = self.cog.get_watspelenwe_sass()
|
|
twice = self.cog.get_watspelenwe_sass()
|
|
with self.subTest(msg="Watspelenwe does not seed correctly"):
|
|
self.assertEqual(once, twice)
|
|
with self.subTest(msg="Watspelenwe does not return a string"):
|
|
self.assertIsInstance(once, str)
|
|
|
|
def test_watspelenwe_cal(self):
|
|
data = requests.get(os.getenv('STROOP_CALDAV_CAL'))
|
|
if not data:
|
|
self.skipTest(f"Server at {self.cog.muzak_url} has an error, or is unavailable")
|
|
|
|
(activiteit, reden) = self.cog.get_watspelenwe_cal()
|
|
with self.subTest(msg="Watspelenwe activiteit does not return a string"):
|
|
self.assertIsInstance(activiteit, str)
|
|
with self.subTest(msg="Watspelenwe reden does not return a string"):
|
|
self.assertIsInstance(reden, str)
|
|
|
|
def test_ktdm(self):
|
|
with self.subTest():
|
|
wit = ["qwerty", "yuiop"]
|
|
kaart = self.cog.get_ktdm(wit)
|
|
self.assertIn(wit[0], kaart)
|
|
self.assertIn(wit[1], kaart)
|
|
with self.subTest():
|
|
wit = ["a", "b", "c", "d"]
|
|
kaart = self.cog.get_ktdm(wit)
|
|
self.assertEqual(kaart, None)
|
|
with self.subTest():
|
|
wit = ["a", "b", "c"]
|
|
self.cog.zwarte_lijst = ["___"]
|
|
kaart = self.cog.get_ktdm(wit)
|
|
self.assertEqual(kaart, None)
|
|
|
|
def test_weer(self):
|
|
data = requests.get("http://weerlive.nl/api/json-data-10min.php")
|
|
if not data:
|
|
self.skipTest(f"Weerlive has an error, or is unavailable")
|
|
weerJson = self.cog.get_weer_json()
|
|
with self.subTest("Weer does not correctly convert from json"):
|
|
self.assertIsInstance(weerJson, dict)
|
|
|
|
icon = self.cog.getWeatherIconTranslation(weerJson["d2weer"])
|
|
with self.subTest("Weericon not available"):
|
|
self.assertNotEqual(icon, ":park:")
|
|
with self.subTest("Weericon incorrect"):
|
|
self.assertRegex(icon, ":[A-z]+:")
|
|
with self.subTest("No weericon for unknown weather"):
|
|
icon = self.cog.getWeatherIconTranslation("sniezelig") # Bestaat niet natuurlijk
|
|
self.assertRegex(icon, ":[A-z]+:")
|
|
|
|
bbq = self.cog.getBbqGrade(weerJson)
|
|
with self.subTest("BBQ cijfer incorrect"):
|
|
self.assertIsInstance(bbq, float)
|
|
self.assertGreaterEqual(bbq, 1.0)
|
|
self.assertLessEqual(bbq, 10.0)
|
|
|
|
with self.subTest("False positive alarm"):
|
|
weerMock = { "alarm": 0}
|
|
alertCode, alertMessage = self.cog.getWeerAlarm(weerMock)
|
|
self.assertEqual(alertCode, None)
|
|
self.assertEqual(alertMessage, "")
|
|
with self.subTest("False negative rood alarm"):
|
|
weerMock = { "alarm": "1", "alarmtxt": "qwerty code rood yuiop"}
|
|
alertCode, alertMessage = self.cog.getWeerAlarm(weerMock)
|
|
self.assertEqual(alertCode, "rood")
|
|
self.assertIsInstance(alertMessage, str)
|
|
with self.subTest("False negative oranje alarm"):
|
|
weerMock = { "alarm": "1", "alarmtxt": "qwerty code oranje yuiop"}
|
|
alertCode, alertMessage = self.cog.getWeerAlarm(weerMock)
|
|
self.assertEqual(alertCode, "oranje")
|
|
self.assertIsInstance(alertMessage, str)
|
|
with self.subTest("False negative geel alarm"):
|
|
weerMock = { "alarm": "1", "alarmtxt": "lorem ipsum dolor sit amet"}
|
|
alertCode, alertMessage = self.cog.getWeerAlarm(weerMock)
|
|
self.assertEqual(alertCode, "geel")
|
|
self.assertIsInstance(alertMessage, str)
|
|
|
|
wb = self.cog.get_weerbericht(weerJson)
|
|
wb_v = self.cog.get_weerbericht(weerJson, "verbose pls")
|
|
with self.subTest("Can't render message from json"):
|
|
self.assertIsInstance(wb, str)
|
|
self.assertIsInstance(wb_v, str)
|
|
with self.subTest("Verbose isn't actually verbose"):
|
|
self.assertTrue(len(wb_v) > len(wb))
|