limnoria-wfg/test.py
Dunedan 0d22b8e05b
All checks were successful
Run Limnoria Plugin Tests / test (pull_request) Successful in 10s
Run Limnoria Plugin Tests / test (push) Successful in 10s
Print links for all mentioned tickets
Up to now this plugin only printed the link for the first encountered
ticket id. With this change links for all tickets are printed instead.
2024-09-21 14:25:11 +02:00

161 lines
6.4 KiB
Python
Executable File

###
# Copyright (c) 2014, scythetwirler
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions, and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions, and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the author of this software nor the name of
# contributors to this software may be used to endorse or promote products
# derived from this software without specific prior written consent.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
###
from supybot.test import *
import supybot.ircmsgs as ircmsgs
class WFGTestCase(PluginTestCase):
plugins = ('wfg',)
config: dict[str, any] = {
'supybot.plugins.wfg': True,
'supybot.plugins.wfg.ticketUrl': "https://gitea.wildfiregames.com/0ad/0ad/issues/",
'supybot.plugins.wfg.channels': ["#test"],
}
def testTicketUrl(self):
obj = self.irc.getCallback('wfg')
obj.doPrivmsg(
self.irc,
ircmsgs.privmsg(self.config["supybot.plugins.wfg.channels"][0], "test")
)
count = 0
msg = self.irc.takeMsg()
while msg is not None:
msg = self.irc.takeMsg()
count += 1
self.assertEqual(count, 0)
obj.doPrivmsg(
self.irc,
ircmsgs.privmsg(self.config["supybot.plugins.wfg.channels"][0], "Sounds like #666")
)
count = 0
msg = self.irc.takeMsg()
while msg is not None:
self.assertEqual(msg.nick, "")
self.assertEqual(msg.args[0], self.config["supybot.plugins.wfg.channels"][0])
self.assertEqual(msg.args[1], "#666 - Remove Devil – https://gitea.wildfiregames.com/0ad/0ad/issues/666")
msg = self.irc.takeMsg()
count += 1
self.assertEqual(count, 1)
def testPullRequestUrl(self):
obj = self.irc.getCallback('wfg')
obj.doPrivmsg(
self.irc,
ircmsgs.privmsg(self.config["supybot.plugins.wfg.channels"][0], "test")
)
count = 0
msg = self.irc.takeMsg()
while msg is not None:
msg = self.irc.takeMsg()
count += 1
self.assertEqual(count, 0)
obj.doPrivmsg(
self.irc,
ircmsgs.privmsg(self.config["supybot.plugins.wfg.channels"][0], "Sounds like it's fixed by #7028")
)
count = 0
msg = self.irc.takeMsg()
while msg is not None:
self.assertEqual(msg.nick, "")
self.assertEqual(msg.args[0], self.config["supybot.plugins.wfg.channels"][0])
self.assertEqual(msg.args[1], "#7028 - Add yamllint to pre-commit – https://gitea.wildfiregames.com/0ad/0ad/pulls/7028")
msg = self.irc.takeMsg()
count += 1
self.assertEqual(count, 1)
def test_dont_match_in_word(self):
obj = self.irc.getCallback('wfg')
obj.doPrivmsg(
self.irc,
ircmsgs.privmsg(self.config["supybot.plugins.wfg.channels"][0],
"https://example.tld/foo#1234")
)
self.assertIsNone(self.irc.takeMsg())
def test_ticket_id_at_the_beginning(self):
obj = self.irc.getCallback('wfg')
obj.doPrivmsg(
self.irc,
ircmsgs.privmsg(self.config["supybot.plugins.wfg.channels"][0],
"#1234 should be fine")
)
msg = self.irc.takeMsg()
self.assertIsInstance(msg, ircmsgs.IrcMsg)
self.assertEqual(msg.nick, "")
self.assertEqual(msg.args[0], self.config["supybot.plugins.wfg.channels"][0])
self.assertEqual(msg.args[1],
"#1234 - [PATCH] Read formations from json files – "
"https://gitea.wildfiregames.com/0ad/0ad/issues/1234")
self.assertIsNone(self.irc.takeMsg())
def test_match_multiple_ticket_ids(self):
obj = self.irc.getCallback('wfg')
obj.doPrivmsg(
self.irc,
ircmsgs.privmsg(self.config["supybot.plugins.wfg.channels"][0],
"References for this are #1234, #1234,#1235 and #1236")
)
msg = self.irc.takeMsg()
self.assertIsInstance(msg, ircmsgs.IrcMsg)
self.assertEqual(msg.nick, "")
self.assertEqual(msg.args[0], self.config["supybot.plugins.wfg.channels"][0])
self.assertEqual(msg.args[1],
"#1234 - [PATCH] Read formations from json files – "
"https://gitea.wildfiregames.com/0ad/0ad/issues/1234")
msg = self.irc.takeMsg()
self.assertIsInstance(msg, ircmsgs.IrcMsg)
self.assertEqual(msg.nick, "")
self.assertEqual(msg.args[0], self.config["supybot.plugins.wfg.channels"][0])
self.assertEqual(msg.args[1],
"#1235 - selection box moves when moving the camera – "
"https://gitea.wildfiregames.com/0ad/0ad/issues/1235")
msg = self.irc.takeMsg()
self.assertIsInstance(msg, ircmsgs.IrcMsg)
self.assertEqual(msg.nick, "")
self.assertEqual(msg.args[0], self.config["supybot.plugins.wfg.channels"][0])
self.assertEqual(msg.args[1],
"#1236 - WP Theming - Fine Footer – "
"https://gitea.wildfiregames.com/0ad/0ad/issues/1236")
self.assertIsNone(self.irc.takeMsg())