mirror of
https://github.com/progval/irctest.git
synced 2025-04-06 07:19:54 +00:00
Add test on the interaction of server-time and echo-message.
This commit is contained in:
@ -301,10 +301,19 @@ class BaseServerTestCase(_IrcTestCase):
|
||||
"""
|
||||
while True:
|
||||
m = self.getMessage(client, synchronize=False)
|
||||
print('foo: {}'.format(m))
|
||||
if m.command == '001':
|
||||
return m
|
||||
def connectClient(self, nick, name=None):
|
||||
def connectClient(self, nick, name=None, capabilities=None):
|
||||
client = self.addClient(name)
|
||||
if capabilities is not None:
|
||||
self.sendLine(client, 'CAP REQ :{}'.format(' '.join(capabilities)))
|
||||
m = self.getRegistrationMessage(client)
|
||||
self.assertMessageEqual(m, command='CAP',
|
||||
fail_msg='Expected CAP ACK, got: {msg}')
|
||||
self.assertEqual(m.params[1], 'ACK', m,
|
||||
fail_msg='Expected CAP ACK, got: {msg}')
|
||||
self.sendLine(client, 'CAP END')
|
||||
self.sendLine(client, 'NICK {}'.format(nick))
|
||||
self.sendLine(client, 'USER username * * :Realname')
|
||||
|
||||
|
@ -38,15 +38,16 @@ def parse_message(s):
|
||||
http://ircv3.net/specs/core/message-tags-3.2.html"""
|
||||
assert s.endswith('\r\n'), 'Message does not end with CR LF'
|
||||
s = s[0:-2]
|
||||
if s.startswith('@'):
|
||||
(tags, s) = s.split(' ', 1)
|
||||
tags = parse_tags(tags[1:])
|
||||
else:
|
||||
tags = []
|
||||
if ' :' in s:
|
||||
(other_tokens, trailing_param) = s.split(' :')
|
||||
(other_tokens, trailing_param) = s.split(' :', 1)
|
||||
tokens = list(filter(bool, other_tokens.split(' '))) + [trailing_param]
|
||||
else:
|
||||
tokens = list(filter(bool, s.split(' ')))
|
||||
if tokens[0].startswith('@'):
|
||||
tags = parse_tags(tokens.pop(0))
|
||||
else:
|
||||
tags = []
|
||||
if tokens[0].startswith(':'):
|
||||
prefix = tokens.pop(0)[1:]
|
||||
else:
|
||||
|
@ -6,36 +6,42 @@ from irctest import cases
|
||||
from irctest.basecontrollers import NotImplementedByController
|
||||
|
||||
class EchoMessageTestCase(cases.BaseServerTestCase):
|
||||
def _testEchoMessage(command, solo):
|
||||
def _testEchoMessage(command, solo, server_time):
|
||||
@cases.SpecificationSelector.requiredBySpecification('IRCv3.2')
|
||||
def f(self):
|
||||
"""<http://ircv3.net/specs/extensions/echo-message-3.2.html>
|
||||
"""
|
||||
print('------'*100)
|
||||
print('---'*1000)
|
||||
self.addClient()
|
||||
self.sendLine(1, 'CAP LS 302')
|
||||
capabilities = self.getCapLs(1)
|
||||
if 'echo-message' not in capabilities:
|
||||
raise NotImplementedByController('echo-message')
|
||||
if server_time and 'server-time' not in capabilities:
|
||||
raise NotImplementedByController('server-time')
|
||||
|
||||
# TODO: check also without this
|
||||
self.sendLine(1, 'CAP REQ :echo-message')
|
||||
self.sendLine(1, 'CAP REQ :echo-message{}'.format(
|
||||
' server-time' if server_time else ''))
|
||||
m = self.getRegistrationMessage(1)
|
||||
# TODO: Remove this one the trailing space issue is fixed in Charybdis
|
||||
# and Mammon:
|
||||
#self.assertMessageEqual(m, command='CAP',
|
||||
# params=['*', 'ACK', 'echo-message'],
|
||||
# fail_msg='Did not ACK capability `echo-message`: {msg}')
|
||||
# params=['*', 'ACK', 'echo-message'] +
|
||||
# (['server-time'] if server_time else []),
|
||||
# fail_msg='Did not ACK advertised capabilities: {msg}')
|
||||
self.sendLine(1, 'USER f * * :foo')
|
||||
self.sendLine(1, 'NICK baz')
|
||||
self.sendLine(1, 'CAP END')
|
||||
print('skip')
|
||||
self.skipToWelcome(1)
|
||||
print('skipped')
|
||||
self.getMessages(1)
|
||||
|
||||
self.sendLine(1, 'JOIN #chan')
|
||||
|
||||
if not solo:
|
||||
self.connectClient('qux')
|
||||
self.connectClient('qux', capabilities=['server-time'])
|
||||
self.sendLine(2, 'JOIN #chan')
|
||||
|
||||
# Synchronize and clean
|
||||
@ -45,21 +51,31 @@ class EchoMessageTestCase(cases.BaseServerTestCase):
|
||||
self.getMessages(1)
|
||||
|
||||
self.sendLine(1, '{} #chan :hello everyone'.format(command))
|
||||
m = self.getMessage(1)
|
||||
self.assertMessageEqual(m, command=command,
|
||||
m1 = self.getMessage(1)
|
||||
self.assertMessageEqual(m1, command=command,
|
||||
params=['#chan', 'hello everyone'],
|
||||
fail_msg='Did not echo “{} #chan :hello everyone”: {msg}',
|
||||
extra_format=(command,))
|
||||
|
||||
if not solo:
|
||||
m = self.getMessage(2)
|
||||
self.assertMessageEqual(m, command=command,
|
||||
m2 = self.getMessage(2)
|
||||
self.assertMessageEqual(m2, command=command,
|
||||
params=['#chan', 'hello everyone'],
|
||||
fail_msg='Did not propagate “{} #chan :hello everyone”: '
|
||||
'after echoing it to the author: {msg}',
|
||||
extra_format=(command,))
|
||||
self.assertEqual(m1.params, m2.params,
|
||||
fail_msg='Parameters of forwarded and echoed '
|
||||
'messages differ: {} {}',
|
||||
extra_format=(m1, m2))
|
||||
if server_time:
|
||||
self.assertEqual(m1.tags, m2.tags,
|
||||
fail_msg='Tags of forwarded and echoed '
|
||||
'messages differ: {} {}',
|
||||
extra_format=(m1, m2))
|
||||
return f
|
||||
|
||||
testEchoMessagePrivmsg = _testEchoMessage('PRIVMSG', False)
|
||||
testEchoMessagePrivmsgSolo = _testEchoMessage('PRIVMSG', True)
|
||||
testEchoMessageNotice = _testEchoMessage('NOTICE', False)
|
||||
testEchoMessagePrivmsgNoServerTime = _testEchoMessage('PRIVMSG', False, False)
|
||||
testEchoMessagePrivmsgSolo = _testEchoMessage('PRIVMSG', True, True)
|
||||
testEchoMessagePrivmsg = _testEchoMessage('PRIVMSG', False, True)
|
||||
testEchoMessageNotice = _testEchoMessage('NOTICE', False, True)
|
||||
|
Reference in New Issue
Block a user