resume: rename bar/baz to observer/mainnick to improve readability

This commit is contained in:
Valentin Lorentz 2021-02-28 11:31:50 +01:00
parent 6125381598
commit 00ff27f277

View File

@ -28,12 +28,12 @@ class ResumeTestCase(cases.BaseServerTestCase):
def testResume(self): def testResume(self):
chname = "#" + secrets.token_hex(12) chname = "#" + secrets.token_hex(12)
self.connectClient( self.connectClient(
"bar", capabilities=["batch", "labeled-response", "server-time"] "observer", capabilities=["batch", "labeled-response", "server-time"]
) )
ms = self.getMessages(1) ms = self.getMessages(1)
welcome = self.connectClient( welcome = self.connectClient(
"baz", "mainnick",
capabilities=[ capabilities=[
"batch", "batch",
"labeled-response", "labeled-response",
@ -49,7 +49,7 @@ class ResumeTestCase(cases.BaseServerTestCase):
self.joinChannel(1, chname) self.joinChannel(1, chname)
self.joinChannel(2, chname) self.joinChannel(2, chname)
self.sendLine(1, "PRIVMSG %s :hello friends" % (chname,)) self.sendLine(1, "PRIVMSG %s :hello friends" % (chname,))
self.sendLine(1, "PRIVMSG baz :hello friend singular") self.sendLine(1, "PRIVMSG mainnick :hello friend singular")
self.getMessages(1) self.getMessages(1)
# should receive these messages # should receive these messages
privmsgs = [m for m in self.getMessages(2) if m.command == "PRIVMSG"] privmsgs = [m for m in self.getMessages(2) if m.command == "PRIVMSG"]
@ -59,7 +59,7 @@ class ResumeTestCase(cases.BaseServerTestCase):
privmsgs[0], command="PRIVMSG", params=[chname, "hello friends"] privmsgs[0], command="PRIVMSG", params=[chname, "hello friends"]
) )
self.assertMessageEqual( self.assertMessageEqual(
privmsgs[1], command="PRIVMSG", params=["baz", "hello friend singular"] privmsgs[1], command="PRIVMSG", params=["mainnick", "hello friend singular"]
) )
channelMsgTime = privmsgs[0].tags.get("time") channelMsgTime = privmsgs[0].tags.get("time")
@ -111,12 +111,12 @@ class ResumeTestCase(cases.BaseServerTestCase):
) )
# success message # success message
self.assertMessageEqual( self.assertMessageEqual(
resume_messages[1], command="RESUME", params=["SUCCESS", "baz"] resume_messages[1], command="RESUME", params=["SUCCESS", "mainnick"]
) )
# test replay of messages # test replay of messages
privmsgs = [ privmsgs = [
m for m in ms if m.command == "PRIVMSG" and m.prefix.startswith("bar") m for m in ms if m.command == "PRIVMSG" and m.prefix.startswith("observer")
] ]
self.assertEqual(len(privmsgs), 2) self.assertEqual(len(privmsgs), 2)
privmsgs.sort(key=lambda m: m.params[0]) privmsgs.sort(key=lambda m: m.params[0])
@ -124,7 +124,7 @@ class ResumeTestCase(cases.BaseServerTestCase):
privmsgs[0], command="PRIVMSG", params=[chname, "hello friends"] privmsgs[0], command="PRIVMSG", params=[chname, "hello friends"]
) )
self.assertMessageEqual( self.assertMessageEqual(
privmsgs[1], command="PRIVMSG", params=["baz", "hello friend singular"] privmsgs[1], command="PRIVMSG", params=["mainnick", "hello friend singular"]
) )
# should replay with the original server-time # should replay with the original server-time
# TODO this probably isn't testing anything because the timestamp only # TODO this probably isn't testing anything because the timestamp only
@ -134,17 +134,17 @@ class ResumeTestCase(cases.BaseServerTestCase):
# legacy client should receive a QUIT and a JOIN # legacy client should receive a QUIT and a JOIN
quit, join = [m for m in self.getMessages(1) if m.command in ("QUIT", "JOIN")] quit, join = [m for m in self.getMessages(1) if m.command in ("QUIT", "JOIN")]
self.assertEqual(quit.command, "QUIT") self.assertEqual(quit.command, "QUIT")
self.assertTrue(quit.prefix.startswith("baz")) self.assertTrue(quit.prefix.startswith("mainnick"))
self.assertMessageEqual(join, command="JOIN", params=[chname]) self.assertMessageEqual(join, command="JOIN", params=[chname])
self.assertTrue(join.prefix.startswith("baz")) self.assertTrue(join.prefix.startswith("mainnick"))
# original client should have been disconnected # original client should have been disconnected
self.assertDisconnected(2) self.assertDisconnected(2)
# new client should be receiving PRIVMSG sent to baz # new client should be receiving PRIVMSG sent to mainnick
self.sendLine(1, "PRIVMSG baz :hello again") self.sendLine(1, "PRIVMSG mainnick :hello again")
self.getMessages(1) self.getMessages(1)
self.assertMessageEqual( self.assertMessageEqual(
self.getMessage(4), command="PRIVMSG", params=["baz", "hello again"] self.getMessage(4), command="PRIVMSG", params=["mainnick", "hello again"]
) )
# test chain-resuming (resuming the resumed connection, using the new token) # test chain-resuming (resuming the resumed connection, using the new token)
@ -172,14 +172,14 @@ class ResumeTestCase(cases.BaseServerTestCase):
) )
# success message # success message
self.assertMessageEqual( self.assertMessageEqual(
resume_messages[1], command="RESUME", params=["SUCCESS", "baz"] resume_messages[1], command="RESUME", params=["SUCCESS", "mainnick"]
) )
@cases.mark_specifications("Oragono") @cases.mark_specifications("Oragono")
def testBRB(self): def testBRB(self):
chname = "#" + secrets.token_hex(12) chname = "#" + secrets.token_hex(12)
self.connectClient( self.connectClient(
"bar", "observer",
capabilities=[ capabilities=[
"batch", "batch",
"labeled-response", "labeled-response",
@ -192,7 +192,7 @@ class ResumeTestCase(cases.BaseServerTestCase):
self.joinChannel(1, chname) self.joinChannel(1, chname)
welcome = self.connectClient( welcome = self.connectClient(
"baz", "mainnick",
capabilities=[ capabilities=[
"batch", "batch",
"labeled-response", "labeled-response",
@ -217,12 +217,12 @@ class ResumeTestCase(cases.BaseServerTestCase):
# without sending a QUIT line to friends # without sending a QUIT line to friends
self.assertEqual(self.getMessages(1), []) self.assertEqual(self.getMessages(1), [])
self.sendLine(1, "PRIVMSG baz :hey there") self.sendLine(1, "PRIVMSG mainnick :hey there")
# BRB message should be sent as an away message # BRB message should be sent as an away message
self.assertMessageEqual( self.assertMessageEqual(
self.getMessage(1), self.getMessage(1),
command=RPL_AWAY, command=RPL_AWAY,
params=["bar", "baz", "software upgrade"], params=["observer", "mainnick", "software upgrade"],
) )
self.addClient(3) self.addClient(3)
@ -234,16 +234,21 @@ class ResumeTestCase(cases.BaseServerTestCase):
self.assertEqual(len(resume_messages), 2) self.assertEqual(len(resume_messages), 2)
self.assertEqual(resume_messages[0].params[0], "TOKEN") self.assertEqual(resume_messages[0].params[0], "TOKEN")
self.assertMessageEqual( self.assertMessageEqual(
resume_messages[1], command="RESUME", params=["SUCCESS", "baz"] resume_messages[1], command="RESUME", params=["SUCCESS", "mainnick"]
) )
privmsgs = [ privmsgs = [
m for m in ms if m.command == "PRIVMSG" and m.prefix.startswith("bar") m for m in ms if m.command == "PRIVMSG" and m.prefix.startswith("observer")
] ]
self.assertEqual(len(privmsgs), 1) self.assertEqual(len(privmsgs), 1, privmsgs)
self.assertMessageEqual(privmsgs[0], params=["baz", "hey there"]) self.assertMessageEqual(
privmsgs[0],
nick="observer",
command="PRIVMSG",
params=["mainnick", "hey there"],
)
# friend with the resume cap should receive a RESUMED message # friend with the resume cap should receive a RESUMED message
resumed_messages = [m for m in self.getMessages(1) if m.command == "RESUMED"] resumed_messages = [m for m in self.getMessages(1) if m.command == "RESUMED"]
self.assertEqual(len(resumed_messages), 1) self.assertEqual(len(resumed_messages), 1)
self.assertTrue(resumed_messages[0].prefix.startswith("baz")) self.assertTrue(resumed_messages[0].prefix.startswith("mainnick"))