From 3c8d34acdd57ec664e392ffec1f8bf5c721ae72a Mon Sep 17 00:00:00 2001 From: Mark Hoekveen Date: Thu, 3 Nov 2022 23:28:14 +0100 Subject: [PATCH 1/5] eerste opzet testje --- tests.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 tests.py diff --git a/tests.py b/tests.py new file mode 100644 index 0000000..f2c3082 --- /dev/null +++ b/tests.py @@ -0,0 +1,37 @@ +import unittest +import configparser +import praw +import random + +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() + 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 + + 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): + pass \ No newline at end of file -- 2.52.0 From f89889fc48f28738ec86da03c3e9c108fe42da3d Mon Sep 17 00:00:00 2001 From: Mark Hoekveen Date: Fri, 4 Nov 2022 23:25:36 +0100 Subject: [PATCH 2/5] refactors en echte tests ofzo --- General.py | 14 ++++++++------ tests.py | 25 ++++++++++++++++++------- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/General.py b/General.py index 6d8bfda..9e7e9a8 100644 --- a/General.py +++ b/General.py @@ -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"], @@ -85,7 +85,7 @@ class General(commands.Cog): rkopieerpasta = self.r.subreddit('kopieerpasta') post = rkopieerpasta.random() - # Subreddits kunnen de random functie uitzetten, dus dit is de fallback: + # Subreddits kunnen de random functie uitzetten, dus dit is de fallback: if post == None: post = rkopieerpasta.top('month', limit=250) listing = list(post) @@ -121,15 +121,17 @@ Op 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 diff --git a/tests.py b/tests.py index f2c3082..ea64811 100644 --- a/tests.py +++ b/tests.py @@ -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 \ No newline at end of file + 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) \ No newline at end of file -- 2.52.0 From 67bb071305c3d4034211e951b999588a53a7bce6 Mon Sep 17 00:00:00 2001 From: Mark Hoekveen Date: Sun, 13 Nov 2022 19:58:27 +0100 Subject: [PATCH 3/5] adds requirements for pip --- .gitignore | 3 ++- requirements.txt | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore index b15dfb2..b0771d7 100644 --- a/.gitignore +++ b/.gitignore @@ -9,5 +9,6 @@ stroopwafel.ini Stroopwafel.sln Stroopwafel.pyproj *.txt +!requirements.txt *.sh -*.npy \ No newline at end of file +*.npy diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..5959dba --- /dev/null +++ b/requirements.txt @@ -0,0 +1,7 @@ +caldav +discord.py +praw +sympy +numpy +youtube_dl +python-ffmpeg -- 2.52.0 From 7e9e88eee7896b51e0f1d7f06cfadc08967e1a4f Mon Sep 17 00:00:00 2001 From: Mark Hoekveen Date: Sun, 13 Nov 2022 20:00:31 +0100 Subject: [PATCH 4/5] adds drone config nog wel de vraag hoe het gaat zonder ini en hoe we die er in krijgen, maar dat moeten we maar even zien --- .drone.yml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .drone.yml diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..98a22ef --- /dev/null +++ b/.drone.yml @@ -0,0 +1,9 @@ +kind: pipeline +name: default + +steps: +- name: test + image: python:3.10 + commands: + - pip install -r requirements.txt + - python -m unittest tests -- 2.52.0 From fc0d59964d4a88210054a77bad5f3a453d21325c Mon Sep 17 00:00:00 2001 From: Mark Hoekveen Date: Sun, 13 Nov 2022 20:02:07 +0100 Subject: [PATCH 5/5] alleen builden op push, niet op PR --- .drone.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.drone.yml b/.drone.yml index 98a22ef..2719268 100644 --- a/.drone.yml +++ b/.drone.yml @@ -7,3 +7,7 @@ steps: commands: - pip install -r requirements.txt - python -m unittest tests +trigger: + event: + exclude: + - pull_request -- 2.52.0