mirror of
https://github.com/progval/irctest.git
synced 2025-04-08 08:19:54 +00:00
Add registration to server tests.
This commit is contained in:
@ -4,6 +4,8 @@ import socket
|
|||||||
import tempfile
|
import tempfile
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
from .optional_extensions import NotImplementedByController
|
||||||
|
|
||||||
class _BaseController:
|
class _BaseController:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -41,4 +43,8 @@ class BaseClientController(_BaseController):
|
|||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
class BaseServerController(_BaseController):
|
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 socket
|
||||||
import unittest
|
import unittest
|
||||||
import collections
|
import collections
|
||||||
@ -15,6 +16,9 @@ class _IrcTestCase(unittest.TestCase):
|
|||||||
print('---- new test ----')
|
print('---- new test ----')
|
||||||
def getLine(self):
|
def getLine(self):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
def getMessages(self, *args):
|
||||||
|
lines = self.getLines(*args)
|
||||||
|
return map(message_parser.parse_message, lines)
|
||||||
def getMessage(self, *args, filter_pred=None):
|
def getMessage(self, *args, filter_pred=None):
|
||||||
"""Gets a message and returns it. If a filter predicate is given,
|
"""Gets a message and returns it. If a filter predicate is given,
|
||||||
fetches messages until the predicate returns a False on a message,
|
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.connect((self.hostname, self.port))
|
||||||
conn_file = conn.makefile(newline='\r\n', encoding='utf8')
|
conn_file = conn.makefile(newline='\r\n', encoding='utf8')
|
||||||
self.clients[name] = Client(conn=conn, conn_file=conn_file)
|
self.clients[name] = Client(conn=conn, conn_file=conn_file)
|
||||||
|
return name
|
||||||
|
|
||||||
def removeClient(self, name):
|
def removeClient(self, name):
|
||||||
assert name in self.clients
|
assert name in self.clients
|
||||||
self.clients[name].conn.close()
|
self.clients[name].conn.close()
|
||||||
del self.clients[name]
|
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):
|
def getLine(self, client):
|
||||||
assert client in self.clients
|
assert client in self.clients
|
||||||
line = self.clients[client].conn_file.readline()
|
line = self.clients[client].conn_file.readline()
|
||||||
|
@ -41,7 +41,10 @@ logs:
|
|||||||
{{
|
{{
|
||||||
}}
|
}}
|
||||||
register:
|
register:
|
||||||
foo: bar
|
enabled_callbacks:
|
||||||
|
- none
|
||||||
|
verify_timeout:
|
||||||
|
days: 1
|
||||||
roles:
|
roles:
|
||||||
"placeholder":
|
"placeholder":
|
||||||
title: "Just a placeholder"
|
title: "Just a placeholder"
|
||||||
@ -74,5 +77,21 @@ class MammonController(BaseServerController, DirectoryBasedController):
|
|||||||
'--config', os.path.join(self.directory, 'server.yml')])
|
'--config', os.path.join(self.directory, 'server.yml')])
|
||||||
time.sleep(start_wait) # FIXME: do better than this to wait for Mammon to start
|
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():
|
def get_irctest_controller_class():
|
||||||
return MammonController
|
return MammonController
|
||||||
|
@ -2,7 +2,7 @@ import unittest
|
|||||||
import operator
|
import operator
|
||||||
import itertools
|
import itertools
|
||||||
|
|
||||||
class NotImplementedByController(unittest.SkipTest):
|
class NotImplementedByController(unittest.SkipTest, NotImplementedError):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return 'Not implemented by controller: {}'.format(self.args[0])
|
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