Add test on the interaction of server-time and echo-message.

This commit is contained in:
Valentin Lorentz
2015-12-24 21:14:59 +01:00
parent 87301592d4
commit da54b76b78
3 changed files with 45 additions and 19 deletions

View File

@ -301,10 +301,19 @@ class BaseServerTestCase(_IrcTestCase):
""" """
while True: while True:
m = self.getMessage(client, synchronize=False) m = self.getMessage(client, synchronize=False)
print('foo: {}'.format(m))
if m.command == '001': if m.command == '001':
return m return m
def connectClient(self, nick, name=None): def connectClient(self, nick, name=None, capabilities=None):
client = self.addClient(name) 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, 'NICK {}'.format(nick))
self.sendLine(client, 'USER username * * :Realname') self.sendLine(client, 'USER username * * :Realname')

View File

@ -38,15 +38,16 @@ def parse_message(s):
http://ircv3.net/specs/core/message-tags-3.2.html""" http://ircv3.net/specs/core/message-tags-3.2.html"""
assert s.endswith('\r\n'), 'Message does not end with CR LF' assert s.endswith('\r\n'), 'Message does not end with CR LF'
s = s[0:-2] s = s[0:-2]
if s.startswith('@'):
(tags, s) = s.split(' ', 1)
tags = parse_tags(tags[1:])
else:
tags = []
if ' :' in s: 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] tokens = list(filter(bool, other_tokens.split(' '))) + [trailing_param]
else: else:
tokens = list(filter(bool, s.split(' '))) tokens = list(filter(bool, s.split(' ')))
if tokens[0].startswith('@'):
tags = parse_tags(tokens.pop(0))
else:
tags = []
if tokens[0].startswith(':'): if tokens[0].startswith(':'):
prefix = tokens.pop(0)[1:] prefix = tokens.pop(0)[1:]
else: else:

View File

@ -6,36 +6,42 @@ from irctest import cases
from irctest.basecontrollers import NotImplementedByController from irctest.basecontrollers import NotImplementedByController
class EchoMessageTestCase(cases.BaseServerTestCase): class EchoMessageTestCase(cases.BaseServerTestCase):
def _testEchoMessage(command, solo): def _testEchoMessage(command, solo, server_time):
@cases.SpecificationSelector.requiredBySpecification('IRCv3.2') @cases.SpecificationSelector.requiredBySpecification('IRCv3.2')
def f(self): def f(self):
"""<http://ircv3.net/specs/extensions/echo-message-3.2.html> """<http://ircv3.net/specs/extensions/echo-message-3.2.html>
""" """
print('------'*100) print('---'*1000)
self.addClient() self.addClient()
self.sendLine(1, 'CAP LS 302') self.sendLine(1, 'CAP LS 302')
capabilities = self.getCapLs(1) capabilities = self.getCapLs(1)
if 'echo-message' not in capabilities: if 'echo-message' not in capabilities:
raise NotImplementedByController('echo-message') raise NotImplementedByController('echo-message')
if server_time and 'server-time' not in capabilities:
raise NotImplementedByController('server-time')
# TODO: check also without this # 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) m = self.getRegistrationMessage(1)
# TODO: Remove this one the trailing space issue is fixed in Charybdis # TODO: Remove this one the trailing space issue is fixed in Charybdis
# and Mammon: # and Mammon:
#self.assertMessageEqual(m, command='CAP', #self.assertMessageEqual(m, command='CAP',
# params=['*', 'ACK', 'echo-message'], # params=['*', 'ACK', 'echo-message'] +
# fail_msg='Did not ACK capability `echo-message`: {msg}') # (['server-time'] if server_time else []),
# fail_msg='Did not ACK advertised capabilities: {msg}')
self.sendLine(1, 'USER f * * :foo') self.sendLine(1, 'USER f * * :foo')
self.sendLine(1, 'NICK baz') self.sendLine(1, 'NICK baz')
self.sendLine(1, 'CAP END') self.sendLine(1, 'CAP END')
print('skip')
self.skipToWelcome(1) self.skipToWelcome(1)
print('skipped')
self.getMessages(1) self.getMessages(1)
self.sendLine(1, 'JOIN #chan') self.sendLine(1, 'JOIN #chan')
if not solo: if not solo:
self.connectClient('qux') self.connectClient('qux', capabilities=['server-time'])
self.sendLine(2, 'JOIN #chan') self.sendLine(2, 'JOIN #chan')
# Synchronize and clean # Synchronize and clean
@ -45,21 +51,31 @@ class EchoMessageTestCase(cases.BaseServerTestCase):
self.getMessages(1) self.getMessages(1)
self.sendLine(1, '{} #chan :hello everyone'.format(command)) self.sendLine(1, '{} #chan :hello everyone'.format(command))
m = self.getMessage(1) m1 = self.getMessage(1)
self.assertMessageEqual(m, command=command, self.assertMessageEqual(m1, command=command,
params=['#chan', 'hello everyone'], params=['#chan', 'hello everyone'],
fail_msg='Did not echo “{} #chan :hello everyone”: {msg}', fail_msg='Did not echo “{} #chan :hello everyone”: {msg}',
extra_format=(command,)) extra_format=(command,))
if not solo: if not solo:
m = self.getMessage(2) m2 = self.getMessage(2)
self.assertMessageEqual(m, command=command, self.assertMessageEqual(m2, command=command,
params=['#chan', 'hello everyone'], params=['#chan', 'hello everyone'],
fail_msg='Did not propagate “{} #chan :hello everyone”: ' fail_msg='Did not propagate “{} #chan :hello everyone”: '
'after echoing it to the author: {msg}', 'after echoing it to the author: {msg}',
extra_format=(command,)) 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 return f
testEchoMessagePrivmsg = _testEchoMessage('PRIVMSG', False) testEchoMessagePrivmsgNoServerTime = _testEchoMessage('PRIVMSG', False, False)
testEchoMessagePrivmsgSolo = _testEchoMessage('PRIVMSG', True) testEchoMessagePrivmsgSolo = _testEchoMessage('PRIVMSG', True, True)
testEchoMessageNotice = _testEchoMessage('NOTICE', False) testEchoMessagePrivmsg = _testEchoMessage('PRIVMSG', False, True)
testEchoMessageNotice = _testEchoMessage('NOTICE', False, True)