improve test coverage on get_welcome() API
This commit is contained in:
parent
d0b3e11950
commit
95651f24f9
|
@ -25,6 +25,7 @@ class ServerBase:
|
||||||
advertise_version=__version__,
|
advertise_version=__version__,
|
||||||
signal_error=error)
|
signal_error=error)
|
||||||
s.setServiceParent(self.sp)
|
s.setServiceParent(self.sp)
|
||||||
|
self._relay_server = s
|
||||||
self._rendezvous = s._rendezvous
|
self._rendezvous = s._rendezvous
|
||||||
self._transit_server = s._transit
|
self._transit_server = s._transit
|
||||||
self.relayurl = u"ws://127.0.0.1:%d/v1" % self.relayport
|
self.relayurl = u"ws://127.0.0.1:%d/v1" % self.relayport
|
||||||
|
|
|
@ -330,6 +330,7 @@ class Wormholes(ServerBase, unittest.TestCase):
|
||||||
yield w2.close()
|
yield w2.close()
|
||||||
|
|
||||||
# once closed, all Deferred-yielding API calls get an immediate error
|
# once closed, all Deferred-yielding API calls get an immediate error
|
||||||
|
self.failureResultOf(w1.get_welcome(), WormholeClosed)
|
||||||
f = self.failureResultOf(w1.get_code(), WormholeClosed)
|
f = self.failureResultOf(w1.get_code(), WormholeClosed)
|
||||||
self.assertEqual(f.value.args[0], "happy")
|
self.assertEqual(f.value.args[0], "happy")
|
||||||
self.failureResultOf(w1.get_unverified_key(), WormholeClosed)
|
self.failureResultOf(w1.get_unverified_key(), WormholeClosed)
|
||||||
|
@ -337,6 +338,28 @@ class Wormholes(ServerBase, unittest.TestCase):
|
||||||
self.failureResultOf(w1.get_versions(), WormholeClosed)
|
self.failureResultOf(w1.get_versions(), WormholeClosed)
|
||||||
self.failureResultOf(w1.get_message(), WormholeClosed)
|
self.failureResultOf(w1.get_message(), WormholeClosed)
|
||||||
|
|
||||||
|
@inlineCallbacks
|
||||||
|
def test_closed_idle(self):
|
||||||
|
yield self._relay_server.disownServiceParent()
|
||||||
|
w1 = wormhole.create(APPID, self.relayurl, reactor)
|
||||||
|
# without a relay server, this won't ever connect
|
||||||
|
|
||||||
|
d_welcome = w1.get_welcome()
|
||||||
|
self.assertNoResult(d_welcome)
|
||||||
|
d_code = w1.get_code()
|
||||||
|
d_key = w1.get_unverified_key()
|
||||||
|
d_verifier = w1.get_verifier()
|
||||||
|
d_versions = w1.get_versions()
|
||||||
|
d_message = w1.get_message()
|
||||||
|
|
||||||
|
yield self.assertFailure(w1.close(), LonelyError)
|
||||||
|
|
||||||
|
self.failureResultOf(d_welcome, LonelyError)
|
||||||
|
self.failureResultOf(d_code, LonelyError)
|
||||||
|
self.failureResultOf(d_key, LonelyError)
|
||||||
|
self.failureResultOf(d_verifier, LonelyError)
|
||||||
|
self.failureResultOf(d_versions, LonelyError)
|
||||||
|
self.failureResultOf(d_message, LonelyError)
|
||||||
|
|
||||||
@inlineCallbacks
|
@inlineCallbacks
|
||||||
def test_wrong_password(self):
|
def test_wrong_password(self):
|
||||||
|
@ -423,6 +446,25 @@ class Wormholes(ServerBase, unittest.TestCase):
|
||||||
self.assertEqual(expected_msg, str(ex.exception))
|
self.assertEqual(expected_msg, str(ex.exception))
|
||||||
yield self.assertFailure(w.close(), LonelyError)
|
yield self.assertFailure(w.close(), LonelyError)
|
||||||
|
|
||||||
|
@inlineCallbacks
|
||||||
|
def test_welcome(self):
|
||||||
|
w1 = wormhole.create(APPID, self.relayurl, reactor)
|
||||||
|
wel1 = yield w1.get_welcome() # early: before connection established
|
||||||
|
wel2 = yield w1.get_welcome() # late: already received welcome
|
||||||
|
self.assertEqual(wel1, wel2)
|
||||||
|
self.assertIn("current_cli_version", wel1)
|
||||||
|
|
||||||
|
# cause an error, so a later get_welcome will return the error
|
||||||
|
w1.set_code("123-foo")
|
||||||
|
w2 = wormhole.create(APPID, self.relayurl, reactor)
|
||||||
|
w2.set_code("123-NOT")
|
||||||
|
yield self.assertFailure(w1.get_verifier(), WrongPasswordError)
|
||||||
|
|
||||||
|
yield self.assertFailure(w1.get_welcome(), WrongPasswordError) # late
|
||||||
|
|
||||||
|
yield self.assertFailure(w1.close(), WrongPasswordError)
|
||||||
|
yield self.assertFailure(w2.close(), WrongPasswordError)
|
||||||
|
|
||||||
@inlineCallbacks
|
@inlineCallbacks
|
||||||
def test_verifier(self):
|
def test_verifier(self):
|
||||||
w1 = wormhole.create(APPID, self.relayurl, reactor)
|
w1 = wormhole.create(APPID, self.relayurl, reactor)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user