mirror of https://github.com/progval/irctest.git
Use assertMessageMatch whenever possible, and generalize listMatch to accept regexps
it's stricter this way + hopefully more readable and better error msgs
This commit is contained in:
parent
e012c5248b
commit
3f231403ba
|
@ -26,7 +26,7 @@ Alternatively, run `pre-commit run -a`
|
|||
[Follow PEP 8](https://www.python.org/dev/peps/pep-0008/#naming-conventions),
|
||||
with these exceptions:
|
||||
|
||||
* assertion methods (eg. `assertMessageEqual` are mixedCase to be consistent
|
||||
* assertion methods (eg. `assertMessageMatch` are mixedCase to be consistent
|
||||
with the unittest module)
|
||||
* other methods defined in `cases.py` are also mixedCase for consistency with
|
||||
the former, for now
|
||||
|
@ -67,7 +67,7 @@ This does not relax the requirement on documentating tests.
|
|||
|
||||
**Use unittest-style assertions** (`self.assertEqual(x, y)` instead of
|
||||
pytest-style (`assert x == y`). This allows consistency with the assertion
|
||||
methods we define, such as `assertMessageEqual`.
|
||||
methods we define, such as `assertMessageMatch`.
|
||||
|
||||
Always **add an error message in assertions**.
|
||||
`irctest` should show readable errors to people unfamiliar with the
|
||||
|
|
|
@ -109,7 +109,7 @@ class _IrcTestCase(unittest.TestCase, Generic[TController]):
|
|||
Takes the message as first arguments, and comparisons to be made
|
||||
as keyword arguments.
|
||||
|
||||
Uses patma.list_match on the params argument.
|
||||
Uses patma.match_list on the params argument.
|
||||
"""
|
||||
error = self.messageDiffers(msg, **kwargs)
|
||||
if error:
|
||||
|
@ -145,7 +145,7 @@ class _IrcTestCase(unittest.TestCase, Generic[TController]):
|
|||
msg=msg,
|
||||
)
|
||||
|
||||
if params and not patma.list_match(msg.params, params):
|
||||
if params and not patma.match_list(msg.params, params):
|
||||
fail_msg = fail_msg or "params to be {expects}, got {got}: {msg}"
|
||||
return fail_msg.format(
|
||||
*extra_format, got=msg.params, expects=params, msg=msg
|
||||
|
|
|
@ -3,6 +3,7 @@ import ssl
|
|||
|
||||
from irctest import cases, runner, tls
|
||||
from irctest.exceptions import ConnectionClosed
|
||||
from irctest.patma import ANYSTR
|
||||
|
||||
BAD_CERT = """
|
||||
-----BEGIN CERTIFICATE-----
|
||||
|
@ -162,9 +163,12 @@ class StsTestCase(cases.BaseClientTestCase, cases.OptionalityHelper):
|
|||
self.acceptClient(server=self.insecure_server)
|
||||
|
||||
# Send STS policy to client
|
||||
m = self.getMessage()
|
||||
self.assertEqual(m.command, "CAP", "First message is not CAP LS.")
|
||||
self.assertEqual(m.params[0], "LS", "First message is not CAP LS.")
|
||||
self.assertMessageMatch(
|
||||
self.getMessage(),
|
||||
command="CAP",
|
||||
params=["LS", ANYSTR],
|
||||
fail_msg="First message is not CAP LS: {got}",
|
||||
)
|
||||
self.sendLine("CAP * LS :sts=port={}".format(self.server.getsockname()[1]))
|
||||
|
||||
# "If the client is not already connected securely to the server
|
||||
|
@ -204,9 +208,12 @@ class StsTestCase(cases.BaseClientTestCase, cases.OptionalityHelper):
|
|||
self.acceptClient(server=self.insecure_server)
|
||||
|
||||
# Send STS policy to client
|
||||
m = self.getMessage()
|
||||
self.assertEqual(m.command, "CAP", "First message is not CAP LS.")
|
||||
self.assertEqual(m.params[0], "LS", "First message is not CAP LS.")
|
||||
self.assertMessageMatch(
|
||||
self.getMessage(),
|
||||
command="CAP",
|
||||
params=["LS", ANYSTR],
|
||||
fail_msg="First message is not CAP LS: {got}",
|
||||
)
|
||||
self.sendLine("CAP * LS :sts=port={}".format(self.server.getsockname()[1]))
|
||||
|
||||
# The client will reconnect to the TLS port. Unfortunately, it does
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from irctest import cases
|
||||
from irctest.irc_utils.sasl import sasl_plain_blob
|
||||
from irctest.numerics import ERR_NICKNAMEINUSE, RPL_WELCOME
|
||||
from irctest.patma import ANYSTR, StrRe
|
||||
|
||||
|
||||
class Bouncer(cases.BaseServerTestCase):
|
||||
|
@ -27,7 +28,7 @@ class Bouncer(cases.BaseServerTestCase):
|
|||
welcomes = [message for message in messages if message.command == RPL_WELCOME]
|
||||
self.assertEqual(len(welcomes), 1)
|
||||
# should see a regburst for testnick
|
||||
self.assertEqual(welcomes[0].params[0], "testnick")
|
||||
self.assertMessageMatch(welcomes[0], params=["testnick", ANYSTR])
|
||||
self.joinChannel(2, "#chan")
|
||||
|
||||
self.addClient()
|
||||
|
@ -42,10 +43,10 @@ class Bouncer(cases.BaseServerTestCase):
|
|||
welcomes = [message for message in messages if message.command == RPL_WELCOME]
|
||||
self.assertEqual(len(welcomes), 1)
|
||||
# should see the *same* regburst for testnick
|
||||
self.assertEqual(welcomes[0].params[0], "testnick")
|
||||
self.assertMessageMatch(welcomes[0], params=["testnick", ANYSTR])
|
||||
joins = [message for message in messages if message.command == "JOIN"]
|
||||
# we should be automatically joined to #chan
|
||||
self.assertEqual(joins[0].params[0], "#chan")
|
||||
self.assertMessageMatch(joins[0], params=["#chan"])
|
||||
|
||||
# disable multiclient in nickserv
|
||||
self.sendLine(3, "NS SET MULTICLIENT OFF")
|
||||
|
@ -95,9 +96,9 @@ class Bouncer(cases.BaseServerTestCase):
|
|||
messagefortwo = messagesfortwo[0]
|
||||
messageforthree = messagesforthree[0]
|
||||
messageforfive = self.getMessage(5)
|
||||
self.assertEqual(messagefortwo.params, ["#chan", "hey"])
|
||||
self.assertEqual(messageforthree.params, ["#chan", "hey"])
|
||||
self.assertEqual(messageforfive.params, ["#chan", "hey"])
|
||||
self.assertMessageMatch(messagefortwo, params=["#chan", "hey"])
|
||||
self.assertMessageMatch(messageforthree, params=["#chan", "hey"])
|
||||
self.assertMessageMatch(messageforfive, params=["#chan", "hey"])
|
||||
self.assertIn("time", messagefortwo.tags)
|
||||
self.assertIn("time", messageforthree.tags)
|
||||
self.assertIn("time", messageforfive.tags)
|
||||
|
@ -126,7 +127,7 @@ class Bouncer(cases.BaseServerTestCase):
|
|||
self.sendLine(2, "QUIT :two out")
|
||||
quitLines = [msg for msg in self.getMessages(2) if msg.command == "QUIT"]
|
||||
self.assertEqual(len(quitLines), 1)
|
||||
self.assertIn("two out", quitLines[0].params[0])
|
||||
self.assertMessageMatch(quitLines[0], params=[StrRe(".*two out.*")])
|
||||
# neither the observer nor the other attached session should see a quit here
|
||||
quitLines = [msg for msg in self.getMessages(1) if msg.command == "QUIT"]
|
||||
self.assertEqual(quitLines, [])
|
||||
|
@ -149,8 +150,8 @@ class Bouncer(cases.BaseServerTestCase):
|
|||
self.sendLine(3, "QUIT :three out")
|
||||
quitLines = [msg for msg in self.getMessages(3) if msg.command == "QUIT"]
|
||||
self.assertEqual(len(quitLines), 1)
|
||||
self.assertIn("three out", quitLines[0].params[0])
|
||||
self.assertMessageMatch(quitLines[0], params=[StrRe(".*three out.*")])
|
||||
# observer should see *this* quit
|
||||
quitLines = [msg for msg in self.getMessages(1) if msg.command == "QUIT"]
|
||||
self.assertEqual(len(quitLines), 1)
|
||||
self.assertIn("three out", quitLines[0].params[0])
|
||||
self.assertMessageMatch(quitLines[0], params=[StrRe(".*three out.*")])
|
||||
|
|
|
@ -22,6 +22,7 @@ from irctest.numerics import (
|
|||
RPL_TOPIC,
|
||||
RPL_TOPICTIME,
|
||||
)
|
||||
from irctest.patma import ANYSTR, StrRe
|
||||
|
||||
MODERN_CAPS = [
|
||||
"server-time",
|
||||
|
@ -396,11 +397,9 @@ class JoinTestCase(cases.BaseServerTestCase):
|
|||
self.sendLine(1, "TOPIC #test :new topic")
|
||||
self.getMessages(1)
|
||||
# client 2 should get the new TOPIC line
|
||||
messages = [
|
||||
message for message in self.getMessages(2) if message.command == "TOPIC"
|
||||
]
|
||||
self.assertEqual(len(messages), 1)
|
||||
self.assertEqual(messages[0].params, ["#test", "new topic"])
|
||||
self.assertMessageMatch(
|
||||
self.getMessage(2), command="TOPIC", params=["#test", "new topic"]
|
||||
)
|
||||
|
||||
# unset the topic:
|
||||
self.sendLine(1, "TOPIC #test :")
|
||||
|
@ -625,12 +624,8 @@ class JoinTestCase(cases.BaseServerTestCase):
|
|||
self.assertGreaterEqual(len(mgroup), 2)
|
||||
m1, m2 = mgroup[:2]
|
||||
|
||||
for m in m1, m2:
|
||||
self.assertEqual(m.command, "KICK")
|
||||
|
||||
self.assertEqual(len(m.params), 3)
|
||||
self.assertEqual(m.params[0], "#chan")
|
||||
self.assertEqual(m.params[2], "bye")
|
||||
self.assertMessageMatch(m1, command="KICK", params=["#chan", ANYSTR, "bye"])
|
||||
self.assertMessageMatch(m2, command="KICK", params=["#chan", ANYSTR, "bye"])
|
||||
|
||||
if (m1.params[1] == "bar" and m2.params[1] == "baz") or (
|
||||
m1.params[1] == "baz" and m2.params[1] == "bar"
|
||||
|
@ -798,13 +793,11 @@ class InviteTestCase(cases.BaseServerTestCase):
|
|||
|
||||
self.sendLine(1, "INVITE bar #chan")
|
||||
m = self.getMessage(1)
|
||||
self.assertEqual(m.command, RPL_INVITING)
|
||||
# modern/ircv3 param order: inviter, invitee, channel
|
||||
self.assertEqual(m.params, ["foo", "bar", "#chan"])
|
||||
self.assertMessageMatch(m, command=RPL_INVITING, params=["foo", "bar", "#chan"])
|
||||
m = self.getMessage(2)
|
||||
self.assertEqual(m.command, "INVITE")
|
||||
self.assertMessageMatch(m, command="INVITE", params=["bar", "#chan"])
|
||||
self.assertTrue(m.prefix.startswith("foo")) # nickmask of inviter
|
||||
self.assertEqual(m.params, ["bar", "#chan"])
|
||||
|
||||
# we were invited, so join should succeed now
|
||||
self.joinChannel(2, "#chan")
|
||||
|
@ -828,9 +821,8 @@ class ChannelQuitTestCase(cases.BaseServerTestCase):
|
|||
self.sendLine(2, "QUIT :qux out")
|
||||
self.getMessages(2)
|
||||
m = self.getMessage(1)
|
||||
self.assertEqual(m.command, "QUIT")
|
||||
self.assertMessageMatch(m, command="QUIT", params=[StrRe(".*qux out.*")])
|
||||
self.assertTrue(m.prefix.startswith("qux")) # nickmask of quitter
|
||||
self.assertIn("qux out", m.params[0])
|
||||
|
||||
|
||||
class NoCTCPTestCase(cases.BaseServerTestCase):
|
||||
|
|
|
@ -3,6 +3,7 @@ import time
|
|||
|
||||
from irctest import cases
|
||||
from irctest.irc_utils.junkdrawer import random_name
|
||||
from irctest.patma import ANYSTR
|
||||
|
||||
CHATHISTORY_CAP = "draft/chathistory"
|
||||
EVENT_PLAYBACK_CAP = "draft/event-playback"
|
||||
|
@ -64,15 +65,19 @@ class ChathistoryTestCase(cases.BaseServerTestCase):
|
|||
|
||||
# test a nonexistent channel
|
||||
self.sendLine(bar, "CHATHISTORY LATEST #nonexistent_channel * 10")
|
||||
msgs = self.getMessages(bar)
|
||||
self.assertEqual(msgs[0].command, "FAIL")
|
||||
self.assertEqual(msgs[0].params[:2], ["CHATHISTORY", "INVALID_TARGET"])
|
||||
self.assertMessageMatch(
|
||||
self.getMessages(bar)[0],
|
||||
command="FAIL",
|
||||
params=["CHATHISTORY", "INVALID_TARGET", ANYSTR, ANYSTR],
|
||||
)
|
||||
|
||||
# as should a real channel to which one is not joined:
|
||||
self.sendLine(bar, "CHATHISTORY LATEST %s * 10" % (real_chname,))
|
||||
msgs = self.getMessages(bar)
|
||||
self.assertEqual(msgs[0].command, "FAIL")
|
||||
self.assertEqual(msgs[0].params[:2], ["CHATHISTORY", "INVALID_TARGET"])
|
||||
self.assertMessageMatch(
|
||||
self.getMessages(bar)[0],
|
||||
command="FAIL",
|
||||
params=["CHATHISTORY", "INVALID_TARGET", ANYSTR, ANYSTR],
|
||||
)
|
||||
|
||||
@cases.mark_specifications("Oragono")
|
||||
def testMessagesToSelf(self):
|
||||
|
@ -92,7 +97,7 @@ class ChathistoryTestCase(cases.BaseServerTestCase):
|
|||
replies = [msg for msg in self.getMessages(bar) if msg.command == "PRIVMSG"]
|
||||
self.assertEqual(len(replies), 1)
|
||||
msg = replies[0]
|
||||
self.assertEqual(msg.params, [bar, "this is a privmsg sent to myself"])
|
||||
self.assertMessageMatch(msg, params=[bar, "this is a privmsg sent to myself"])
|
||||
messages.append(msg.to_history_message())
|
||||
|
||||
self.sendLine(bar, "CAP REQ echo-message")
|
||||
|
@ -103,8 +108,8 @@ class ChathistoryTestCase(cases.BaseServerTestCase):
|
|||
replies = [msg for msg in self.getMessages(bar) if msg.command == "PRIVMSG"]
|
||||
# two messages, the echo and the delivery
|
||||
self.assertEqual(len(replies), 2)
|
||||
self.assertEqual(
|
||||
replies[0].params, [bar, "this is a second privmsg sent to myself"]
|
||||
self.assertMessageMatch(
|
||||
replies[0], params=[bar, "this is a second privmsg sent to myself"]
|
||||
)
|
||||
messages.append(replies[0].to_history_message())
|
||||
# messages should be otherwise identical
|
||||
|
@ -121,7 +126,9 @@ class ChathistoryTestCase(cases.BaseServerTestCase):
|
|||
# exactly one of the replies MUST be labeled
|
||||
echo = [msg for msg in replies if msg.tags.get("label") == "xyz"][0]
|
||||
delivery = [msg for msg in replies if msg.tags.get("label") is None][0]
|
||||
self.assertEqual(echo.params, [bar, "this is a third privmsg sent to myself"])
|
||||
self.assertMessageMatch(
|
||||
echo, params=[bar, "this is a third privmsg sent to myself"]
|
||||
)
|
||||
messages.append(echo.to_history_message())
|
||||
self.assertEqual(echo.to_history_message(), delivery.to_history_message())
|
||||
|
||||
|
@ -527,10 +534,9 @@ class ChathistoryTestCase(cases.BaseServerTestCase):
|
|||
msgid = echo.tags["msgid"]
|
||||
|
||||
def validate_tagmsg(msg, target, msgid):
|
||||
self.assertEqual(msg.command, "TAGMSG")
|
||||
self.assertMessageMatch(msg, command="TAGMSG", params=[target])
|
||||
self.assertEqual(msg.tags["+client-only-tag-test"], "success")
|
||||
self.assertEqual(msg.tags["msgid"], msgid)
|
||||
self.assertEqual(msg.params, [target])
|
||||
|
||||
validate_tagmsg(echo, chname, msgid)
|
||||
|
||||
|
@ -616,10 +622,9 @@ class ChathistoryTestCase(cases.BaseServerTestCase):
|
|||
echo_msgid = None
|
||||
|
||||
def validate_msg(msg):
|
||||
self.assertEqual(msg.command, "PRIVMSG")
|
||||
self.assertMessageMatch(msg, command="PRIVMSG", params=[c2, "hi"])
|
||||
self.assertEqual(msg.tags["+client-only-tag-test"], "success")
|
||||
self.assertEqual(msg.tags["msgid"], echo_msgid)
|
||||
self.assertEqual(msg.params, [c2, "hi"])
|
||||
|
||||
self.sendLine(
|
||||
1, "@+client-only-tag-test=success;+draft/persist PRIVMSG %s hi" % (c2,)
|
||||
|
|
|
@ -8,6 +8,7 @@ so there may be many false positives.
|
|||
import re
|
||||
|
||||
from irctest import cases
|
||||
from irctest.patma import StrRe
|
||||
|
||||
|
||||
class LabeledResponsesTestCase(cases.BaseServerTestCase, cases.OptionalityHelper):
|
||||
|
@ -674,11 +675,10 @@ class LabeledResponsesTestCase(cases.BaseServerTestCase, cases.OptionalityHelper
|
|||
|
||||
# valid BATCH start line:
|
||||
batch_start = m[0]
|
||||
self.assertMessageMatch(batch_start, command="BATCH")
|
||||
self.assertEqual(len(batch_start.params), 2)
|
||||
self.assertTrue(
|
||||
batch_start.params[0].startswith("+"),
|
||||
"batch start param must begin with +, got %s" % (batch_start.params[0],),
|
||||
self.assertMessageMatch(
|
||||
batch_start,
|
||||
command="BATCH",
|
||||
params=[StrRe(r"\+.*"), "labeled-response"],
|
||||
)
|
||||
batch_id = batch_start.params[0][1:]
|
||||
# batch id MUST be alphanumerics and hyphens
|
||||
|
@ -686,7 +686,6 @@ class LabeledResponsesTestCase(cases.BaseServerTestCase, cases.OptionalityHelper
|
|||
re.match(r"^[A-Za-z0-9\-]+$", batch_id) is not None,
|
||||
"batch id must be alphanumerics and hyphens, got %r" % (batch_id,),
|
||||
)
|
||||
self.assertEqual(batch_start.params[1], "labeled-response")
|
||||
self.assertEqual(batch_start.tags.get("label"), "12345")
|
||||
|
||||
# valid BATCH end line
|
||||
|
@ -712,6 +711,7 @@ class LabeledResponsesTestCase(cases.BaseServerTestCase, cases.OptionalityHelper
|
|||
m = ms[0]
|
||||
self.assertEqual(m.command, "PONG")
|
||||
self.assertEqual(m.params[-1], "adhoctestline")
|
||||
|
||||
# check the label
|
||||
self.assertEqual(m.tags.get("label"), "98765")
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ from irctest.numerics import (
|
|||
RPL_MONOFFLINE,
|
||||
RPL_MONONLINE,
|
||||
)
|
||||
from irctest.patma import ANYSTR, StrRe
|
||||
|
||||
|
||||
class MonitorTestCase(cases.BaseServerTestCase):
|
||||
|
@ -24,21 +25,9 @@ class MonitorTestCase(cases.BaseServerTestCase):
|
|||
self.assertMessageMatch(
|
||||
m,
|
||||
command="730", # RPL_MONONLINE
|
||||
fail_msg="Sent non-730 (RPL_MONONLINE) message after "
|
||||
"monitored nick “{}” connected: {msg}",
|
||||
extra_format=(nick,),
|
||||
)
|
||||
self.assertEqual(
|
||||
len(m.params),
|
||||
2,
|
||||
m,
|
||||
fail_msg="Invalid number of params of RPL_MONONLINE: {msg}",
|
||||
)
|
||||
self.assertEqual(
|
||||
m.params[1].split("!")[0],
|
||||
"bar",
|
||||
fail_msg="730 (RPL_MONONLINE) with bad target after “{}” "
|
||||
"connects: {msg}",
|
||||
params=[ANYSTR, StrRe(nick + "(!.*)?")],
|
||||
fail_msg="Unexpected notification that monitored nick “{}” "
|
||||
"is online: {msg}",
|
||||
extra_format=(nick,),
|
||||
)
|
||||
|
||||
|
@ -48,21 +37,9 @@ class MonitorTestCase(cases.BaseServerTestCase):
|
|||
self.assertMessageMatch(
|
||||
m,
|
||||
command="731", # RPL_MONOFFLINE
|
||||
fail_msg="Did not reply with 731 (RPL_MONOFFLINE) to "
|
||||
"“MONITOR + {}”, while “{}” is offline: {msg}",
|
||||
extra_format=(nick, nick),
|
||||
)
|
||||
self.assertEqual(
|
||||
len(m.params),
|
||||
2,
|
||||
m,
|
||||
fail_msg="Invalid number of params of RPL_MONOFFLINE: {msg}",
|
||||
)
|
||||
self.assertEqual(
|
||||
m.params[1].split("!")[0],
|
||||
"bar",
|
||||
fail_msg="731 (RPL_MONOFFLINE) reply to “MONITOR + {}” "
|
||||
"with bad target: {msg}",
|
||||
params=[ANYSTR, nick],
|
||||
fail_msg="Unexpected notification that monitored nick “{}” "
|
||||
"is offline: {msg}",
|
||||
extra_format=(nick,),
|
||||
)
|
||||
|
||||
|
@ -163,32 +140,9 @@ class MonitorTestCase(cases.BaseServerTestCase):
|
|||
)
|
||||
if m1.command == "731":
|
||||
(m1, m2) = (m2, m1)
|
||||
self.assertEqual(
|
||||
len(m1.params),
|
||||
2,
|
||||
m1,
|
||||
fail_msg="Invalid number of params of RPL_MONONLINE: {msg}",
|
||||
)
|
||||
self.assertEqual(
|
||||
len(m2.params),
|
||||
2,
|
||||
m2,
|
||||
fail_msg="Invalid number of params of RPL_MONONLINE: {msg}",
|
||||
)
|
||||
self.assertEqual(
|
||||
m1.params[1].split("!")[0],
|
||||
"bar",
|
||||
m1,
|
||||
fail_msg="730 (RPL_MONONLINE) with bad target after "
|
||||
"“MONITOR + bar,baz” and “bar” is connected: {msg}",
|
||||
)
|
||||
self.assertEqual(
|
||||
m2.params[1].split("!")[0],
|
||||
"baz",
|
||||
m2,
|
||||
fail_msg="731 (RPL_MONOFFLINE) with bad target after "
|
||||
"“MONITOR + bar,baz” and “baz” is disconnected: {msg}",
|
||||
)
|
||||
|
||||
self.assertMononline(None, "bar", m=m1)
|
||||
self.assertMonoffline(None, "baz", m=m2)
|
||||
|
||||
@cases.mark_specifications("IRCv3")
|
||||
@cases.mark_isupport("MONITOR")
|
||||
|
|
|
@ -4,6 +4,7 @@ Tests multi-prefix.
|
|||
"""
|
||||
|
||||
from irctest import cases
|
||||
from irctest.patma import ANYSTR
|
||||
|
||||
|
||||
class MultiPrefixTestCase(cases.BaseServerTestCase):
|
||||
|
@ -32,7 +33,7 @@ class MultiPrefixTestCase(cases.BaseServerTestCase):
|
|||
self.assertMessageMatch(
|
||||
reply,
|
||||
command="353",
|
||||
params=["foo", reply.params[1], "#chan", "@+foo"],
|
||||
params=["foo", ANYSTR, "#chan", "@+foo"],
|
||||
fail_msg="Expected NAMES response (353) with @+foo, got: {msg}",
|
||||
)
|
||||
self.getMessages(1)
|
||||
|
|
|
@ -3,6 +3,7 @@ draft/multiline
|
|||
"""
|
||||
|
||||
from irctest import cases
|
||||
from irctest.patma import StrRe
|
||||
|
||||
CAP_NAME = "draft/multiline"
|
||||
BATCH_TYPE = "draft/multiline"
|
||||
|
@ -35,13 +36,16 @@ class MultilineTestCase(cases.BaseServerTestCase, cases.OptionalityHelper):
|
|||
|
||||
echo = self.getMessages(1)
|
||||
batchStart, batchEnd = echo[0], echo[-1]
|
||||
self.assertEqual(batchStart.command, "BATCH")
|
||||
self.assertMessageMatch(
|
||||
batchStart, command="BATCH", params=[StrRe(r"\+.*"), BATCH_TYPE, "#test"]
|
||||
)
|
||||
self.assertEqual(batchStart.tags.get("label"), "xyz")
|
||||
self.assertEqual(len(batchStart.params), 3)
|
||||
self.assertEqual(batchStart.params[1], CAP_NAME)
|
||||
self.assertEqual(batchStart.params[2], "#test")
|
||||
self.assertEqual(batchEnd.command, "BATCH")
|
||||
self.assertEqual(batchStart.params[0][1:], batchEnd.params[0][1:])
|
||||
self.assertMessageMatch(batchEnd, command="BATCH", params=[StrRe("-.*")])
|
||||
self.assertEqual(
|
||||
batchStart.params[0][1:],
|
||||
batchEnd.params[0][1:],
|
||||
fail_msg="batch start and end do not match",
|
||||
)
|
||||
msgid = batchStart.tags.get("msgid")
|
||||
time = batchStart.tags.get("time")
|
||||
assert msgid
|
||||
|
@ -55,11 +59,11 @@ class MultilineTestCase(cases.BaseServerTestCase, cases.OptionalityHelper):
|
|||
|
||||
relay = self.getMessages(2)
|
||||
batchStart, batchEnd = relay[0], relay[-1]
|
||||
self.assertEqual(batchStart.command, "BATCH")
|
||||
self.assertEqual(batchEnd.command, "BATCH")
|
||||
self.assertMessageMatch(
|
||||
batchStart, command="BATCH", params=[StrRe(r"\+.*"), BATCH_TYPE, "#test"]
|
||||
)
|
||||
batchTag = batchStart.params[0][1:]
|
||||
self.assertEqual(batchStart.params[0], "+" + batchTag)
|
||||
self.assertEqual(batchEnd.params[0], "-" + batchTag)
|
||||
self.assertMessageMatch(batchEnd, command="BATCH", params=["-" + batchTag])
|
||||
self.assertEqual(batchStart.tags.get("msgid"), msgid)
|
||||
self.assertEqual(batchStart.tags.get("time"), time)
|
||||
privmsgs = relay[1:-1]
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
from irctest import cases
|
||||
from irctest.patma import ANYSTR
|
||||
|
||||
REGISTER_CAP_NAME = "draft/register"
|
||||
|
||||
|
@ -23,7 +24,7 @@ class TestRegisterBeforeConnect(cases.BaseServerTestCase):
|
|||
self.sendLine("bar", "REGISTER * shivarampassphrase")
|
||||
msgs = self.getMessages("bar")
|
||||
register_response = [msg for msg in msgs if msg.command == "REGISTER"][0]
|
||||
self.assertEqual(register_response.params[0], "SUCCESS")
|
||||
self.assertMessageMatch(register_response, params=["SUCCESS", ANYSTR, ANYSTR])
|
||||
|
||||
|
||||
class TestRegisterBeforeConnectDisallowed(cases.BaseServerTestCase):
|
||||
|
@ -46,7 +47,9 @@ class TestRegisterBeforeConnectDisallowed(cases.BaseServerTestCase):
|
|||
self.sendLine("bar", "REGISTER * shivarampassphrase")
|
||||
msgs = self.getMessages("bar")
|
||||
fail_response = [msg for msg in msgs if msg.command == "FAIL"][0]
|
||||
self.assertEqual(fail_response.params[:2], ["REGISTER", "DISALLOWED"])
|
||||
self.assertMessageMatch(
|
||||
fail_response, params=["REGISTER", "DISALLOWED", ANYSTR]
|
||||
)
|
||||
|
||||
|
||||
class TestRegisterEmailVerified(cases.BaseServerTestCase):
|
||||
|
@ -80,7 +83,9 @@ class TestRegisterEmailVerified(cases.BaseServerTestCase):
|
|||
self.sendLine("bar", "REGISTER * shivarampassphrase")
|
||||
msgs = self.getMessages("bar")
|
||||
fail_response = [msg for msg in msgs if msg.command == "FAIL"][0]
|
||||
self.assertEqual(fail_response.params[:2], ["REGISTER", "INVALID_EMAIL"])
|
||||
self.assertMessageMatch(
|
||||
fail_response, params=["REGISTER", "INVALID_EMAIL", ANYSTR, ANYSTR]
|
||||
)
|
||||
|
||||
@cases.mark_specifications("Oragono")
|
||||
def testAfterConnect(self):
|
||||
|
@ -88,7 +93,9 @@ class TestRegisterEmailVerified(cases.BaseServerTestCase):
|
|||
self.sendLine("bar", "REGISTER * shivarampassphrase")
|
||||
msgs = self.getMessages("bar")
|
||||
fail_response = [msg for msg in msgs if msg.command == "FAIL"][0]
|
||||
self.assertEqual(fail_response.params[:2], ["REGISTER", "INVALID_EMAIL"])
|
||||
self.assertMessageMatch(
|
||||
fail_response, params=["REGISTER", "INVALID_EMAIL", ANYSTR, ANYSTR]
|
||||
)
|
||||
|
||||
|
||||
class TestRegisterNoLandGrabs(cases.BaseServerTestCase):
|
||||
|
@ -111,4 +118,6 @@ class TestRegisterNoLandGrabs(cases.BaseServerTestCase):
|
|||
self.sendLine("bar", "REGISTER * shivarampassphrase")
|
||||
msgs = self.getMessages("bar")
|
||||
fail_response = [msg for msg in msgs if msg.command == "FAIL"][0]
|
||||
self.assertEqual(fail_response.params[:2], ["REGISTER", "USERNAME_EXISTS"])
|
||||
self.assertMessageMatch(
|
||||
fail_response, params=["REGISTER", "USERNAME_EXISTS", ANYSTR, ANYSTR]
|
||||
)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from irctest import cases
|
||||
from irctest.irc_utils.junkdrawer import random_name
|
||||
from irctest.patma import ANYSTR
|
||||
from irctest.server_tests.test_chathistory import CHATHISTORY_CAP, EVENT_PLAYBACK_CAP
|
||||
|
||||
RELAYMSG_CAP = "draft/relaymsg"
|
||||
|
@ -46,14 +47,18 @@ class RelaymsgTestCase(cases.BaseServerTestCase):
|
|||
self.getMessages("qux")
|
||||
|
||||
self.sendLine("baz", "RELAYMSG %s invalid!nick/discord hi" % (chname,))
|
||||
response = self.getMessages("baz")[0]
|
||||
self.assertEqual(response.command, "FAIL")
|
||||
self.assertEqual(response.params[:2], ["RELAYMSG", "INVALID_NICK"])
|
||||
self.assertMessageMatch(
|
||||
self.getMessages("baz")[0],
|
||||
command="FAIL",
|
||||
params=["RELAYMSG", "INVALID_NICK", ANYSTR],
|
||||
)
|
||||
|
||||
self.sendLine("baz", "RELAYMSG %s regular_nick hi" % (chname,))
|
||||
response = self.getMessages("baz")[0]
|
||||
self.assertEqual(response.command, "FAIL")
|
||||
self.assertEqual(response.params[:2], ["RELAYMSG", "INVALID_NICK"])
|
||||
self.assertMessageMatch(
|
||||
self.getMessages("baz")[0],
|
||||
command="FAIL",
|
||||
params=["RELAYMSG", "INVALID_NICK", ANYSTR],
|
||||
)
|
||||
|
||||
self.sendLine("baz", "RELAYMSG %s smt/discord hi" % (chname,))
|
||||
response = self.getMessages("baz")[0]
|
||||
|
@ -81,9 +86,11 @@ class RelaymsgTestCase(cases.BaseServerTestCase):
|
|||
)
|
||||
|
||||
self.sendLine("qux", "RELAYMSG %s smt/discord :hi a third time" % (chname,))
|
||||
response = self.getMessages("qux")[0]
|
||||
self.assertEqual(response.command, "FAIL")
|
||||
self.assertEqual(response.params[:2], ["RELAYMSG", "PRIVS_NEEDED"])
|
||||
self.assertMessageMatch(
|
||||
self.getMessages("qux")[0],
|
||||
command="FAIL",
|
||||
params=["RELAYMSG", "PRIVS_NEEDED", ANYSTR],
|
||||
)
|
||||
|
||||
# grant qux chanop, allowing relaymsg
|
||||
self.sendLine("baz", "MODE %s +o qux" % (chname,))
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from irctest import cases
|
||||
from irctest.irc_utils.junkdrawer import random_name
|
||||
from irctest.numerics import ERR_CANNOTSENDRP
|
||||
from irctest.patma import StrRe
|
||||
|
||||
|
||||
class RoleplayTestCase(cases.BaseServerTestCase):
|
||||
|
@ -40,29 +41,29 @@ class RoleplayTestCase(cases.BaseServerTestCase):
|
|||
|
||||
self.sendLine(bar, "NPC %s bilbo too much bread" % (chan,))
|
||||
reply = self.getMessages(bar)[0]
|
||||
self.assertEqual(reply.command, "PRIVMSG")
|
||||
self.assertEqual(reply.params[0], chan)
|
||||
self.assertMessageMatch(
|
||||
reply, command="PRIVMSG", params=[chan, StrRe(".*too much bread.*")]
|
||||
)
|
||||
self.assertTrue(reply.prefix.startswith("*bilbo*!"))
|
||||
self.assertIn("too much bread", reply.params[1])
|
||||
|
||||
reply = self.getMessages(qux)[0]
|
||||
self.assertEqual(reply.command, "PRIVMSG")
|
||||
self.assertEqual(reply.params[0], chan)
|
||||
self.assertMessageMatch(
|
||||
reply, command="PRIVMSG", params=[chan, StrRe(".*too much bread.*")]
|
||||
)
|
||||
self.assertTrue(reply.prefix.startswith("*bilbo*!"))
|
||||
self.assertIn("too much bread", reply.params[1])
|
||||
|
||||
self.sendLine(bar, "SCENE %s dark and stormy night" % (chan,))
|
||||
reply = self.getMessages(bar)[0]
|
||||
self.assertEqual(reply.command, "PRIVMSG")
|
||||
self.assertEqual(reply.params[0], chan)
|
||||
self.assertMessageMatch(
|
||||
reply, command="PRIVMSG", params=[chan, StrRe(".*dark and stormy night.*")]
|
||||
)
|
||||
self.assertTrue(reply.prefix.startswith("=Scene=!"))
|
||||
self.assertIn("dark and stormy night", reply.params[1])
|
||||
|
||||
reply = self.getMessages(qux)[0]
|
||||
self.assertEqual(reply.command, "PRIVMSG")
|
||||
self.assertEqual(reply.params[0], chan)
|
||||
self.assertMessageMatch(
|
||||
reply, command="PRIVMSG", params=[chan, StrRe(".*dark and stormy night.*")]
|
||||
)
|
||||
self.assertTrue(reply.prefix.startswith("=Scene=!"))
|
||||
self.assertIn("dark and stormy night", reply.params[1])
|
||||
|
||||
# test history storage
|
||||
self.sendLine(qux, "CHATHISTORY LATEST %s * 10" % (chan,))
|
||||
|
@ -71,7 +72,7 @@ class RoleplayTestCase(cases.BaseServerTestCase):
|
|||
for msg in self.getMessages(qux)
|
||||
if msg.command == "PRIVMSG" and "bilbo" in msg.prefix
|
||||
][0]
|
||||
self.assertEqual(reply.command, "PRIVMSG")
|
||||
self.assertEqual(reply.params[0], chan)
|
||||
self.assertMessageMatch(
|
||||
reply, command="PRIVMSG", params=[chan, StrRe(".*too much bread.*")]
|
||||
)
|
||||
self.assertTrue(reply.prefix.startswith("*bilbo*!"))
|
||||
self.assertIn("too much bread", reply.params[1])
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import base64
|
||||
|
||||
from irctest import cases
|
||||
from irctest.patma import ANYSTR
|
||||
|
||||
|
||||
class RegistrationTestCase(cases.BaseServerTestCase):
|
||||
|
@ -44,14 +45,8 @@ class SaslTestCase(cases.BaseServerTestCase, cases.OptionalityHelper):
|
|||
self.assertMessageMatch(
|
||||
m,
|
||||
command="900",
|
||||
fail_msg="Did not send 900 after correct SASL authentication.",
|
||||
)
|
||||
self.assertEqual(
|
||||
m.params[2],
|
||||
"jilles",
|
||||
m,
|
||||
fail_msg="900 should contain the account name as 3rd argument "
|
||||
"({expects}), not {got}: {msg}",
|
||||
params=[ANYSTR, ANYSTR, "jilles", ANYSTR],
|
||||
fail_msg="Unexpected reply to correct SASL authentication: {msg}",
|
||||
)
|
||||
|
||||
@cases.mark_specifications("IRCv3")
|
||||
|
@ -109,14 +104,8 @@ class SaslTestCase(cases.BaseServerTestCase, cases.OptionalityHelper):
|
|||
self.assertMessageMatch(
|
||||
m,
|
||||
command="900",
|
||||
fail_msg="Did not send 900 after correct SASL authentication.",
|
||||
)
|
||||
self.assertEqual(
|
||||
m.params[2],
|
||||
"jilles",
|
||||
m,
|
||||
fail_msg="900 should contain the account name as 3rd argument "
|
||||
"({expects}), not {got}: {msg}",
|
||||
params=[ANYSTR, ANYSTR, "jilles", ANYSTR],
|
||||
fail_msg="Unexpected reply to correct SASL authentication: {msg}",
|
||||
)
|
||||
|
||||
@cases.mark_specifications("IRCv3")
|
||||
|
|
|
@ -151,10 +151,11 @@ class AwayTestCase(cases.BaseServerTestCase):
|
|||
|
||||
self.connectClient("qux")
|
||||
self.sendLine(2, "PRIVMSG bar :what's up")
|
||||
replies = self.getMessages(2)
|
||||
self.assertEqual(len(replies), 1)
|
||||
self.assertEqual(replies[0].command, RPL_AWAY)
|
||||
self.assertEqual(replies[0].params, ["qux", "bar", "I'm not here right now"])
|
||||
self.assertMessageMatch(
|
||||
self.getMessage(2),
|
||||
command=RPL_AWAY,
|
||||
params=["qux", "bar", "I'm not here right now"],
|
||||
)
|
||||
|
||||
self.sendLine(1, "AWAY")
|
||||
replies = self.getMessages(1)
|
||||
|
@ -174,7 +175,9 @@ class TestNoCTCPMode(cases.BaseServerTestCase):
|
|||
self.sendLine("qux", "PRIVMSG bar :\x01VERSION\x01")
|
||||
self.getMessages("qux")
|
||||
relay = [msg for msg in self.getMessages("bar") if msg.command == "PRIVMSG"][0]
|
||||
self.assertEqual(relay.params[-1], "\x01VERSION\x01")
|
||||
self.assertMessageMatch(
|
||||
relay, command="PRIVMSG", params=["bar", "\x01VERSION\x01"]
|
||||
)
|
||||
|
||||
# set the no-CTCP user mode on bar:
|
||||
self.sendLine("bar", "MODE bar +T")
|
||||
|
|
Loading…
Reference in New Issue