From aa7013e6f5952d7931506ec94ba585b827be6f6b Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Wed, 28 Jun 2017 12:03:04 -0400 Subject: [PATCH] Factor duplicate RelayServer construction out --- src/wormhole/test/test_server.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/wormhole/test/test_server.py b/src/wormhole/test/test_server.py index 514d573..b940cc6 100644 --- a/src/wormhole/test/test_server.py +++ b/src/wormhole/test/test_server.py @@ -11,6 +11,19 @@ from ..server import server, rendezvous from ..server.rendezvous import Usage, SidedMessage from ..server.database import get_db +def easy_relay( + rendezvous_web_port=str("tcp:0"), + transit_port=str("tcp:0"), + advertise_version=None, + **kwargs +): + return server.RelayServer( + rendezvous_web_port, + transit_port, + advertise_version, + **kwargs + ) + class _Util: def _nameplate(self, app, name): np_row = app._db.execute("SELECT * FROM `nameplates`" @@ -1313,7 +1326,7 @@ class Summary(unittest.TestCase): class DumpStats(unittest.TestCase): def test_nostats(self): - rs = server.RelayServer(str("tcp:0"), str("tcp:0"), None) + rs = easy_relay() # with no ._stats_file, this should do nothing rs.dump_stats(1, 1) @@ -1321,8 +1334,7 @@ class DumpStats(unittest.TestCase): basedir = self.mktemp() os.mkdir(basedir) fn = os.path.join(basedir, "stats.json") - rs = server.RelayServer(str("tcp:0"), str("tcp:0"), None, - stats_file=fn) + rs = easy_relay(stats_file=fn) now = 1234 validity = 500 rs.dump_stats(now, validity) @@ -1339,12 +1351,7 @@ class Startup(unittest.TestCase): @mock.patch('wormhole.server.server.log') def test_empty(self, fake_log): - rs = server.RelayServer( - str("tcp:0"), - str("tcp:0"), - None, - allow_list=False, - ) + rs = easy_relay(allow_list=False) rs.startService() try: logs = '\n'.join([call[1][0] for call in fake_log.mock_calls])