mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-26 20:59:27 +01:00
ChannelLogger: write tests for relayed privmsg
This commit is contained in:
parent
7887001ea3
commit
01dc289cd6
@ -302,8 +302,8 @@ class ChannelLogger(callbacks.Plugin):
|
||||
if msg.command in ('PRIVMSG', 'NOTICE'):
|
||||
rewriteRelayed = self.registryValue(
|
||||
'rewriteRelayed', msg.channel, irc.network)
|
||||
if rewriteRelayed and 'echo-message' in self.state.capabilities_ack:
|
||||
assert 'labeled-response' in self.state.capabilities_ack, \
|
||||
if rewriteRelayed and 'echo-message' in irc.state.capabilities_ack:
|
||||
assert 'labeled-response' in irc.state.capabilities_ack, \
|
||||
'echo-message was negotiated without labeled-response.'
|
||||
# If we negotiated the echo-message cap, we have to remember
|
||||
# this message was relayed when the server sends it back to us.
|
||||
|
@ -102,6 +102,49 @@ class ChannelLoggerTestCase(ChannelPluginTestCase):
|
||||
timestamp_re + '<foo> test message\n'
|
||||
)
|
||||
|
||||
@patch_open
|
||||
def testLogRewriteRelayedEmulatedEcho(self, mock_open):
|
||||
with conf.supybot.plugins.ChannelLogger.rewriteRelayed.context(True):
|
||||
log_file = io.StringIO()
|
||||
mock_open.return_value = log_file
|
||||
|
||||
msg = ircmsgs.privmsg('#foo', '<someone> test message')
|
||||
msg.tag('relayedMsg')
|
||||
self.irc.getCallback('ChannelLogger').outFilter(self.irc, msg)
|
||||
self.irc.feedMsg(msg)
|
||||
|
||||
self.assertRegex(
|
||||
log_file.getvalue(),
|
||||
timestamp_re + '<someone> test message\n'
|
||||
)
|
||||
|
||||
@patch_open
|
||||
def testLogRewriteRelayedRealEcho(self, mock_open):
|
||||
with conf.supybot.plugins.ChannelLogger.rewriteRelayed.context(True):
|
||||
log_file = io.StringIO()
|
||||
mock_open.return_value = log_file
|
||||
|
||||
original_caps = self.irc.state.capabilities_ack
|
||||
self.irc.state.capabilities_ack |= {
|
||||
'echo-message', 'labeled-response'
|
||||
}
|
||||
|
||||
try:
|
||||
out_msg = ircmsgs.privmsg('#foo', '<someone> test message')
|
||||
out_msg.tag('relayedMsg')
|
||||
self.irc.getCallback('ChannelLogger').outFilter(self.irc, out_msg)
|
||||
finally:
|
||||
self.irc.state.capabilities_ack = original_caps
|
||||
|
||||
msg = ircmsgs.privmsg('#foo', '<someone> test message')
|
||||
msg.server_tags['label'] = out_msg.server_tags['label']
|
||||
self.irc.feedMsg(msg)
|
||||
|
||||
self.assertRegex(
|
||||
log_file.getvalue(),
|
||||
timestamp_re + '<someone> test message\n'
|
||||
)
|
||||
|
||||
@patch_open
|
||||
def testLogNotice(self, mock_open):
|
||||
log_file = io.StringIO()
|
||||
|
Loading…
Reference in New Issue
Block a user