Skip to content

Commit 279f061

Browse files
committed
functests config module, add logging
Intent with the config module is to support running infobob against the test ircd/services environment with the same settings as the functional tests would use.
1 parent 72216b3 commit 279f061

File tree

2 files changed

+57
-30
lines changed

2 files changed

+57
-30
lines changed

functional-tests/clients.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ class ComposedIRCClient(irc.IRCClient):
5959
"""
6060
log = Logger()
6161

62-
def __init__(self, nickname: str):
62+
def __init__(self, nickname: str, password: str):
6363
self.nickname = nickname
64+
self.password = password
6465
self.signOnComplete = defer.Deferred()
6566

6667
def signedOn(self):
@@ -69,17 +70,24 @@ def signedOn(self):
6970
def joined(self, channel: str) -> None:
7071
self.factory.actions.myJoins.complete(channel)
7172

73+
def irc_unknown(self, command, prefix, params):
74+
self.log.warn(
75+
"received command we aren't prepared to handle: {cmd} {pfx} {pms}",
76+
cmd=command, pfx=prefix, pms=params,
77+
)
78+
7279

7380
class ComposedIRCClientFactory(Factory):
74-
def __init__(self, nickname: str):
81+
def __init__(self, nickname: str, password: str):
7582
self.nickname = nickname
83+
self.password = password
7684
self.actions = None
7785

7886
def startFactory(self):
7987
self.actions = Actions()
8088

8189
def buildProtocol(self, addr):
82-
proto = ComposedIRCClient(self.nickname)
90+
proto = ComposedIRCClient(self.nickname, self.password)
8391
proto.factory = self
8492
self.p = proto
8593
return proto

functional-tests/test_basic.py

+46-27
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import pathlib
44
import sqlite3
55
import time
6+
import sys
67

78
import pytest
89
import pytest_twisted as pytest_tw
@@ -11,24 +12,33 @@
1112
from twisted.internet import task
1213
from twisted.internet import endpoints
1314
from twisted.internet.error import ProcessDone
15+
from twisted import logger
1416

1517
import clients
16-
17-
18-
HERE = pathlib.Path(__name__).parent.resolve()
19-
SCHEMA = HERE.parent.joinpath('db.schema')
20-
21-
SERVER = 'localhost'
22-
SERVER_PORT = 6667
23-
INFOBOB_NICK = 'infotest'
24-
INFOBOB_PASS = 'infotestpass'
25-
INFOBOB_WEB_PORT = 8888
18+
from config import (
19+
INFOBOB_PYTHON,
20+
INFOTEST,
21+
MONITOR,
22+
SCHEMA_PATH,
23+
IRCD_HOST,
24+
IRCD_PORT,
25+
WEBUI_PORT,
26+
)
27+
28+
29+
@pytest.fixture(scope='session', autouse=True)
30+
def fixture_start_logging():
31+
"""
32+
Start up twisted.logger machinery.
33+
"""
34+
observers = [logger.textFileLogObserver(sys.stderr)]
35+
logger.globalLogBeginner.beginLoggingTo(
36+
observers, redirectStandardIO=False)
2637

2738

2839
@pytest.fixture(name='start_infobob')
2940
def fixture_start_infobob(tmp_path):
30-
infobob_python = pathlib.Path(os.environ['INFOBOB_PYTHON']).resolve()
31-
infobob_twistd = str(infobob_python.parent.joinpath('twistd'))
41+
infobob_twistd = str(INFOBOB_PYTHON.parent.joinpath('twistd'))
3242
called = False
3343
spawned = None
3444
ended = None
@@ -44,11 +54,11 @@ def start_infobob(channelsconf, autojoin):
4454
dbpath = tmp_path.joinpath('infobob.db')
4555
conf = {
4656
'irc': {
47-
'server': SERVER,
48-
'port': SERVER_PORT,
57+
'server': IRCD_HOST,
58+
'port': IRCD_PORT,
4959
'ssl': False,
50-
'nickname': INFOBOB_NICK,
51-
'password': INFOBOB_PASS,
60+
'nickname': INFOTEST.nickname,
61+
'password': INFOTEST.password,
5262
'nickserv_pw': None,
5363
'autojoin': autojoin,
5464
},
@@ -61,18 +71,20 @@ def start_infobob(channelsconf, autojoin):
6171
**channelsconf,
6272
},
6373
'database': {'sqlite': {'db_file': dbpath.name}},
64-
'web': {'port': INFOBOB_WEB_PORT},
74+
'web': {
75+
'port': WEBUI_PORT,
76+
'url': f'http://localhost:{WEBUI_PORT}',
77+
},
6578
'misc': {'manhole': {'socket': None}},
6679
}
6780
conn = sqlite3.connect(str(dbpath))
6881
with conn:
69-
conn.executescript(SCHEMA.read_text())
82+
conn.executescript(SCHEMA_PATH.read_text())
7083
conn.close()
7184
confpath.write_text(json.dumps(conf))
7285
from twisted.internet import reactor
7386
proto = InfobobProcessProtocol()
7487
args = [infobob_twistd, '-n', 'infobob', confpath.name]
75-
print('running', args)
7688
childFDs = {
7789
0: open(os.devnull, 'rb').fileno(),
7890
#1: open(os.devnull, 'wb').fileno(),
@@ -101,39 +113,46 @@ def cbStop(procTransport):
101113

102114

103115
class InfobobProcessProtocol(protocol.ProcessProtocol):
116+
log = logger.Logger()
117+
104118
def __init__(self):
105119
self.ended = defer.Deferred()
106120

107121
def connectionMade(self):
108-
print('Infobob started')
122+
self.log.info('Infobob started')
109123
self.transport.closeStdin()
110124

111125
def outReceived(self, data: bytes):
112-
print('Got chunk of stdout:', data.decode('utf-8').rstrip('\r\n'))
126+
self.log.info("stdout: " + data.decode('utf-8').rstrip('\r\n'))
113127

114128
def errReceived(self, data: bytes):
115-
print('Got chunk of stderr:', data.decode('utf-8').rstrip('\r\n'))
129+
self.log.info("stderr: " + data.decode('utf-8').rstrip('\r\n'))
116130

117131
def processEnded(self, status):
118-
print('Infobob exited', status.value)
119132
if status.check(ProcessDone) is None:
133+
self.log.warn('Infobob exited: {status}', status=status)
120134
self.ended.errback(status)
121135
else:
136+
self.log.info('Infobob exited cleanly')
122137
self.ended.callback(None)
123138

124139

125140
@pytest_tw.inlineCallbacks
126141
def test_infobob_basic(start_infobob):
127142
from twisted.internet import reactor
128143

129-
monitor = clients.ComposedIRCClientFactory('monitor')
144+
monitor = clients.ComposedIRCClientFactory(
145+
MONITOR.nickname, MONITOR.password)
130146
endpoint = endpoints.TCP4ClientEndpoint(
131-
reactor, SERVER, SERVER_PORT, timeout=5)
147+
reactor, IRCD_HOST, IRCD_PORT, timeout=5)
132148
yield endpoint.connect(monitor).addCallback(lambda p: p.signOnComplete)
133149
yield defer.gatherResults([
134150
monitor.joinChannel('#project'),
135151
monitor.joinChannel('##offtopic'),
136152
])
137153

138-
start_infobob(channelsconf={}, autojoin=['#project', '##offtopic'])
139-
yield task.deferLater(reactor, 5, lambda: None)
154+
start_infobob(channelsconf={
155+
'#project': {'have_ops': True},
156+
'##offtopic': {'have_ops': True},
157+
}, autojoin=['#project', '##offtopic'])
158+
yield task.deferLater(reactor, 300, lambda: None)

0 commit comments

Comments
 (0)