tests: split common code out
This commit is contained in:
parent
bdb8b395b5
commit
1e6fc4601e
23
src/wormhole/test/common.py
Normal file
23
src/wormhole/test/common.py
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
from twisted.application import service
|
||||||
|
from ..twisted.util import allocate_ports
|
||||||
|
from ..servers.relay import RelayServer
|
||||||
|
from .. import __version__
|
||||||
|
|
||||||
|
class ServerBase:
|
||||||
|
def setUp(self):
|
||||||
|
self.sp = service.MultiService()
|
||||||
|
self.sp.startService()
|
||||||
|
d = allocate_ports()
|
||||||
|
def _got_ports(ports):
|
||||||
|
relayport, transitport = ports
|
||||||
|
s = RelayServer("tcp:%d:interface=127.0.0.1" % relayport,
|
||||||
|
"tcp:%s:interface=127.0.0.1" % transitport,
|
||||||
|
__version__)
|
||||||
|
s.setServiceParent(self.sp)
|
||||||
|
self.relayurl = "http://127.0.0.1:%d/wormhole-relay/" % relayport
|
||||||
|
self.transit = "tcp:127.0.0.1:%d" % transitport
|
||||||
|
d.addCallback(_got_ports)
|
||||||
|
return d
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
return self.sp.stopService()
|
|
@ -2,35 +2,13 @@ import json
|
||||||
from twisted.trial import unittest
|
from twisted.trial import unittest
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
from twisted.internet.threads import deferToThread
|
from twisted.internet.threads import deferToThread
|
||||||
from twisted.application import service
|
|
||||||
from ..servers.relay import RelayServer
|
|
||||||
from ..twisted.transcribe import Wormhole, UsageError
|
from ..twisted.transcribe import Wormhole, UsageError
|
||||||
from ..twisted.util import allocate_ports
|
|
||||||
from ..blocking.transcribe import Wormhole as BlockingWormhole
|
from ..blocking.transcribe import Wormhole as BlockingWormhole
|
||||||
from .. import __version__
|
from .common import ServerBase
|
||||||
#from twisted.python import log
|
#from twisted.python import log
|
||||||
#import sys
|
#import sys
|
||||||
#log.startLogging(sys.stdout)
|
#log.startLogging(sys.stdout)
|
||||||
|
|
||||||
class ServerBase:
|
|
||||||
def setUp(self):
|
|
||||||
self.sp = service.MultiService()
|
|
||||||
self.sp.startService()
|
|
||||||
d = allocate_ports()
|
|
||||||
def _got_ports(ports):
|
|
||||||
relayport, transitport = ports
|
|
||||||
s = RelayServer("tcp:%d:interface=127.0.0.1" % relayport,
|
|
||||||
"tcp:%s:interface=127.0.0.1" % transitport,
|
|
||||||
__version__)
|
|
||||||
s.setServiceParent(self.sp)
|
|
||||||
self.relayurl = "http://127.0.0.1:%d/wormhole-relay/" % relayport
|
|
||||||
self.transit = "tcp:127.0.0.1:%d" % transitport
|
|
||||||
d.addCallback(_got_ports)
|
|
||||||
return d
|
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
return self.sp.stopService()
|
|
||||||
|
|
||||||
class Basic(ServerBase, unittest.TestCase):
|
class Basic(ServerBase, unittest.TestCase):
|
||||||
def test_basic(self):
|
def test_basic(self):
|
||||||
appid = "appid"
|
appid = "appid"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user