Testing/CI #21

Merged
jp merged 40 commits from testing into master 2022-12-11 16:27:22 +01:00
2 changed files with 26 additions and 13 deletions
Showing only changes of commit f89889fc48 - Show all commits
+7 -5
View File
@@ -8,7 +8,6 @@ import json, requests
from discord.ext import commands
from sympy import latex, symbols, preview, Symbol #for LaTeX images
import youtube_dl
import ffmpeg
class General(commands.Cog):
"""Overal toegestaan."""
@@ -16,6 +15,7 @@ class General(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.voice_states = {}
self.muzak_url = 'https://hdcon-muzak.herokuapp.com'
self.r = praw.Reddit(
user_agent='StroopwafelBot',
client_secret=self.bot.tokens["redditSecret"],
@@ -121,15 +121,17 @@ Op <https://gifrun.com/> kunt u bijvoorbeeld via een web-interface gifjes maken
Namens de directie van Stroopwafel B.V. onze excuses voor dit ongemak.""")
def get_playlist_json(self):
return requests.get(self.muzak_url + '/stroopwafel')
@commands.command(pass_context=True)
@asyncio.coroutine
def playlist(self, ctx):
"""HDcon2021 playlist"""
muzak_url = 'https://hdcon-muzak.herokuapp.com'
data = json.loads(requests.get(muzak_url + '/stroopwafel').content) # als dit faalt yolo no catch
msg = 'Stemmen en nomineren kan hier: {}\n'.format(muzak_url)
data = json.loads(self.get_playlist_json().content)
msg = 'Stemmen en nomineren kan hier: {}\n'.format(self.muzak_url)
msg += '*Er zijn al {} nummers genomineerd*\n'.format(data['stemCount'])
yield from ctx.channel.send(msg)
yield from ctx.channel.send(self.get_playlist_msg())
@commands.command(pass_context=True, hidden=True)
@asyncio.coroutine
+18 -7
View File
@@ -2,15 +2,14 @@ import unittest
import configparser
import praw
import random
import requests
import json
import discord
from discord.ext import commands
import General
class TestTest(unittest.TestCase):
def test_a(self):
self.assertEqual(1, 1)
def test_b(self):
self.assertEqual("ab", "a" + "b")
class TestGeneral(unittest.TestCase):
def setUp(self):
config = configparser.ConfigParser()
@@ -22,6 +21,12 @@ class TestGeneral(unittest.TestCase):
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
@@ -34,4 +39,10 @@ class TestGeneral(unittest.TestCase):
self.assertIsInstance(post,praw.models.Submission)
def test_playlist(self):
pass
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)