mirror of
https://github.com/progval/irctest.git
synced 2025-04-06 23:39:46 +00:00
Add registration to server tests.
This commit is contained in:
@ -4,6 +4,8 @@ import socket
|
||||
import tempfile
|
||||
import subprocess
|
||||
|
||||
from .optional_extensions import NotImplementedByController
|
||||
|
||||
class _BaseController:
|
||||
pass
|
||||
|
||||
@ -41,4 +43,8 @@ class BaseClientController(_BaseController):
|
||||
raise NotImplementedError()
|
||||
|
||||
class BaseServerController(_BaseController):
|
||||
pass
|
||||
def run(self, hostname, port, start_wait):
|
||||
raise NotImplementedError()
|
||||
def registerUser(self, case, username):
|
||||
raise NotImplementedByController('registration')
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
import time
|
||||
import socket
|
||||
import unittest
|
||||
import collections
|
||||
@ -15,6 +16,9 @@ class _IrcTestCase(unittest.TestCase):
|
||||
print('---- new test ----')
|
||||
def getLine(self):
|
||||
raise NotImplementedError()
|
||||
def getMessages(self, *args):
|
||||
lines = self.getLines(*args)
|
||||
return map(message_parser.parse_message, lines)
|
||||
def getMessage(self, *args, filter_pred=None):
|
||||
"""Gets a message and returns it. If a filter predicate is given,
|
||||
fetches messages until the predicate returns a False on a message,
|
||||
@ -180,12 +184,28 @@ class BaseServerTestCase(_IrcTestCase):
|
||||
conn.connect((self.hostname, self.port))
|
||||
conn_file = conn.makefile(newline='\r\n', encoding='utf8')
|
||||
self.clients[name] = Client(conn=conn, conn_file=conn_file)
|
||||
return name
|
||||
|
||||
def removeClient(self, name):
|
||||
assert name in self.clients
|
||||
self.clients[name].conn.close()
|
||||
del self.clients[name]
|
||||
|
||||
def getLines(self, client):
|
||||
data = b''
|
||||
conn = self.clients[client].conn
|
||||
try:
|
||||
conn.setblocking(False)
|
||||
while True:
|
||||
time.sleep(0.1) # TODO: do better than this (use ping?)
|
||||
data += conn.recv(4096)
|
||||
except BlockingIOError:
|
||||
for line in data.decode().split('\r\n'):
|
||||
if line:
|
||||
print('S -> {}: {}'.format(client, line.strip()))
|
||||
yield line + '\r\n'
|
||||
finally:
|
||||
conn.setblocking(True) # required for readline()
|
||||
def getLine(self, client):
|
||||
assert client in self.clients
|
||||
line = self.clients[client].conn_file.readline()
|
||||
|
@ -41,7 +41,10 @@ logs:
|
||||
{{
|
||||
}}
|
||||
register:
|
||||
foo: bar
|
||||
enabled_callbacks:
|
||||
- none
|
||||
verify_timeout:
|
||||
days: 1
|
||||
roles:
|
||||
"placeholder":
|
||||
title: "Just a placeholder"
|
||||
@ -74,5 +77,21 @@ class MammonController(BaseServerController, DirectoryBasedController):
|
||||
'--config', os.path.join(self.directory, 'server.yml')])
|
||||
time.sleep(start_wait) # FIXME: do better than this to wait for Mammon to start
|
||||
|
||||
def registerUser(self, case, username):
|
||||
# XXX: Move this somewhere else when
|
||||
# https://github.com/ircv3/ircv3-specifications/pull/152 becomes
|
||||
# part of the specification
|
||||
client = case.addClient()
|
||||
case.sendLine(client, 'CAP LS 302')
|
||||
case.sendLine(client, 'NICK registration_user')
|
||||
case.sendLine(client, 'USER r e g :user')
|
||||
case.sendLine(client, 'CAP END')
|
||||
list(case.getLines(client))
|
||||
case.sendLine(client, 'REG CREATE {} passphrase temporarypassword'.format(username))
|
||||
msg = case.getMessage(client)
|
||||
assert msg.command == '920'
|
||||
list(case.getLines(client))
|
||||
case.removeClient(client)
|
||||
|
||||
def get_irctest_controller_class():
|
||||
return MammonController
|
||||
|
@ -2,7 +2,7 @@ import unittest
|
||||
import operator
|
||||
import itertools
|
||||
|
||||
class NotImplementedByController(unittest.SkipTest):
|
||||
class NotImplementedByController(unittest.SkipTest, NotImplementedError):
|
||||
def __str__(self):
|
||||
return 'Not implemented by controller: {}'.format(self.args[0])
|
||||
|
||||
|
6
irctest/server_tests/test_registration.py
Normal file
6
irctest/server_tests/test_registration.py
Normal file
@ -0,0 +1,6 @@
|
||||
from irctest import cases
|
||||
from irctest.irc_utils.message_parser import Message
|
||||
|
||||
class RegistrationTestCase(cases.BaseServerTestCase):
|
||||
def testRegistration(self):
|
||||
self.controller.registerUser(self, 'testuser')
|
Reference in New Issue
Block a user