limnoria-wfg/test.py

161 lines
6.4 KiB
Python
Raw Normal View History

2024-08-21 22:08:36 +02:00
###
# 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 *
2024-09-08 16:27:11 +02:00
import supybot.ircmsgs as ircmsgs
2024-08-21 22:08:36 +02:00
class WFGTestCase(PluginTestCase):
plugins = ('wfg',)
2024-09-08 16:27:11 +02:00
config: dict[str, any] = {
'supybot.plugins.wfg': True,
'supybot.plugins.wfg.ticketUrl': "https://gitea.wildfiregames.com/0ad/0ad/issues/",
'supybot.plugins.wfg.channels': ["#test"],
}
2024-08-21 22:08:36 +02:00
2024-09-08 16:27:11 +02:00
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
2024-09-21 12:10:04 +02:00
self.assertEqual(count, 0)
2024-08-21 22:08:36 +02:00
2024-09-08 16:27:11 +02:00
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:
2024-09-21 12:10:04 +02:00
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")
2024-09-08 16:27:11 +02:00
msg = self.irc.takeMsg()
count += 1
2024-09-21 12:10:04 +02:00
self.assertEqual(count, 1)
2024-09-08 16:27:11 +02:00
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
2024-09-21 12:10:04 +02:00
self.assertEqual(count, 0)
2024-09-08 16:27:11 +02:00
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:
2024-09-21 12:10:04 +02:00
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")
2024-09-08 16:27:11 +02:00
msg = self.irc.takeMsg()
count += 1
2024-09-21 12:10:04 +02:00
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())